diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 1d3a900..07e2f62 100644 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: cfd52247-6a25-4c6d-bbce-fe6fce0cd69d management: - docChecksum: 7136b263714e485a5a96ee056b6e3f36 + docChecksum: 342e7e8ea9cb2b7ff1c1860e18d58822 docVersion: 1.0.0 speakeasyVersion: 1.666.0 generationVersion: 2.768.0 - releaseVersion: 0.1.3 - configChecksum: d03f8606816d7028a10e566c4ff2ac44 + releaseVersion: 0.2.0 + configChecksum: 65a367d36e219e834a1176c8ec421a0a repoURL: https://github.com/OpenRouterTeam/python-sdk.git installationURL: https://github.com/OpenRouterTeam/python-sdk.git published: true @@ -74,11 +74,6 @@ generatedFiles: - docs/components/chatgenerationparamspreferredminthroughput.md - docs/components/chatgenerationparamspreferredminthroughputunion.md - docs/components/chatgenerationparamsprovider.md - - docs/components/chatgenerationparamsresponseformatjsonobject.md - - docs/components/chatgenerationparamsresponseformatpython.md - - docs/components/chatgenerationparamsresponseformattext.md - - docs/components/chatgenerationparamsresponseformatunion.md - - docs/components/chatgenerationparamsstop.md - docs/components/chatgenerationtokenusage.md - docs/components/chatmessagecontentitem.md - docs/components/chatmessagecontentitemaudio.md @@ -109,18 +104,7 @@ generatedFiles: - docs/components/chatstreamoptions.md - docs/components/code.md - docs/components/codeenum.md - - docs/components/completionchoice.md - - docs/components/completioncreateparams.md - - docs/components/completioncreateparamsresponseformatjsonobject.md - - docs/components/completioncreateparamsresponseformatpython.md - - docs/components/completioncreateparamsresponseformattext.md - - docs/components/completioncreateparamsresponseformatunion.md - - docs/components/completioncreateparamsstop.md - - docs/components/completionfinishreason.md - - docs/components/completionlogprobs.md - - docs/components/completionresponse.md - docs/components/completiontokensdetails.md - - docs/components/completionusage.md - docs/components/costdetails.md - docs/components/createchargerequest.md - docs/components/datacollection.md @@ -345,7 +329,6 @@ generatedFiles: - docs/components/preferredmaxlatency.md - docs/components/preferredminthroughput.md - docs/components/pricing.md - - docs/components/prompt.md - docs/components/prompttokensdetails.md - docs/components/providername.md - docs/components/provideroverloadedresponseerrordata.md @@ -376,7 +359,11 @@ generatedFiles: - docs/components/reasoningtextcontent.md - docs/components/reasoningtextcontenttype.md - docs/components/requesttimeoutresponseerrordata.md + - docs/components/responseformat.md + - docs/components/responseformatjsonobject.md - docs/components/responseformatjsonschema.md + - docs/components/responseformatpython.md + - docs/components/responseformattext.md - docs/components/responseformattextconfig.md - docs/components/responseformattextgrammar.md - docs/components/responseinputaudio.md @@ -448,7 +435,7 @@ generatedFiles: - docs/components/servicetier.md - docs/components/serviceunavailableresponseerrordata.md - docs/components/sortenum.md - - docs/components/streamoptions.md + - docs/components/stop.md - docs/components/systemmessage.md - docs/components/systemmessagecontent.md - docs/components/tokenizer.md @@ -627,7 +614,6 @@ generatedFiles: - docs/sdks/analytics/README.md - docs/sdks/apikeys/README.md - docs/sdks/chat/README.md - - docs/sdks/completions/README.md - docs/sdks/credits/README.md - docs/sdks/embeddings/README.md - docs/sdks/endpoints/README.md @@ -651,7 +637,6 @@ generatedFiles: - src/openrouter/basesdk.py - src/openrouter/beta.py - src/openrouter/chat.py - - src/openrouter/completions.py - src/openrouter/components/__init__.py - src/openrouter/components/_schema0.py - src/openrouter/components/_schema2.py @@ -679,11 +664,6 @@ generatedFiles: - src/openrouter/components/chatstreamingmessagetoolcall.py - src/openrouter/components/chatstreamingresponsechunk.py - src/openrouter/components/chatstreamoptions.py - - src/openrouter/components/completionchoice.py - - src/openrouter/components/completioncreateparams.py - - src/openrouter/components/completionlogprobs.py - - src/openrouter/components/completionresponse.py - - src/openrouter/components/completionusage.py - src/openrouter/components/createchargerequest.py - src/openrouter/components/datacollection.py - src/openrouter/components/defaultparameters.py @@ -1063,6 +1043,8 @@ examples: application/json: {"error": {"code": 401, "message": "Missing Authentication header"}} "500": application/json: {"error": {"code": 500, "message": "Internal Server Error"}} + "404": + application/json: {"error": {"code": 404, "message": "Resource not found"}} listEndpoints: speakeasy-default-list-endpoints: parameters: diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index 81e4708..1c1e5cc 100644 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -31,7 +31,7 @@ generation: skipResponseBodyAssertions: false preApplyUnionDiscriminators: true python: - version: 0.1.3 + version: 0.2.0 additionalDependencies: dev: {} main: {} diff --git a/.speakeasy/in.openapi.yaml b/.speakeasy/in.openapi.yaml old mode 100644 new mode 100755 index 232f496..7ab2a07 --- a/.speakeasy/in.openapi.yaml +++ b/.speakeasy/in.openapi.yaml @@ -2,7 +2,7 @@ openapi: 3.1.0 info: title: OpenRouter API version: 1.0.0 - description: OpenAI-compatible Chat Completions and Completions API with additional OpenRouter features + description: OpenAI-compatible API with additional OpenRouter features contact: name: OpenRouter Support url: https://openrouter.ai/docs @@ -9341,263 +9341,6 @@ components: required: - data additionalProperties: false - CompletionFinishReason: - anyOf: - - type: string - enum: - - stop - - length - - content_filter - - type: 'null' - CompletionLogprobs: - type: object - properties: - tokens: - type: array - items: - type: string - token_logprobs: - type: array - items: - type: number - top_logprobs: - anyOf: - - type: array - items: - type: object - propertyNames: - type: string - additionalProperties: - type: number - - type: 'null' - text_offset: - type: array - items: - type: number - required: - - tokens - - token_logprobs - - top_logprobs - - text_offset - CompletionUsage: - type: object - properties: - prompt_tokens: - type: number - completion_tokens: - type: number - total_tokens: - type: number - required: - - prompt_tokens - - completion_tokens - - total_tokens - CompletionCreateParams: - type: object - properties: - model: - $ref: '#/components/schemas/ModelName' - models: - type: array - items: - $ref: '#/components/schemas/ModelName' - prompt: - anyOf: - - type: string - - type: array - items: - type: string - - type: array - items: - type: number - - type: array - items: - type: array - items: - type: number - best_of: - anyOf: - - type: integer - minimum: 1 - maximum: 20 - - type: 'null' - echo: - anyOf: - - type: boolean - - type: 'null' - frequency_penalty: - anyOf: - - type: number - minimum: -2 - maximum: 2 - - type: 'null' - logit_bias: - anyOf: - - type: object - propertyNames: - type: string - additionalProperties: - type: number - - type: 'null' - logprobs: - anyOf: - - type: integer - minimum: 0 - maximum: 5 - - type: 'null' - max_tokens: - anyOf: - - type: integer - minimum: 1 - maximum: 9007199254740991 - - type: 'null' - 'n': - anyOf: - - type: integer - minimum: 1 - maximum: 128 - - type: 'null' - presence_penalty: - anyOf: - - type: number - minimum: -2 - maximum: 2 - - type: 'null' - seed: - anyOf: - - type: integer - minimum: -9007199254740991 - maximum: 9007199254740991 - - type: 'null' - stop: - anyOf: - - anyOf: - - type: string - - type: array - items: - type: string - - type: 'null' - stream: - default: false - type: boolean - stream_options: - anyOf: - - type: object - properties: - include_usage: - anyOf: - - type: boolean - - type: 'null' - - type: 'null' - suffix: - anyOf: - - type: string - - type: 'null' - temperature: - anyOf: - - type: number - minimum: 0 - maximum: 2 - - type: 'null' - top_p: - anyOf: - - type: number - minimum: 0 - maximum: 1 - - type: 'null' - user: - type: string - metadata: - anyOf: - - type: object - propertyNames: - type: string - additionalProperties: - type: string - - type: 'null' - response_format: - anyOf: - - oneOf: - - type: object - properties: - type: - type: string - const: text - required: - - type - - type: object - properties: - type: - type: string - const: json_object - required: - - type - - $ref: '#/components/schemas/ResponseFormatJSONSchema' - - $ref: '#/components/schemas/ResponseFormatTextGrammar' - - type: object - properties: - type: - type: string - const: python - required: - - type - type: object - - type: 'null' - required: - - prompt - CompletionChoice: - type: object - properties: - text: - type: string - index: - type: number - logprobs: - anyOf: - - $ref: '#/components/schemas/CompletionLogprobs' - - type: 'null' - finish_reason: - $ref: '#/components/schemas/CompletionFinishReason' - native_finish_reason: - type: string - reasoning: - anyOf: - - type: string - - type: 'null' - required: - - text - - index - - logprobs - - finish_reason - CompletionResponse: - type: object - properties: - id: - type: string - object: - type: string - const: text_completion - created: - type: number - model: - type: string - provider: - type: string - system_fingerprint: - type: string - choices: - type: array - items: - $ref: '#/components/schemas/CompletionChoice' - usage: - $ref: '#/components/schemas/CompletionUsage' - required: - - id - - object - - created - - model - - choices - additionalProperties: false parameters: {} securitySchemes: apiKey: @@ -9724,7 +9467,7 @@ paths: x-speakeasy-name-override: create x-speakeasy-stream-request-field: stream tags: - - anthropic.messages + - Anthropic Messages summary: Create a message description: >- Creates a message using the Anthropic Messages API format. Supports text, images, PDFs, tools, and extended @@ -10790,7 +10533,13 @@ paths: tags: - Models x-speakeasy-name-override: listForUser - summary: List models filtered by user provider preferences + description: >- + List models filtered by user provider preferences, [privacy + settings](https://openrouter.ai/docs/guides/privacy/logging), and + [guardrails](https://openrouter.ai/docs/guides/features/guardrails). If requesting through + `eu.openrouter.ai/api/v1/...` the results will be filtered to models that satisfy [EU in-region + routing](https://openrouter.ai/docs/guides/privacy/logging#enterprise-eu-in-region-routing). + summary: List models filtered by user provider preferences, privacy settings, and guardrails security: - bearer: [] responses: @@ -10806,6 +10555,12 @@ paths: application/json: schema: $ref: '#/components/schemas/UnauthorizedResponse' + '404': + description: Not Found - No eligible endpoints found + content: + application/json: + schema: + $ref: '#/components/schemas/NotFoundResponse' '500': description: Internal Server Error content: @@ -13812,55 +13567,6 @@ paths: application/json: schema: $ref: '#/components/schemas/ChatError' - /completions: - post: - summary: Create a completion - x-speakeasy-group: completions - x-speakeasy-name-override: generate - x-speakeasy-stream-request-field: stream - description: Creates a completion for the provided prompt and parameters. Supports both streaming and non-streaming modes. - tags: - - Completions - requestBody: - required: true - description: Completion request parameters - content: - application/json: - schema: - $ref: '#/components/schemas/CompletionCreateParams' - responses: - '200': - description: Successful completion response - content: - application/json: - schema: - $ref: '#/components/schemas/CompletionResponse' - description: Completion response - '400': - description: Bad request - invalid parameters - content: - application/json: - schema: - $ref: '#/components/schemas/ChatError' - '401': - description: Unauthorized - invalid API key - content: - application/json: - schema: - $ref: '#/components/schemas/ChatError' - '429': - description: Too many requests - rate limit exceeded - content: - application/json: - schema: - $ref: '#/components/schemas/ChatError' - '500': - description: Internal server error - content: - application/json: - schema: - $ref: '#/components/schemas/ChatError' - operationId: createCompletions servers: - url: https://openrouter.ai/api/v1 description: Production server @@ -13875,10 +13581,10 @@ tags: description: API key management endpoints - name: Analytics description: Analytics and usage endpoints + - name: Anthropic Messages + description: Anthropic Messages endpoints - name: Chat description: Chat completion endpoints - - name: Completions - description: Text completion endpoints - name: Credits description: Credit management endpoints - name: Embeddings @@ -13895,8 +13601,6 @@ tags: description: OAuth authentication endpoints - name: Providers description: Provider information endpoints - - name: anthropic.messages - description: anthropic.messages endpoints - name: beta.responses description: beta.responses endpoints x-fern-base-path: / diff --git a/.speakeasy/out.openapi.yaml b/.speakeasy/out.openapi.yaml index e183d3f..b40a40a 100644 --- a/.speakeasy/out.openapi.yaml +++ b/.speakeasy/out.openapi.yaml @@ -2,7 +2,7 @@ openapi: 3.1.0 info: title: OpenRouter API version: 1.0.0 - description: OpenAI-compatible Chat Completions and Completions API with additional OpenRouter features + description: OpenAI-compatible API with additional OpenRouter features contact: name: OpenRouter Support url: https://openrouter.ai/docs @@ -9350,264 +9350,6 @@ components: required: - data additionalProperties: false - CompletionFinishReason: - anyOf: - - type: string - enum: - - stop - - length - - content_filter - x-speakeasy-unknown-values: allow - - type: 'null' - CompletionLogprobs: - type: object - properties: - tokens: - type: array - items: - type: string - token_logprobs: - type: array - items: - type: number - top_logprobs: - anyOf: - - type: array - items: - type: object - propertyNames: - type: string - additionalProperties: - type: number - - type: 'null' - text_offset: - type: array - items: - type: number - required: - - tokens - - token_logprobs - - top_logprobs - - text_offset - CompletionUsage: - type: object - properties: - prompt_tokens: - type: number - completion_tokens: - type: number - total_tokens: - type: number - required: - - prompt_tokens - - completion_tokens - - total_tokens - CompletionCreateParams: - type: object - properties: - model: - $ref: '#/components/schemas/ModelName' - models: - type: array - items: - $ref: '#/components/schemas/ModelName' - prompt: - anyOf: - - type: string - - type: array - items: - type: string - - type: array - items: - type: number - - type: array - items: - type: array - items: - type: number - best_of: - anyOf: - - type: integer - minimum: 1 - maximum: 20 - - type: 'null' - echo: - anyOf: - - type: boolean - - type: 'null' - frequency_penalty: - anyOf: - - type: number - minimum: -2 - maximum: 2 - - type: 'null' - logit_bias: - anyOf: - - type: object - propertyNames: - type: string - additionalProperties: - type: number - - type: 'null' - logprobs: - anyOf: - - type: integer - minimum: 0 - maximum: 5 - - type: 'null' - max_tokens: - anyOf: - - type: integer - minimum: 1 - maximum: 9007199254740991 - - type: 'null' - 'n': - anyOf: - - type: integer - minimum: 1 - maximum: 128 - - type: 'null' - presence_penalty: - anyOf: - - type: number - minimum: -2 - maximum: 2 - - type: 'null' - seed: - anyOf: - - type: integer - minimum: -9007199254740991 - maximum: 9007199254740991 - - type: 'null' - stop: - anyOf: - - anyOf: - - type: string - - type: array - items: - type: string - - type: 'null' - stream: - default: false - type: boolean - stream_options: - anyOf: - - type: object - properties: - include_usage: - anyOf: - - type: boolean - - type: 'null' - - type: 'null' - suffix: - anyOf: - - type: string - - type: 'null' - temperature: - anyOf: - - type: number - minimum: 0 - maximum: 2 - - type: 'null' - top_p: - anyOf: - - type: number - minimum: 0 - maximum: 1 - - type: 'null' - user: - type: string - metadata: - anyOf: - - type: object - propertyNames: - type: string - additionalProperties: - type: string - - type: 'null' - response_format: - anyOf: - - oneOf: - - type: object - properties: - type: - type: string - const: text - required: - - type - - type: object - properties: - type: - type: string - const: json_object - required: - - type - - $ref: '#/components/schemas/ResponseFormatJSONSchema' - - $ref: '#/components/schemas/ResponseFormatTextGrammar' - - type: object - properties: - type: - type: string - const: python - required: - - type - type: object - - type: 'null' - required: - - prompt - CompletionChoice: - type: object - properties: - text: - type: string - index: - type: number - logprobs: - anyOf: - - $ref: '#/components/schemas/CompletionLogprobs' - - type: 'null' - finish_reason: - $ref: '#/components/schemas/CompletionFinishReason' - native_finish_reason: - type: string - reasoning: - anyOf: - - type: string - - type: 'null' - required: - - text - - index - - logprobs - - finish_reason - CompletionResponse: - type: object - properties: - id: - type: string - object: - type: string - const: text_completion - created: - type: number - model: - type: string - provider: - type: string - system_fingerprint: - type: string - choices: - type: array - items: - $ref: '#/components/schemas/CompletionChoice' - usage: - $ref: '#/components/schemas/CompletionUsage' - required: - - id - - object - - created - - model - - choices - additionalProperties: false parameters: {AppIdentifier: {name: HTTP-Referer, in: header, schema: {type: string}, description: "The app identifier should be your app's URL and is used as the primary identifier for rankings.\nThis is used to track API usage per application.\n"}, AppDisplayName: {name: X-Title, in: header, schema: {type: string}, description: "The app display name allows you to customize how your app appears in OpenRouter's dashboard.\n"}} securitySchemes: apiKey: @@ -9734,7 +9476,7 @@ paths: x-speakeasy-name-override: create x-speakeasy-stream-request-field: stream tags: - - anthropic.messages + - Anthropic Messages summary: Create a message description: >- Creates a message using the Anthropic Messages API format. Supports text, images, PDFs, tools, and extended thinking. @@ -10787,7 +10529,9 @@ paths: tags: - Models x-speakeasy-name-override: listForUser - summary: List models filtered by user provider preferences + description: >- + List models filtered by user provider preferences, [privacy settings](https://openrouter.ai/docs/guides/privacy/logging), and [guardrails](https://openrouter.ai/docs/guides/features/guardrails). If requesting through `eu.openrouter.ai/api/v1/...` the results will be filtered to models that satisfy [EU in-region routing](https://openrouter.ai/docs/guides/privacy/logging#enterprise-eu-in-region-routing). + summary: List models filtered by user provider preferences, privacy settings, and guardrails security: - bearer: [] responses: @@ -10803,6 +10547,12 @@ paths: application/json: schema: $ref: '#/components/schemas/UnauthorizedResponse' + '404': + description: Not Found - No eligible endpoints found + content: + application/json: + schema: + $ref: '#/components/schemas/NotFoundResponse' '500': description: Internal Server Error content: @@ -13802,55 +13552,6 @@ paths: application/json: schema: $ref: '#/components/schemas/ChatError' - /completions: - post: - summary: Create a completion - x-speakeasy-group: completions - x-speakeasy-name-override: generate - x-speakeasy-stream-request-field: stream - description: Creates a completion for the provided prompt and parameters. Supports both streaming and non-streaming modes. - tags: - - Completions - requestBody: - required: true - description: Completion request parameters - content: - application/json: - schema: - $ref: '#/components/schemas/CompletionCreateParams' - responses: - '200': - description: Successful completion response - content: - application/json: - schema: - $ref: '#/components/schemas/CompletionResponse' - description: Completion response - '400': - description: Bad request - invalid parameters - content: - application/json: - schema: - $ref: '#/components/schemas/ChatError' - '401': - description: Unauthorized - invalid API key - content: - application/json: - schema: - $ref: '#/components/schemas/ChatError' - '429': - description: Too many requests - rate limit exceeded - content: - application/json: - schema: - $ref: '#/components/schemas/ChatError' - '500': - description: Internal server error - content: - application/json: - schema: - $ref: '#/components/schemas/ChatError' - operationId: createCompletions servers: - url: https://openrouter.ai/api/v1 description: Production server @@ -13865,10 +13566,10 @@ tags: description: API key management endpoints - name: Analytics description: Analytics and usage endpoints + - name: Anthropic Messages + description: Anthropic Messages endpoints - name: Chat description: Chat completion endpoints - - name: Completions - description: Text completion endpoints - name: Credits description: Credit management endpoints - name: Embeddings @@ -13885,8 +13586,6 @@ tags: description: OAuth authentication endpoints - name: Providers description: Provider information endpoints - - name: anthropic.messages - description: anthropic.messages endpoints - name: beta.responses description: beta.responses endpoints x-fern-base-path: / diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index ff94a13..d31b093 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -8,8 +8,8 @@ sources: - latest OpenRouter API: sourceNamespace: open-router-chat-completions-api - sourceRevisionDigest: sha256:291e215687f85db05005d79dd87602a75b8086f39a841700fdbaaff7690b4f76 - sourceBlobDigest: sha256:166639d08f0ae9687cea532ed8a93db59e63293c6a6f4d17d63f015b60d643d2 + sourceRevisionDigest: sha256:5ba48c1ff7f13c2c5d9ab558e9ecd4638b65c12dd9c4e0cff7fb337674e94ceb + sourceBlobDigest: sha256:082db9694677b85116bda99811c8b957f96d1c493a3c606643479a65dad79730 tags: - latest - 1.0.0 @@ -17,10 +17,10 @@ targets: open-router: source: OpenRouter API sourceNamespace: open-router-chat-completions-api - sourceRevisionDigest: sha256:291e215687f85db05005d79dd87602a75b8086f39a841700fdbaaff7690b4f76 - sourceBlobDigest: sha256:166639d08f0ae9687cea532ed8a93db59e63293c6a6f4d17d63f015b60d643d2 + sourceRevisionDigest: sha256:5ba48c1ff7f13c2c5d9ab558e9ecd4638b65c12dd9c4e0cff7fb337674e94ceb + sourceBlobDigest: sha256:082db9694677b85116bda99811c8b957f96d1c493a3c606643479a65dad79730 codeSamplesNamespace: open-router-python-code-samples - codeSamplesRevisionDigest: sha256:f19eae09ec90a23147935f07a86f75dbbc998e6bac3b820351a1e5f147fec590 + codeSamplesRevisionDigest: sha256:bfe86dbe763c7e6164cdcddd56ddda61a8981ca5b5dc0aa7cd97bbbb4a44142a workflow: workflowVersion: 1.0.0 speakeasyVersion: 1.666.0 diff --git a/docs/components/chatgenerationparams.md b/docs/components/chatgenerationparams.md index f01af13..b3d787a 100644 --- a/docs/components/chatgenerationparams.md +++ b/docs/components/chatgenerationparams.md @@ -22,9 +22,9 @@ | `metadata` | Dict[str, *str*] | :heavy_minus_sign: | N/A | | `presence_penalty` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A | | `reasoning` | [Optional[components.Reasoning]](../components/reasoning.md) | :heavy_minus_sign: | N/A | -| `response_format` | [Optional[components.ChatGenerationParamsResponseFormatUnion]](../components/chatgenerationparamsresponseformatunion.md) | :heavy_minus_sign: | N/A | +| `response_format` | [Optional[components.ResponseFormat]](../components/responseformat.md) | :heavy_minus_sign: | N/A | | `seed` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A | -| `stop` | [OptionalNullable[components.ChatGenerationParamsStop]](../components/chatgenerationparamsstop.md) | :heavy_minus_sign: | N/A | +| `stop` | [OptionalNullable[components.Stop]](../components/stop.md) | :heavy_minus_sign: | N/A | | `stream` | *Optional[bool]* | :heavy_minus_sign: | N/A | | `stream_options` | [OptionalNullable[components.ChatStreamOptions]](../components/chatstreamoptions.md) | :heavy_minus_sign: | N/A | | `temperature` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A | diff --git a/docs/components/chatgenerationparamsresponseformatunion.md b/docs/components/chatgenerationparamsresponseformatunion.md deleted file mode 100644 index 19f2e8c..0000000 --- a/docs/components/chatgenerationparamsresponseformatunion.md +++ /dev/null @@ -1,35 +0,0 @@ -# ChatGenerationParamsResponseFormatUnion - - -## Supported Types - -### `components.ChatGenerationParamsResponseFormatText` - -```python -value: components.ChatGenerationParamsResponseFormatText = /* values here */ -``` - -### `components.ChatGenerationParamsResponseFormatJSONObject` - -```python -value: components.ChatGenerationParamsResponseFormatJSONObject = /* values here */ -``` - -### `components.ResponseFormatJSONSchema` - -```python -value: components.ResponseFormatJSONSchema = /* values here */ -``` - -### `components.ResponseFormatTextGrammar` - -```python -value: components.ResponseFormatTextGrammar = /* values here */ -``` - -### `components.ChatGenerationParamsResponseFormatPython` - -```python -value: components.ChatGenerationParamsResponseFormatPython = /* values here */ -``` - diff --git a/docs/components/completionchoice.md b/docs/components/completionchoice.md deleted file mode 100644 index cb489be..0000000 --- a/docs/components/completionchoice.md +++ /dev/null @@ -1,13 +0,0 @@ -# CompletionChoice - - -## Fields - -| Field | Type | Required | Description | -| -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | -| `text` | *str* | :heavy_check_mark: | N/A | -| `index` | *float* | :heavy_check_mark: | N/A | -| `logprobs` | [Nullable[components.CompletionLogprobs]](../components/completionlogprobs.md) | :heavy_check_mark: | N/A | -| `finish_reason` | [Nullable[components.CompletionFinishReason]](../components/completionfinishreason.md) | :heavy_check_mark: | N/A | -| `native_finish_reason` | *Optional[str]* | :heavy_minus_sign: | N/A | -| `reasoning` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/components/completioncreateparams.md b/docs/components/completioncreateparams.md deleted file mode 100644 index 7f7c9f4..0000000 --- a/docs/components/completioncreateparams.md +++ /dev/null @@ -1,28 +0,0 @@ -# CompletionCreateParams - - -## Fields - -| Field | Type | Required | Description | -| ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ | -| `model` | *Optional[str]* | :heavy_minus_sign: | N/A | -| `models` | List[*str*] | :heavy_minus_sign: | N/A | -| `prompt` | [components.Prompt](../components/prompt.md) | :heavy_check_mark: | N/A | -| `best_of` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A | -| `echo` | *OptionalNullable[bool]* | :heavy_minus_sign: | N/A | -| `frequency_penalty` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A | -| `logit_bias` | Dict[str, *float*] | :heavy_minus_sign: | N/A | -| `logprobs` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A | -| `max_tokens` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A | -| `n` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A | -| `presence_penalty` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A | -| `seed` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A | -| `stop` | [OptionalNullable[components.CompletionCreateParamsStop]](../components/completioncreateparamsstop.md) | :heavy_minus_sign: | N/A | -| `stream` | *Optional[bool]* | :heavy_minus_sign: | N/A | -| `stream_options` | [OptionalNullable[components.StreamOptions]](../components/streamoptions.md) | :heavy_minus_sign: | N/A | -| `suffix` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A | -| `temperature` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A | -| `top_p` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A | -| `user` | *Optional[str]* | :heavy_minus_sign: | N/A | -| `metadata` | Dict[str, *str*] | :heavy_minus_sign: | N/A | -| `response_format` | [OptionalNullable[components.CompletionCreateParamsResponseFormatUnion]](../components/completioncreateparamsresponseformatunion.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/components/completioncreateparamsresponseformatjsonobject.md b/docs/components/completioncreateparamsresponseformatjsonobject.md deleted file mode 100644 index a5c6d3b..0000000 --- a/docs/components/completioncreateparamsresponseformatjsonobject.md +++ /dev/null @@ -1,8 +0,0 @@ -# CompletionCreateParamsResponseFormatJSONObject - - -## Fields - -| Field | Type | Required | Description | -| ------------------------ | ------------------------ | ------------------------ | ------------------------ | -| `type` | *Literal["json_object"]* | :heavy_check_mark: | N/A | \ No newline at end of file diff --git a/docs/components/completioncreateparamsresponseformatpython.md b/docs/components/completioncreateparamsresponseformatpython.md deleted file mode 100644 index e0bcf67..0000000 --- a/docs/components/completioncreateparamsresponseformatpython.md +++ /dev/null @@ -1,8 +0,0 @@ -# CompletionCreateParamsResponseFormatPython - - -## Fields - -| Field | Type | Required | Description | -| ------------------- | ------------------- | ------------------- | ------------------- | -| `type` | *Literal["python"]* | :heavy_check_mark: | N/A | \ No newline at end of file diff --git a/docs/components/completioncreateparamsresponseformattext.md b/docs/components/completioncreateparamsresponseformattext.md deleted file mode 100644 index bb80891..0000000 --- a/docs/components/completioncreateparamsresponseformattext.md +++ /dev/null @@ -1,8 +0,0 @@ -# CompletionCreateParamsResponseFormatText - - -## Fields - -| Field | Type | Required | Description | -| ------------------ | ------------------ | ------------------ | ------------------ | -| `type` | *Literal["text"]* | :heavy_check_mark: | N/A | \ No newline at end of file diff --git a/docs/components/completioncreateparamsresponseformatunion.md b/docs/components/completioncreateparamsresponseformatunion.md deleted file mode 100644 index 53050dc..0000000 --- a/docs/components/completioncreateparamsresponseformatunion.md +++ /dev/null @@ -1,35 +0,0 @@ -# CompletionCreateParamsResponseFormatUnion - - -## Supported Types - -### `components.CompletionCreateParamsResponseFormatText` - -```python -value: components.CompletionCreateParamsResponseFormatText = /* values here */ -``` - -### `components.CompletionCreateParamsResponseFormatJSONObject` - -```python -value: components.CompletionCreateParamsResponseFormatJSONObject = /* values here */ -``` - -### `components.ResponseFormatJSONSchema` - -```python -value: components.ResponseFormatJSONSchema = /* values here */ -``` - -### `components.ResponseFormatTextGrammar` - -```python -value: components.ResponseFormatTextGrammar = /* values here */ -``` - -### `components.CompletionCreateParamsResponseFormatPython` - -```python -value: components.CompletionCreateParamsResponseFormatPython = /* values here */ -``` - diff --git a/docs/components/completioncreateparamsstop.md b/docs/components/completioncreateparamsstop.md deleted file mode 100644 index da48725..0000000 --- a/docs/components/completioncreateparamsstop.md +++ /dev/null @@ -1,17 +0,0 @@ -# CompletionCreateParamsStop - - -## Supported Types - -### `str` - -```python -value: str = /* values here */ -``` - -### `List[str]` - -```python -value: List[str] = /* values here */ -``` - diff --git a/docs/components/completionfinishreason.md b/docs/components/completionfinishreason.md deleted file mode 100644 index 4a4e249..0000000 --- a/docs/components/completionfinishreason.md +++ /dev/null @@ -1,10 +0,0 @@ -# CompletionFinishReason - - -## Values - -| Name | Value | -| ---------------- | ---------------- | -| `STOP` | stop | -| `LENGTH` | length | -| `CONTENT_FILTER` | content_filter | \ No newline at end of file diff --git a/docs/components/completionlogprobs.md b/docs/components/completionlogprobs.md deleted file mode 100644 index 9a8b558..0000000 --- a/docs/components/completionlogprobs.md +++ /dev/null @@ -1,11 +0,0 @@ -# CompletionLogprobs - - -## Fields - -| Field | Type | Required | Description | -| ------------------------ | ------------------------ | ------------------------ | ------------------------ | -| `tokens` | List[*str*] | :heavy_check_mark: | N/A | -| `token_logprobs` | List[*float*] | :heavy_check_mark: | N/A | -| `top_logprobs` | List[Dict[str, *float*]] | :heavy_check_mark: | N/A | -| `text_offset` | List[*float*] | :heavy_check_mark: | N/A | \ No newline at end of file diff --git a/docs/components/completionresponse.md b/docs/components/completionresponse.md deleted file mode 100644 index 3e9a9bd..0000000 --- a/docs/components/completionresponse.md +++ /dev/null @@ -1,15 +0,0 @@ -# CompletionResponse - - -## Fields - -| Field | Type | Required | Description | -| ------------------------------------------------------------------------ | ------------------------------------------------------------------------ | ------------------------------------------------------------------------ | ------------------------------------------------------------------------ | -| `id` | *str* | :heavy_check_mark: | N/A | -| `object` | *Literal["text_completion"]* | :heavy_check_mark: | N/A | -| `created` | *float* | :heavy_check_mark: | N/A | -| `model` | *str* | :heavy_check_mark: | N/A | -| `provider` | *Optional[str]* | :heavy_minus_sign: | N/A | -| `system_fingerprint` | *Optional[str]* | :heavy_minus_sign: | N/A | -| `choices` | List[[components.CompletionChoice](../components/completionchoice.md)] | :heavy_check_mark: | N/A | -| `usage` | [Optional[components.CompletionUsage]](../components/completionusage.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/components/completionusage.md b/docs/components/completionusage.md deleted file mode 100644 index e9e3983..0000000 --- a/docs/components/completionusage.md +++ /dev/null @@ -1,10 +0,0 @@ -# CompletionUsage - - -## Fields - -| Field | Type | Required | Description | -| ------------------- | ------------------- | ------------------- | ------------------- | -| `prompt_tokens` | *float* | :heavy_check_mark: | N/A | -| `completion_tokens` | *float* | :heavy_check_mark: | N/A | -| `total_tokens` | *float* | :heavy_check_mark: | N/A | \ No newline at end of file diff --git a/docs/components/prompt.md b/docs/components/prompt.md deleted file mode 100644 index c700709..0000000 --- a/docs/components/prompt.md +++ /dev/null @@ -1,29 +0,0 @@ -# Prompt - - -## Supported Types - -### `str` - -```python -value: str = /* values here */ -``` - -### `List[str]` - -```python -value: List[str] = /* values here */ -``` - -### `List[float]` - -```python -value: List[float] = /* values here */ -``` - -### `List[List[float]]` - -```python -value: List[List[float]] = /* values here */ -``` - diff --git a/docs/components/responseformat.md b/docs/components/responseformat.md new file mode 100644 index 0000000..e9e9fda --- /dev/null +++ b/docs/components/responseformat.md @@ -0,0 +1,35 @@ +# ResponseFormat + + +## Supported Types + +### `components.ResponseFormatText` + +```python +value: components.ResponseFormatText = /* values here */ +``` + +### `components.ResponseFormatJSONObject` + +```python +value: components.ResponseFormatJSONObject = /* values here */ +``` + +### `components.ResponseFormatJSONSchema` + +```python +value: components.ResponseFormatJSONSchema = /* values here */ +``` + +### `components.ResponseFormatTextGrammar` + +```python +value: components.ResponseFormatTextGrammar = /* values here */ +``` + +### `components.ResponseFormatPython` + +```python +value: components.ResponseFormatPython = /* values here */ +``` + diff --git a/docs/components/chatgenerationparamsresponseformatjsonobject.md b/docs/components/responseformatjsonobject.md similarity index 87% rename from docs/components/chatgenerationparamsresponseformatjsonobject.md rename to docs/components/responseformatjsonobject.md index 4c9c696..88c50c4 100644 --- a/docs/components/chatgenerationparamsresponseformatjsonobject.md +++ b/docs/components/responseformatjsonobject.md @@ -1,4 +1,4 @@ -# ChatGenerationParamsResponseFormatJSONObject +# ResponseFormatJSONObject ## Fields diff --git a/docs/components/chatgenerationparamsresponseformatpython.md b/docs/components/responseformatpython.md similarity index 86% rename from docs/components/chatgenerationparamsresponseformatpython.md rename to docs/components/responseformatpython.md index 5b1274c..ca9fc95 100644 --- a/docs/components/chatgenerationparamsresponseformatpython.md +++ b/docs/components/responseformatpython.md @@ -1,4 +1,4 @@ -# ChatGenerationParamsResponseFormatPython +# ResponseFormatPython ## Fields diff --git a/docs/components/chatgenerationparamsresponseformattext.md b/docs/components/responseformattext.md similarity index 86% rename from docs/components/chatgenerationparamsresponseformattext.md rename to docs/components/responseformattext.md index 9efb0d8..1b66a78 100644 --- a/docs/components/chatgenerationparamsresponseformattext.md +++ b/docs/components/responseformattext.md @@ -1,4 +1,4 @@ -# ChatGenerationParamsResponseFormatText +# ResponseFormatText ## Fields diff --git a/docs/components/chatgenerationparamsstop.md b/docs/components/stop.md similarity index 84% rename from docs/components/chatgenerationparamsstop.md rename to docs/components/stop.md index 9725523..9cfdaa0 100644 --- a/docs/components/chatgenerationparamsstop.md +++ b/docs/components/stop.md @@ -1,4 +1,4 @@ -# ChatGenerationParamsStop +# Stop ## Supported Types diff --git a/docs/components/streamoptions.md b/docs/components/streamoptions.md deleted file mode 100644 index a2e5702..0000000 --- a/docs/components/streamoptions.md +++ /dev/null @@ -1,8 +0,0 @@ -# StreamOptions - - -## Fields - -| Field | Type | Required | Description | -| ------------------------ | ------------------------ | ------------------------ | ------------------------ | -| `include_usage` | *OptionalNullable[bool]* | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/sdks/chat/README.md b/docs/sdks/chat/README.md index 6b781c3..65a5f9b 100644 --- a/docs/sdks/chat/README.md +++ b/docs/sdks/chat/README.md @@ -53,9 +53,9 @@ with OpenRouter( | `metadata` | Dict[str, *str*] | :heavy_minus_sign: | N/A | | `presence_penalty` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A | | `reasoning` | [Optional[components.Reasoning]](../../components/reasoning.md) | :heavy_minus_sign: | N/A | -| `response_format` | [Optional[components.ChatGenerationParamsResponseFormatUnion]](../../components/chatgenerationparamsresponseformatunion.md) | :heavy_minus_sign: | N/A | +| `response_format` | [Optional[components.ResponseFormat]](../../components/responseformat.md) | :heavy_minus_sign: | N/A | | `seed` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A | -| `stop` | [OptionalNullable[components.ChatGenerationParamsStop]](../../components/chatgenerationparamsstop.md) | :heavy_minus_sign: | N/A | +| `stop` | [OptionalNullable[components.Stop]](../../components/stop.md) | :heavy_minus_sign: | N/A | | `stream` | *Optional[bool]* | :heavy_minus_sign: | N/A | | `stream_options` | [OptionalNullable[components.ChatStreamOptions]](../../components/chatstreamoptions.md) | :heavy_minus_sign: | N/A | | `temperature` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A | diff --git a/docs/sdks/completions/README.md b/docs/sdks/completions/README.md deleted file mode 100644 index beeb03e..0000000 --- a/docs/sdks/completions/README.md +++ /dev/null @@ -1,70 +0,0 @@ -# Completions -(*completions*) - -## Overview - -### Available Operations - -* [generate](#generate) - Create a completion - -## generate - -Creates a completion for the provided prompt and parameters. Supports both streaming and non-streaming modes. - -### Example Usage - - -```python -from openrouter import OpenRouter -import os - - -with OpenRouter( - api_key=os.getenv("OPENROUTER_API_KEY", ""), -) as open_router: - - res = open_router.completions.generate(prompt=[], stream=False) - - # Handle response - print(res) - -``` - -### Parameters - -| Parameter | Type | Required | Description | -| --------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | -| `prompt` | [components.Prompt](../../components/prompt.md) | :heavy_check_mark: | N/A | -| `model` | *Optional[str]* | :heavy_minus_sign: | N/A | -| `models` | List[*str*] | :heavy_minus_sign: | N/A | -| `best_of` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A | -| `echo` | *OptionalNullable[bool]* | :heavy_minus_sign: | N/A | -| `frequency_penalty` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A | -| `logit_bias` | Dict[str, *float*] | :heavy_minus_sign: | N/A | -| `logprobs` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A | -| `max_tokens` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A | -| `n` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A | -| `presence_penalty` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A | -| `seed` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A | -| `stop` | [OptionalNullable[components.CompletionCreateParamsStop]](../../components/completioncreateparamsstop.md) | :heavy_minus_sign: | N/A | -| `stream` | *Optional[bool]* | :heavy_minus_sign: | N/A | -| `stream_options` | [OptionalNullable[components.StreamOptions]](../../components/streamoptions.md) | :heavy_minus_sign: | N/A | -| `suffix` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A | -| `temperature` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A | -| `top_p` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A | -| `user` | *Optional[str]* | :heavy_minus_sign: | N/A | -| `metadata` | Dict[str, *str*] | :heavy_minus_sign: | N/A | -| `response_format` | [OptionalNullable[components.CompletionCreateParamsResponseFormatUnion]](../../components/completioncreateparamsresponseformatunion.md) | :heavy_minus_sign: | N/A | -| `retries` | [Optional[utils.RetryConfig]](../../models/utils/retryconfig.md) | :heavy_minus_sign: | Configuration to override the default retry behavior of the client. | - -### Response - -**[components.CompletionResponse](../../components/completionresponse.md)** - -### Errors - -| Error Type | Status Code | Content Type | -| ----------------------------- | ----------------------------- | ----------------------------- | -| errors.ChatError | 400, 401, 429 | application/json | -| errors.ChatError | 500 | application/json | -| errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | \ No newline at end of file diff --git a/docs/sdks/models/README.md b/docs/sdks/models/README.md index b106323..2ea55ea 100644 --- a/docs/sdks/models/README.md +++ b/docs/sdks/models/README.md @@ -9,7 +9,7 @@ Model information endpoints * [count](#count) - Get total count of available models * [list](#list) - List all models and their properties -* [list_for_user](#list_for_user) - List models filtered by user provider preferences +* [list_for_user](#list_for_user) - List models filtered by user provider preferences, privacy settings, and guardrails ## count @@ -96,7 +96,7 @@ with OpenRouter( ## list_for_user -List models filtered by user provider preferences +List models filtered by user provider preferences, [privacy settings](https://openrouter.ai/docs/guides/privacy/logging), and [guardrails](https://openrouter.ai/docs/guides/features/guardrails). If requesting through `eu.openrouter.ai/api/v1/...` the results will be filtered to models that satisfy [EU in-region routing](https://openrouter.ai/docs/guides/privacy/logging#enterprise-eu-in-region-routing). ### Example Usage @@ -133,5 +133,6 @@ with OpenRouter() as open_router: | Error Type | Status Code | Content Type | | ---------------------------------- | ---------------------------------- | ---------------------------------- | | errors.UnauthorizedResponseError | 401 | application/json | +| errors.NotFoundResponseError | 404 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 09db2ac..1c237a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "openrouter" -version = "0.1.3" +version = "0.2.0" description = "Official Python Client SDK for OpenRouter." authors = [{ name = "OpenRouter" },] readme = "README-PYPI.md" diff --git a/src/openrouter/_version.py b/src/openrouter/_version.py index 59cb4ed..ddd5684 100644 --- a/src/openrouter/_version.py +++ b/src/openrouter/_version.py @@ -3,10 +3,10 @@ import importlib.metadata __title__: str = "openrouter" -__version__: str = "0.1.3" +__version__: str = "0.2.0" __openapi_doc_version__: str = "1.0.0" __gen_version__: str = "2.768.0" -__user_agent__: str = "speakeasy-sdk/python 0.1.3 2.768.0 1.0.0 openrouter" +__user_agent__: str = "speakeasy-sdk/python 0.2.0 2.768.0 1.0.0 openrouter" try: if __package__ is not None: diff --git a/src/openrouter/chat.py b/src/openrouter/chat.py index d75dbd2..dcd9fce 100644 --- a/src/openrouter/chat.py +++ b/src/openrouter/chat.py @@ -50,17 +50,11 @@ def send( Union[components.Reasoning, components.ReasoningTypedDict] ] = None, response_format: Optional[ - Union[ - components.ChatGenerationParamsResponseFormatUnion, - components.ChatGenerationParamsResponseFormatUnionTypedDict, - ] + Union[components.ResponseFormat, components.ResponseFormatTypedDict] ] = None, seed: OptionalNullable[int] = UNSET, stop: OptionalNullable[ - Union[ - components.ChatGenerationParamsStop, - components.ChatGenerationParamsStopTypedDict, - ] + Union[components.Stop, components.StopTypedDict] ] = UNSET, stream: Union[Literal[False], None] = None, stream_options: OptionalNullable[ @@ -162,17 +156,11 @@ def send( Union[components.Reasoning, components.ReasoningTypedDict] ] = None, response_format: Optional[ - Union[ - components.ChatGenerationParamsResponseFormatUnion, - components.ChatGenerationParamsResponseFormatUnionTypedDict, - ] + Union[components.ResponseFormat, components.ResponseFormatTypedDict] ] = None, seed: OptionalNullable[int] = UNSET, stop: OptionalNullable[ - Union[ - components.ChatGenerationParamsStop, - components.ChatGenerationParamsStopTypedDict, - ] + Union[components.Stop, components.StopTypedDict] ] = UNSET, stream: Literal[True], stream_options: OptionalNullable[ @@ -273,17 +261,11 @@ def send( Union[components.Reasoning, components.ReasoningTypedDict] ] = None, response_format: Optional[ - Union[ - components.ChatGenerationParamsResponseFormatUnion, - components.ChatGenerationParamsResponseFormatUnionTypedDict, - ] + Union[components.ResponseFormat, components.ResponseFormatTypedDict] ] = None, seed: OptionalNullable[int] = UNSET, stop: OptionalNullable[ - Union[ - components.ChatGenerationParamsStop, - components.ChatGenerationParamsStopTypedDict, - ] + Union[components.Stop, components.StopTypedDict] ] = UNSET, stream: Optional[bool] = False, stream_options: OptionalNullable[ @@ -385,8 +367,7 @@ def send( reasoning, Optional[components.Reasoning] ), response_format=utils.get_pydantic_model( - response_format, - Optional[components.ChatGenerationParamsResponseFormatUnion], + response_format, Optional[components.ResponseFormat] ), seed=seed, stop=stop, @@ -526,17 +507,11 @@ async def send_async( Union[components.Reasoning, components.ReasoningTypedDict] ] = None, response_format: Optional[ - Union[ - components.ChatGenerationParamsResponseFormatUnion, - components.ChatGenerationParamsResponseFormatUnionTypedDict, - ] + Union[components.ResponseFormat, components.ResponseFormatTypedDict] ] = None, seed: OptionalNullable[int] = UNSET, stop: OptionalNullable[ - Union[ - components.ChatGenerationParamsStop, - components.ChatGenerationParamsStopTypedDict, - ] + Union[components.Stop, components.StopTypedDict] ] = UNSET, stream: Union[Literal[False], None] = None, stream_options: OptionalNullable[ @@ -638,17 +613,11 @@ async def send_async( Union[components.Reasoning, components.ReasoningTypedDict] ] = None, response_format: Optional[ - Union[ - components.ChatGenerationParamsResponseFormatUnion, - components.ChatGenerationParamsResponseFormatUnionTypedDict, - ] + Union[components.ResponseFormat, components.ResponseFormatTypedDict] ] = None, seed: OptionalNullable[int] = UNSET, stop: OptionalNullable[ - Union[ - components.ChatGenerationParamsStop, - components.ChatGenerationParamsStopTypedDict, - ] + Union[components.Stop, components.StopTypedDict] ] = UNSET, stream: Literal[True], stream_options: OptionalNullable[ @@ -749,17 +718,11 @@ async def send_async( Union[components.Reasoning, components.ReasoningTypedDict] ] = None, response_format: Optional[ - Union[ - components.ChatGenerationParamsResponseFormatUnion, - components.ChatGenerationParamsResponseFormatUnionTypedDict, - ] + Union[components.ResponseFormat, components.ResponseFormatTypedDict] ] = None, seed: OptionalNullable[int] = UNSET, stop: OptionalNullable[ - Union[ - components.ChatGenerationParamsStop, - components.ChatGenerationParamsStopTypedDict, - ] + Union[components.Stop, components.StopTypedDict] ] = UNSET, stream: Optional[bool] = False, stream_options: OptionalNullable[ @@ -861,8 +824,7 @@ async def send_async( reasoning, Optional[components.Reasoning] ), response_format=utils.get_pydantic_model( - response_format, - Optional[components.ChatGenerationParamsResponseFormatUnion], + response_format, Optional[components.ResponseFormat] ), seed=seed, stop=stop, diff --git a/src/openrouter/completions.py b/src/openrouter/completions.py deleted file mode 100644 index 26bbf6a..0000000 --- a/src/openrouter/completions.py +++ /dev/null @@ -1,361 +0,0 @@ -"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" - -from .basesdk import BaseSDK -from openrouter import components, errors, utils -from openrouter._hooks import HookContext -from openrouter.types import OptionalNullable, UNSET -from openrouter.utils import get_security_from_env -from openrouter.utils.unmarshal_json_response import unmarshal_json_response -from typing import Any, Dict, List, Mapping, Optional, Union - - -class Completions(BaseSDK): - def generate( - self, - *, - prompt: Union[components.Prompt, components.PromptTypedDict], - model: Optional[str] = None, - models: Optional[List[str]] = None, - best_of: OptionalNullable[int] = UNSET, - echo: OptionalNullable[bool] = UNSET, - frequency_penalty: OptionalNullable[float] = UNSET, - logit_bias: OptionalNullable[Dict[str, float]] = UNSET, - logprobs: OptionalNullable[int] = UNSET, - max_tokens: OptionalNullable[int] = UNSET, - n: OptionalNullable[int] = UNSET, - presence_penalty: OptionalNullable[float] = UNSET, - seed: OptionalNullable[int] = UNSET, - stop: OptionalNullable[ - Union[ - components.CompletionCreateParamsStop, - components.CompletionCreateParamsStopTypedDict, - ] - ] = UNSET, - stream: Optional[bool] = False, - stream_options: OptionalNullable[ - Union[components.StreamOptions, components.StreamOptionsTypedDict] - ] = UNSET, - suffix: OptionalNullable[str] = UNSET, - temperature: OptionalNullable[float] = UNSET, - top_p: OptionalNullable[float] = UNSET, - user: Optional[str] = None, - metadata: OptionalNullable[Dict[str, str]] = UNSET, - response_format: OptionalNullable[ - Union[ - components.CompletionCreateParamsResponseFormatUnion, - components.CompletionCreateParamsResponseFormatUnionTypedDict, - ] - ] = UNSET, - retries: OptionalNullable[utils.RetryConfig] = UNSET, - server_url: Optional[str] = None, - timeout_ms: Optional[int] = None, - http_headers: Optional[Mapping[str, str]] = None, - ) -> components.CompletionResponse: - r"""Create a completion - - Creates a completion for the provided prompt and parameters. Supports both streaming and non-streaming modes. - - :param prompt: - :param model: - :param models: - :param best_of: - :param echo: - :param frequency_penalty: - :param logit_bias: - :param logprobs: - :param max_tokens: - :param n: - :param presence_penalty: - :param seed: - :param stop: - :param stream: - :param stream_options: - :param suffix: - :param temperature: - :param top_p: - :param user: - :param metadata: - :param response_format: - :param retries: Override the default retry configuration for this method - :param server_url: Override the default server URL for this method - :param timeout_ms: Override the default request timeout configuration for this method in milliseconds - :param http_headers: Additional headers to set or replace on requests. - """ - base_url = None - url_variables = None - if timeout_ms is None: - timeout_ms = self.sdk_configuration.timeout_ms - - if server_url is not None: - base_url = server_url - else: - base_url = self._get_url(base_url, url_variables) - - request = components.CompletionCreateParams( - model=model, - models=models, - prompt=prompt, - best_of=best_of, - echo=echo, - frequency_penalty=frequency_penalty, - logit_bias=logit_bias, - logprobs=logprobs, - max_tokens=max_tokens, - n=n, - presence_penalty=presence_penalty, - seed=seed, - stop=stop, - stream=stream, - stream_options=utils.get_pydantic_model( - stream_options, OptionalNullable[components.StreamOptions] - ), - suffix=suffix, - temperature=temperature, - top_p=top_p, - user=user, - metadata=metadata, - response_format=utils.get_pydantic_model( - response_format, - OptionalNullable[components.CompletionCreateParamsResponseFormatUnion], - ), - ) - - req = self._build_request( - method="POST", - path="/completions", - base_url=base_url, - url_variables=url_variables, - request=request, - request_body_required=True, - request_has_path_params=False, - request_has_query_params=True, - user_agent_header="user-agent", - accept_header_value="application/json", - http_headers=http_headers, - security=self.sdk_configuration.security, - get_serialized_body=lambda: utils.serialize_request_body( - request, False, False, "json", components.CompletionCreateParams - ), - allow_empty_value=None, - timeout_ms=timeout_ms, - ) - - if retries == UNSET: - if self.sdk_configuration.retry_config is not UNSET: - retries = self.sdk_configuration.retry_config - - retry_config = None - if isinstance(retries, utils.RetryConfig): - retry_config = (retries, ["429", "500", "502", "503", "504"]) - - http_res = self.do_request( - hook_ctx=HookContext( - config=self.sdk_configuration, - base_url=base_url or "", - operation_id="createCompletions", - oauth2_scopes=None, - security_source=get_security_from_env( - self.sdk_configuration.security, components.Security - ), - ), - request=req, - error_status_codes=["400", "401", "429", "4XX", "500", "5XX"], - retry_config=retry_config, - ) - - response_data: Any = None - if utils.match_response(http_res, "200", "application/json"): - return unmarshal_json_response(components.CompletionResponse, http_res) - if utils.match_response(http_res, ["400", "401", "429"], "application/json"): - response_data = unmarshal_json_response(errors.ChatErrorData, http_res) - raise errors.ChatError(response_data, http_res) - if utils.match_response(http_res, "500", "application/json"): - response_data = unmarshal_json_response(errors.ChatErrorData, http_res) - raise errors.ChatError(response_data, http_res) - if utils.match_response(http_res, "4XX", "*"): - http_res_text = utils.stream_to_text(http_res) - raise errors.OpenRouterDefaultError( - "API error occurred", http_res, http_res_text - ) - if utils.match_response(http_res, "5XX", "*"): - http_res_text = utils.stream_to_text(http_res) - raise errors.OpenRouterDefaultError( - "API error occurred", http_res, http_res_text - ) - - raise errors.OpenRouterDefaultError("Unexpected response received", http_res) - - async def generate_async( - self, - *, - prompt: Union[components.Prompt, components.PromptTypedDict], - model: Optional[str] = None, - models: Optional[List[str]] = None, - best_of: OptionalNullable[int] = UNSET, - echo: OptionalNullable[bool] = UNSET, - frequency_penalty: OptionalNullable[float] = UNSET, - logit_bias: OptionalNullable[Dict[str, float]] = UNSET, - logprobs: OptionalNullable[int] = UNSET, - max_tokens: OptionalNullable[int] = UNSET, - n: OptionalNullable[int] = UNSET, - presence_penalty: OptionalNullable[float] = UNSET, - seed: OptionalNullable[int] = UNSET, - stop: OptionalNullable[ - Union[ - components.CompletionCreateParamsStop, - components.CompletionCreateParamsStopTypedDict, - ] - ] = UNSET, - stream: Optional[bool] = False, - stream_options: OptionalNullable[ - Union[components.StreamOptions, components.StreamOptionsTypedDict] - ] = UNSET, - suffix: OptionalNullable[str] = UNSET, - temperature: OptionalNullable[float] = UNSET, - top_p: OptionalNullable[float] = UNSET, - user: Optional[str] = None, - metadata: OptionalNullable[Dict[str, str]] = UNSET, - response_format: OptionalNullable[ - Union[ - components.CompletionCreateParamsResponseFormatUnion, - components.CompletionCreateParamsResponseFormatUnionTypedDict, - ] - ] = UNSET, - retries: OptionalNullable[utils.RetryConfig] = UNSET, - server_url: Optional[str] = None, - timeout_ms: Optional[int] = None, - http_headers: Optional[Mapping[str, str]] = None, - ) -> components.CompletionResponse: - r"""Create a completion - - Creates a completion for the provided prompt and parameters. Supports both streaming and non-streaming modes. - - :param prompt: - :param model: - :param models: - :param best_of: - :param echo: - :param frequency_penalty: - :param logit_bias: - :param logprobs: - :param max_tokens: - :param n: - :param presence_penalty: - :param seed: - :param stop: - :param stream: - :param stream_options: - :param suffix: - :param temperature: - :param top_p: - :param user: - :param metadata: - :param response_format: - :param retries: Override the default retry configuration for this method - :param server_url: Override the default server URL for this method - :param timeout_ms: Override the default request timeout configuration for this method in milliseconds - :param http_headers: Additional headers to set or replace on requests. - """ - base_url = None - url_variables = None - if timeout_ms is None: - timeout_ms = self.sdk_configuration.timeout_ms - - if server_url is not None: - base_url = server_url - else: - base_url = self._get_url(base_url, url_variables) - - request = components.CompletionCreateParams( - model=model, - models=models, - prompt=prompt, - best_of=best_of, - echo=echo, - frequency_penalty=frequency_penalty, - logit_bias=logit_bias, - logprobs=logprobs, - max_tokens=max_tokens, - n=n, - presence_penalty=presence_penalty, - seed=seed, - stop=stop, - stream=stream, - stream_options=utils.get_pydantic_model( - stream_options, OptionalNullable[components.StreamOptions] - ), - suffix=suffix, - temperature=temperature, - top_p=top_p, - user=user, - metadata=metadata, - response_format=utils.get_pydantic_model( - response_format, - OptionalNullable[components.CompletionCreateParamsResponseFormatUnion], - ), - ) - - req = self._build_request_async( - method="POST", - path="/completions", - base_url=base_url, - url_variables=url_variables, - request=request, - request_body_required=True, - request_has_path_params=False, - request_has_query_params=True, - user_agent_header="user-agent", - accept_header_value="application/json", - http_headers=http_headers, - security=self.sdk_configuration.security, - get_serialized_body=lambda: utils.serialize_request_body( - request, False, False, "json", components.CompletionCreateParams - ), - allow_empty_value=None, - timeout_ms=timeout_ms, - ) - - if retries == UNSET: - if self.sdk_configuration.retry_config is not UNSET: - retries = self.sdk_configuration.retry_config - - retry_config = None - if isinstance(retries, utils.RetryConfig): - retry_config = (retries, ["429", "500", "502", "503", "504"]) - - http_res = await self.do_request_async( - hook_ctx=HookContext( - config=self.sdk_configuration, - base_url=base_url or "", - operation_id="createCompletions", - oauth2_scopes=None, - security_source=get_security_from_env( - self.sdk_configuration.security, components.Security - ), - ), - request=req, - error_status_codes=["400", "401", "429", "4XX", "500", "5XX"], - retry_config=retry_config, - ) - - response_data: Any = None - if utils.match_response(http_res, "200", "application/json"): - return unmarshal_json_response(components.CompletionResponse, http_res) - if utils.match_response(http_res, ["400", "401", "429"], "application/json"): - response_data = unmarshal_json_response(errors.ChatErrorData, http_res) - raise errors.ChatError(response_data, http_res) - if utils.match_response(http_res, "500", "application/json"): - response_data = unmarshal_json_response(errors.ChatErrorData, http_res) - raise errors.ChatError(response_data, http_res) - if utils.match_response(http_res, "4XX", "*"): - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.OpenRouterDefaultError( - "API error occurred", http_res, http_res_text - ) - if utils.match_response(http_res, "5XX", "*"): - http_res_text = await utils.stream_to_text_async(http_res) - raise errors.OpenRouterDefaultError( - "API error occurred", http_res, http_res_text - ) - - raise errors.OpenRouterDefaultError("Unexpected response received", http_res) diff --git a/src/openrouter/components/__init__.py b/src/openrouter/components/__init__.py index 94e838c..8cd537b 100644 --- a/src/openrouter/components/__init__.py +++ b/src/openrouter/components/__init__.py @@ -68,16 +68,6 @@ ChatGenerationParamsPreferredMinThroughputUnionTypedDict, ChatGenerationParamsProvider, ChatGenerationParamsProviderTypedDict, - ChatGenerationParamsResponseFormatJSONObject, - ChatGenerationParamsResponseFormatJSONObjectTypedDict, - ChatGenerationParamsResponseFormatPython, - ChatGenerationParamsResponseFormatPythonTypedDict, - ChatGenerationParamsResponseFormatText, - ChatGenerationParamsResponseFormatTextTypedDict, - ChatGenerationParamsResponseFormatUnion, - ChatGenerationParamsResponseFormatUnionTypedDict, - ChatGenerationParamsStop, - ChatGenerationParamsStopTypedDict, ChatGenerationParamsTypedDict, Debug, DebugTypedDict, @@ -90,7 +80,17 @@ Quantizations, Reasoning, ReasoningTypedDict, + ResponseFormat, + ResponseFormatJSONObject, + ResponseFormatJSONObjectTypedDict, + ResponseFormatPython, + ResponseFormatPythonTypedDict, + ResponseFormatText, + ResponseFormatTextTypedDict, + ResponseFormatTypedDict, Route, + Stop, + StopTypedDict, ) from .chatgenerationtokenusage import ( ChatGenerationTokenUsage, @@ -177,32 +177,6 @@ ChatStreamingResponseChunkTypedDict, ) from .chatstreamoptions import ChatStreamOptions, ChatStreamOptionsTypedDict - from .completionchoice import ( - CompletionChoice, - CompletionChoiceTypedDict, - CompletionFinishReason, - ) - from .completioncreateparams import ( - CompletionCreateParams, - CompletionCreateParamsResponseFormatJSONObject, - CompletionCreateParamsResponseFormatJSONObjectTypedDict, - CompletionCreateParamsResponseFormatPython, - CompletionCreateParamsResponseFormatPythonTypedDict, - CompletionCreateParamsResponseFormatText, - CompletionCreateParamsResponseFormatTextTypedDict, - CompletionCreateParamsResponseFormatUnion, - CompletionCreateParamsResponseFormatUnionTypedDict, - CompletionCreateParamsStop, - CompletionCreateParamsStopTypedDict, - CompletionCreateParamsTypedDict, - Prompt, - PromptTypedDict, - StreamOptions, - StreamOptionsTypedDict, - ) - from .completionlogprobs import CompletionLogprobs, CompletionLogprobsTypedDict - from .completionresponse import CompletionResponse, CompletionResponseTypedDict - from .completionusage import CompletionUsage, CompletionUsageTypedDict from .createchargerequest import ( ChainID, CreateChargeRequest, @@ -956,16 +930,6 @@ "ChatGenerationParamsPreferredMinThroughputUnionTypedDict", "ChatGenerationParamsProvider", "ChatGenerationParamsProviderTypedDict", - "ChatGenerationParamsResponseFormatJSONObject", - "ChatGenerationParamsResponseFormatJSONObjectTypedDict", - "ChatGenerationParamsResponseFormatPython", - "ChatGenerationParamsResponseFormatPythonTypedDict", - "ChatGenerationParamsResponseFormatText", - "ChatGenerationParamsResponseFormatTextTypedDict", - "ChatGenerationParamsResponseFormatUnion", - "ChatGenerationParamsResponseFormatUnionTypedDict", - "ChatGenerationParamsStop", - "ChatGenerationParamsStopTypedDict", "ChatGenerationParamsTypedDict", "ChatGenerationTokenUsage", "ChatGenerationTokenUsageTypedDict", @@ -1024,29 +988,8 @@ "Code", "CodeEnum", "CodeTypedDict", - "CompletionChoice", - "CompletionChoiceTypedDict", - "CompletionCreateParams", - "CompletionCreateParamsResponseFormatJSONObject", - "CompletionCreateParamsResponseFormatJSONObjectTypedDict", - "CompletionCreateParamsResponseFormatPython", - "CompletionCreateParamsResponseFormatPythonTypedDict", - "CompletionCreateParamsResponseFormatText", - "CompletionCreateParamsResponseFormatTextTypedDict", - "CompletionCreateParamsResponseFormatUnion", - "CompletionCreateParamsResponseFormatUnionTypedDict", - "CompletionCreateParamsStop", - "CompletionCreateParamsStopTypedDict", - "CompletionCreateParamsTypedDict", - "CompletionFinishReason", - "CompletionLogprobs", - "CompletionLogprobsTypedDict", - "CompletionResponse", - "CompletionResponseTypedDict", "CompletionTokensDetails", "CompletionTokensDetailsTypedDict", - "CompletionUsage", - "CompletionUsageTypedDict", "CostDetails", "CostDetailsTypedDict", "CreateChargeRequest", @@ -1406,10 +1349,8 @@ "PreferredMinThroughputTypedDict", "Pricing", "PricingTypedDict", - "Prompt", "PromptTokensDetails", "PromptTokensDetailsTypedDict", - "PromptTypedDict", "ProviderName", "ProviderOverloadedResponseErrorData", "ProviderOverloadedResponseErrorDataTypedDict", @@ -1456,12 +1397,20 @@ "ReasoningTypedDict", "RequestTimeoutResponseErrorData", "RequestTimeoutResponseErrorDataTypedDict", + "ResponseFormat", + "ResponseFormatJSONObject", + "ResponseFormatJSONObjectTypedDict", "ResponseFormatJSONSchema", "ResponseFormatJSONSchemaTypedDict", + "ResponseFormatPython", + "ResponseFormatPythonTypedDict", + "ResponseFormatText", "ResponseFormatTextConfig", "ResponseFormatTextConfigTypedDict", "ResponseFormatTextGrammar", "ResponseFormatTextGrammarTypedDict", + "ResponseFormatTextTypedDict", + "ResponseFormatTypedDict", "ResponseInputAudio", "ResponseInputAudioFormat", "ResponseInputAudioInputAudio", @@ -1563,8 +1512,8 @@ "ServiceUnavailableResponseErrorData", "ServiceUnavailableResponseErrorDataTypedDict", "SortEnum", - "StreamOptions", - "StreamOptionsTypedDict", + "Stop", + "StopTypedDict", "SystemMessage", "SystemMessageContent", "SystemMessageContentTypedDict", @@ -1688,16 +1637,6 @@ "ChatGenerationParamsPreferredMinThroughputUnionTypedDict": ".chatgenerationparams", "ChatGenerationParamsProvider": ".chatgenerationparams", "ChatGenerationParamsProviderTypedDict": ".chatgenerationparams", - "ChatGenerationParamsResponseFormatJSONObject": ".chatgenerationparams", - "ChatGenerationParamsResponseFormatJSONObjectTypedDict": ".chatgenerationparams", - "ChatGenerationParamsResponseFormatPython": ".chatgenerationparams", - "ChatGenerationParamsResponseFormatPythonTypedDict": ".chatgenerationparams", - "ChatGenerationParamsResponseFormatText": ".chatgenerationparams", - "ChatGenerationParamsResponseFormatTextTypedDict": ".chatgenerationparams", - "ChatGenerationParamsResponseFormatUnion": ".chatgenerationparams", - "ChatGenerationParamsResponseFormatUnionTypedDict": ".chatgenerationparams", - "ChatGenerationParamsStop": ".chatgenerationparams", - "ChatGenerationParamsStopTypedDict": ".chatgenerationparams", "ChatGenerationParamsTypedDict": ".chatgenerationparams", "Debug": ".chatgenerationparams", "DebugTypedDict": ".chatgenerationparams", @@ -1710,7 +1649,17 @@ "Quantizations": ".chatgenerationparams", "Reasoning": ".chatgenerationparams", "ReasoningTypedDict": ".chatgenerationparams", + "ResponseFormat": ".chatgenerationparams", + "ResponseFormatJSONObject": ".chatgenerationparams", + "ResponseFormatJSONObjectTypedDict": ".chatgenerationparams", + "ResponseFormatPython": ".chatgenerationparams", + "ResponseFormatPythonTypedDict": ".chatgenerationparams", + "ResponseFormatText": ".chatgenerationparams", + "ResponseFormatTextTypedDict": ".chatgenerationparams", + "ResponseFormatTypedDict": ".chatgenerationparams", "Route": ".chatgenerationparams", + "Stop": ".chatgenerationparams", + "StopTypedDict": ".chatgenerationparams", "ChatGenerationTokenUsage": ".chatgenerationtokenusage", "ChatGenerationTokenUsageTypedDict": ".chatgenerationtokenusage", "CompletionTokensDetails": ".chatgenerationtokenusage", @@ -1774,31 +1723,6 @@ "ChatStreamingResponseChunkTypedDict": ".chatstreamingresponsechunk", "ChatStreamOptions": ".chatstreamoptions", "ChatStreamOptionsTypedDict": ".chatstreamoptions", - "CompletionChoice": ".completionchoice", - "CompletionChoiceTypedDict": ".completionchoice", - "CompletionFinishReason": ".completionchoice", - "CompletionCreateParams": ".completioncreateparams", - "CompletionCreateParamsResponseFormatJSONObject": ".completioncreateparams", - "CompletionCreateParamsResponseFormatJSONObjectTypedDict": ".completioncreateparams", - "CompletionCreateParamsResponseFormatPython": ".completioncreateparams", - "CompletionCreateParamsResponseFormatPythonTypedDict": ".completioncreateparams", - "CompletionCreateParamsResponseFormatText": ".completioncreateparams", - "CompletionCreateParamsResponseFormatTextTypedDict": ".completioncreateparams", - "CompletionCreateParamsResponseFormatUnion": ".completioncreateparams", - "CompletionCreateParamsResponseFormatUnionTypedDict": ".completioncreateparams", - "CompletionCreateParamsStop": ".completioncreateparams", - "CompletionCreateParamsStopTypedDict": ".completioncreateparams", - "CompletionCreateParamsTypedDict": ".completioncreateparams", - "Prompt": ".completioncreateparams", - "PromptTypedDict": ".completioncreateparams", - "StreamOptions": ".completioncreateparams", - "StreamOptionsTypedDict": ".completioncreateparams", - "CompletionLogprobs": ".completionlogprobs", - "CompletionLogprobsTypedDict": ".completionlogprobs", - "CompletionResponse": ".completionresponse", - "CompletionResponseTypedDict": ".completionresponse", - "CompletionUsage": ".completionusage", - "CompletionUsageTypedDict": ".completionusage", "ChainID": ".createchargerequest", "CreateChargeRequest": ".createchargerequest", "CreateChargeRequestTypedDict": ".createchargerequest", diff --git a/src/openrouter/components/chatgenerationparams.py b/src/openrouter/components/chatgenerationparams.py index 226d298..028e280 100644 --- a/src/openrouter/components/chatgenerationparams.py +++ b/src/openrouter/components/chatgenerationparams.py @@ -562,22 +562,22 @@ def serialize_model(self, handler): return m -class ChatGenerationParamsResponseFormatPythonTypedDict(TypedDict): +class ResponseFormatPythonTypedDict(TypedDict): type: Literal["python"] -class ChatGenerationParamsResponseFormatPython(BaseModel): +class ResponseFormatPython(BaseModel): TYPE: Annotated[ Annotated[Literal["python"], AfterValidator(validate_const("python"))], pydantic.Field(alias="type"), ] = "python" -class ChatGenerationParamsResponseFormatJSONObjectTypedDict(TypedDict): +class ResponseFormatJSONObjectTypedDict(TypedDict): type: Literal["json_object"] -class ChatGenerationParamsResponseFormatJSONObject(BaseModel): +class ResponseFormatJSONObject(BaseModel): TYPE: Annotated[ Annotated[ Literal["json_object"], AfterValidator(validate_const("json_object")) @@ -586,49 +586,45 @@ class ChatGenerationParamsResponseFormatJSONObject(BaseModel): ] = "json_object" -class ChatGenerationParamsResponseFormatTextTypedDict(TypedDict): +class ResponseFormatTextTypedDict(TypedDict): type: Literal["text"] -class ChatGenerationParamsResponseFormatText(BaseModel): +class ResponseFormatText(BaseModel): TYPE: Annotated[ Annotated[Literal["text"], AfterValidator(validate_const("text"))], pydantic.Field(alias="type"), ] = "text" -ChatGenerationParamsResponseFormatUnionTypedDict = TypeAliasType( - "ChatGenerationParamsResponseFormatUnionTypedDict", +ResponseFormatTypedDict = TypeAliasType( + "ResponseFormatTypedDict", Union[ - ChatGenerationParamsResponseFormatTextTypedDict, - ChatGenerationParamsResponseFormatJSONObjectTypedDict, - ChatGenerationParamsResponseFormatPythonTypedDict, + ResponseFormatTextTypedDict, + ResponseFormatJSONObjectTypedDict, + ResponseFormatPythonTypedDict, ResponseFormatJSONSchemaTypedDict, ResponseFormatTextGrammarTypedDict, ], ) -ChatGenerationParamsResponseFormatUnion = Annotated[ +ResponseFormat = Annotated[ Union[ - Annotated[ChatGenerationParamsResponseFormatText, Tag("text")], - Annotated[ChatGenerationParamsResponseFormatJSONObject, Tag("json_object")], + Annotated[ResponseFormatText, Tag("text")], + Annotated[ResponseFormatJSONObject, Tag("json_object")], Annotated[ResponseFormatJSONSchema, Tag("json_schema")], Annotated[ResponseFormatTextGrammar, Tag("grammar")], - Annotated[ChatGenerationParamsResponseFormatPython, Tag("python")], + Annotated[ResponseFormatPython, Tag("python")], ], Discriminator(lambda m: get_discriminator(m, "type", "type")), ] -ChatGenerationParamsStopTypedDict = TypeAliasType( - "ChatGenerationParamsStopTypedDict", Union[str, List[str]] -) +StopTypedDict = TypeAliasType("StopTypedDict", Union[str, List[str]]) -ChatGenerationParamsStop = TypeAliasType( - "ChatGenerationParamsStop", Union[str, List[str]] -) +Stop = TypeAliasType("Stop", Union[str, List[str]]) class DebugTypedDict(TypedDict): @@ -679,9 +675,9 @@ class ChatGenerationParamsTypedDict(TypedDict): metadata: NotRequired[Dict[str, str]] presence_penalty: NotRequired[Nullable[float]] reasoning: NotRequired[ReasoningTypedDict] - response_format: NotRequired[ChatGenerationParamsResponseFormatUnionTypedDict] + response_format: NotRequired[ResponseFormatTypedDict] seed: NotRequired[Nullable[int]] - stop: NotRequired[Nullable[ChatGenerationParamsStopTypedDict]] + stop: NotRequired[Nullable[StopTypedDict]] stream: NotRequired[bool] stream_options: NotRequired[Nullable[ChatStreamOptionsTypedDict]] temperature: NotRequired[Nullable[float]] @@ -733,11 +729,11 @@ class ChatGenerationParams(BaseModel): reasoning: Optional[Reasoning] = None - response_format: Optional[ChatGenerationParamsResponseFormatUnion] = None + response_format: Optional[ResponseFormat] = None seed: OptionalNullable[int] = UNSET - stop: OptionalNullable[ChatGenerationParamsStop] = UNSET + stop: OptionalNullable[Stop] = UNSET stream: Optional[bool] = False diff --git a/src/openrouter/components/completionchoice.py b/src/openrouter/components/completionchoice.py deleted file mode 100644 index 21ce2b9..0000000 --- a/src/openrouter/components/completionchoice.py +++ /dev/null @@ -1,82 +0,0 @@ -"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" - -from __future__ import annotations -from .completionlogprobs import CompletionLogprobs, CompletionLogprobsTypedDict -from openrouter.types import ( - BaseModel, - Nullable, - OptionalNullable, - UNSET, - UNSET_SENTINEL, - UnrecognizedStr, -) -from openrouter.utils import validate_open_enum -from pydantic import model_serializer -from pydantic.functional_validators import PlainValidator -from typing import Literal, Optional, Union -from typing_extensions import Annotated, NotRequired, TypedDict - - -CompletionFinishReason = Union[ - Literal[ - "stop", - "length", - "content_filter", - ], - UnrecognizedStr, -] - - -class CompletionChoiceTypedDict(TypedDict): - text: str - index: float - logprobs: Nullable[CompletionLogprobsTypedDict] - finish_reason: Nullable[CompletionFinishReason] - native_finish_reason: NotRequired[str] - reasoning: NotRequired[Nullable[str]] - - -class CompletionChoice(BaseModel): - text: str - - index: float - - logprobs: Nullable[CompletionLogprobs] - - finish_reason: Annotated[ - Nullable[CompletionFinishReason], PlainValidator(validate_open_enum(False)) - ] - - native_finish_reason: Optional[str] = None - - reasoning: OptionalNullable[str] = UNSET - - @model_serializer(mode="wrap") - def serialize_model(self, handler): - optional_fields = ["native_finish_reason", "reasoning"] - nullable_fields = ["logprobs", "finish_reason", "reasoning"] - null_default_fields = [] - - serialized = handler(self) - - m = {} - - for n, f in type(self).model_fields.items(): - k = f.alias or n - val = serialized.get(k) - serialized.pop(k, None) - - optional_nullable = k in optional_fields and k in nullable_fields - is_set = ( - self.__pydantic_fields_set__.intersection({n}) - or k in null_default_fields - ) # pylint: disable=no-member - - if val is not None and val != UNSET_SENTINEL: - m[k] = val - elif val != UNSET_SENTINEL and ( - not k in optional_fields or (optional_nullable and is_set) - ): - m[k] = val - - return m diff --git a/src/openrouter/components/completioncreateparams.py b/src/openrouter/components/completioncreateparams.py deleted file mode 100644 index 712feaa..0000000 --- a/src/openrouter/components/completioncreateparams.py +++ /dev/null @@ -1,277 +0,0 @@ -"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" - -from __future__ import annotations -from .responseformatjsonschema import ( - ResponseFormatJSONSchema, - ResponseFormatJSONSchemaTypedDict, -) -from .responseformattextgrammar import ( - ResponseFormatTextGrammar, - ResponseFormatTextGrammarTypedDict, -) -from openrouter.types import ( - BaseModel, - Nullable, - OptionalNullable, - UNSET, - UNSET_SENTINEL, -) -from openrouter.utils import get_discriminator, validate_const -import pydantic -from pydantic import Discriminator, Tag, model_serializer -from pydantic.functional_validators import AfterValidator -from typing import Dict, List, Literal, Optional, Union -from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict - - -PromptTypedDict = TypeAliasType( - "PromptTypedDict", Union[str, List[str], List[float], List[List[float]]] -) - - -Prompt = TypeAliasType("Prompt", Union[str, List[str], List[float], List[List[float]]]) - - -CompletionCreateParamsStopTypedDict = TypeAliasType( - "CompletionCreateParamsStopTypedDict", Union[str, List[str]] -) - - -CompletionCreateParamsStop = TypeAliasType( - "CompletionCreateParamsStop", Union[str, List[str]] -) - - -class StreamOptionsTypedDict(TypedDict): - include_usage: NotRequired[Nullable[bool]] - - -class StreamOptions(BaseModel): - include_usage: OptionalNullable[bool] = UNSET - - @model_serializer(mode="wrap") - def serialize_model(self, handler): - optional_fields = ["include_usage"] - nullable_fields = ["include_usage"] - null_default_fields = [] - - serialized = handler(self) - - m = {} - - for n, f in type(self).model_fields.items(): - k = f.alias or n - val = serialized.get(k) - serialized.pop(k, None) - - optional_nullable = k in optional_fields and k in nullable_fields - is_set = ( - self.__pydantic_fields_set__.intersection({n}) - or k in null_default_fields - ) # pylint: disable=no-member - - if val is not None and val != UNSET_SENTINEL: - m[k] = val - elif val != UNSET_SENTINEL and ( - not k in optional_fields or (optional_nullable and is_set) - ): - m[k] = val - - return m - - -class CompletionCreateParamsResponseFormatPythonTypedDict(TypedDict): - type: Literal["python"] - - -class CompletionCreateParamsResponseFormatPython(BaseModel): - TYPE: Annotated[ - Annotated[Literal["python"], AfterValidator(validate_const("python"))], - pydantic.Field(alias="type"), - ] = "python" - - -class CompletionCreateParamsResponseFormatJSONObjectTypedDict(TypedDict): - type: Literal["json_object"] - - -class CompletionCreateParamsResponseFormatJSONObject(BaseModel): - TYPE: Annotated[ - Annotated[ - Literal["json_object"], AfterValidator(validate_const("json_object")) - ], - pydantic.Field(alias="type"), - ] = "json_object" - - -class CompletionCreateParamsResponseFormatTextTypedDict(TypedDict): - type: Literal["text"] - - -class CompletionCreateParamsResponseFormatText(BaseModel): - TYPE: Annotated[ - Annotated[Literal["text"], AfterValidator(validate_const("text"))], - pydantic.Field(alias="type"), - ] = "text" - - -CompletionCreateParamsResponseFormatUnionTypedDict = TypeAliasType( - "CompletionCreateParamsResponseFormatUnionTypedDict", - Union[ - CompletionCreateParamsResponseFormatTextTypedDict, - CompletionCreateParamsResponseFormatJSONObjectTypedDict, - CompletionCreateParamsResponseFormatPythonTypedDict, - ResponseFormatJSONSchemaTypedDict, - ResponseFormatTextGrammarTypedDict, - ], -) - - -CompletionCreateParamsResponseFormatUnion = Annotated[ - Union[ - Annotated[CompletionCreateParamsResponseFormatText, Tag("text")], - Annotated[CompletionCreateParamsResponseFormatJSONObject, Tag("json_object")], - Annotated[ResponseFormatJSONSchema, Tag("json_schema")], - Annotated[ResponseFormatTextGrammar, Tag("grammar")], - Annotated[CompletionCreateParamsResponseFormatPython, Tag("python")], - ], - Discriminator(lambda m: get_discriminator(m, "type", "type")), -] - - -class CompletionCreateParamsTypedDict(TypedDict): - prompt: PromptTypedDict - model: NotRequired[str] - models: NotRequired[List[str]] - best_of: NotRequired[Nullable[int]] - echo: NotRequired[Nullable[bool]] - frequency_penalty: NotRequired[Nullable[float]] - logit_bias: NotRequired[Nullable[Dict[str, float]]] - logprobs: NotRequired[Nullable[int]] - max_tokens: NotRequired[Nullable[int]] - n: NotRequired[Nullable[int]] - presence_penalty: NotRequired[Nullable[float]] - seed: NotRequired[Nullable[int]] - stop: NotRequired[Nullable[CompletionCreateParamsStopTypedDict]] - stream: NotRequired[bool] - stream_options: NotRequired[Nullable[StreamOptionsTypedDict]] - suffix: NotRequired[Nullable[str]] - temperature: NotRequired[Nullable[float]] - top_p: NotRequired[Nullable[float]] - user: NotRequired[str] - metadata: NotRequired[Nullable[Dict[str, str]]] - response_format: NotRequired[ - Nullable[CompletionCreateParamsResponseFormatUnionTypedDict] - ] - - -class CompletionCreateParams(BaseModel): - prompt: Prompt - - model: Optional[str] = None - - models: Optional[List[str]] = None - - best_of: OptionalNullable[int] = UNSET - - echo: OptionalNullable[bool] = UNSET - - frequency_penalty: OptionalNullable[float] = UNSET - - logit_bias: OptionalNullable[Dict[str, float]] = UNSET - - logprobs: OptionalNullable[int] = UNSET - - max_tokens: OptionalNullable[int] = UNSET - - n: OptionalNullable[int] = UNSET - - presence_penalty: OptionalNullable[float] = UNSET - - seed: OptionalNullable[int] = UNSET - - stop: OptionalNullable[CompletionCreateParamsStop] = UNSET - - stream: Optional[bool] = False - - stream_options: OptionalNullable[StreamOptions] = UNSET - - suffix: OptionalNullable[str] = UNSET - - temperature: OptionalNullable[float] = UNSET - - top_p: OptionalNullable[float] = UNSET - - user: Optional[str] = None - - metadata: OptionalNullable[Dict[str, str]] = UNSET - - response_format: OptionalNullable[CompletionCreateParamsResponseFormatUnion] = UNSET - - @model_serializer(mode="wrap") - def serialize_model(self, handler): - optional_fields = [ - "model", - "models", - "best_of", - "echo", - "frequency_penalty", - "logit_bias", - "logprobs", - "max_tokens", - "n", - "presence_penalty", - "seed", - "stop", - "stream", - "stream_options", - "suffix", - "temperature", - "top_p", - "user", - "metadata", - "response_format", - ] - nullable_fields = [ - "best_of", - "echo", - "frequency_penalty", - "logit_bias", - "logprobs", - "max_tokens", - "n", - "presence_penalty", - "seed", - "stop", - "stream_options", - "suffix", - "temperature", - "top_p", - "metadata", - "response_format", - ] - null_default_fields = [] - - serialized = handler(self) - - m = {} - - for n, f in type(self).model_fields.items(): - k = f.alias or n - val = serialized.get(k) - serialized.pop(k, None) - - optional_nullable = k in optional_fields and k in nullable_fields - is_set = ( - self.__pydantic_fields_set__.intersection({n}) - or k in null_default_fields - ) # pylint: disable=no-member - - if val is not None and val != UNSET_SENTINEL: - m[k] = val - elif val != UNSET_SENTINEL and ( - not k in optional_fields or (optional_nullable and is_set) - ): - m[k] = val - - return m diff --git a/src/openrouter/components/completionlogprobs.py b/src/openrouter/components/completionlogprobs.py deleted file mode 100644 index 758ccd1..0000000 --- a/src/openrouter/components/completionlogprobs.py +++ /dev/null @@ -1,54 +0,0 @@ -"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" - -from __future__ import annotations -from openrouter.types import BaseModel, Nullable, UNSET_SENTINEL -from pydantic import model_serializer -from typing import Dict, List -from typing_extensions import TypedDict - - -class CompletionLogprobsTypedDict(TypedDict): - tokens: List[str] - token_logprobs: List[float] - top_logprobs: Nullable[List[Dict[str, float]]] - text_offset: List[float] - - -class CompletionLogprobs(BaseModel): - tokens: List[str] - - token_logprobs: List[float] - - top_logprobs: Nullable[List[Dict[str, float]]] - - text_offset: List[float] - - @model_serializer(mode="wrap") - def serialize_model(self, handler): - optional_fields = [] - nullable_fields = ["top_logprobs"] - null_default_fields = [] - - serialized = handler(self) - - m = {} - - for n, f in type(self).model_fields.items(): - k = f.alias or n - val = serialized.get(k) - serialized.pop(k, None) - - optional_nullable = k in optional_fields and k in nullable_fields - is_set = ( - self.__pydantic_fields_set__.intersection({n}) - or k in null_default_fields - ) # pylint: disable=no-member - - if val is not None and val != UNSET_SENTINEL: - m[k] = val - elif val != UNSET_SENTINEL and ( - not k in optional_fields or (optional_nullable and is_set) - ): - m[k] = val - - return m diff --git a/src/openrouter/components/completionresponse.py b/src/openrouter/components/completionresponse.py deleted file mode 100644 index dcdd529..0000000 --- a/src/openrouter/components/completionresponse.py +++ /dev/null @@ -1,46 +0,0 @@ -"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" - -from __future__ import annotations -from .completionchoice import CompletionChoice, CompletionChoiceTypedDict -from .completionusage import CompletionUsage, CompletionUsageTypedDict -from openrouter.types import BaseModel -from openrouter.utils import validate_const -import pydantic -from pydantic.functional_validators import AfterValidator -from typing import List, Literal, Optional -from typing_extensions import Annotated, NotRequired, TypedDict - - -class CompletionResponseTypedDict(TypedDict): - id: str - created: float - model: str - choices: List[CompletionChoiceTypedDict] - object: Literal["text_completion"] - provider: NotRequired[str] - system_fingerprint: NotRequired[str] - usage: NotRequired[CompletionUsageTypedDict] - - -class CompletionResponse(BaseModel): - id: str - - created: float - - model: str - - choices: List[CompletionChoice] - - OBJECT: Annotated[ - Annotated[ - Literal["text_completion"], - AfterValidator(validate_const("text_completion")), - ], - pydantic.Field(alias="object"), - ] = "text_completion" - - provider: Optional[str] = None - - system_fingerprint: Optional[str] = None - - usage: Optional[CompletionUsage] = None diff --git a/src/openrouter/components/completionusage.py b/src/openrouter/components/completionusage.py deleted file mode 100644 index 80bba78..0000000 --- a/src/openrouter/components/completionusage.py +++ /dev/null @@ -1,19 +0,0 @@ -"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" - -from __future__ import annotations -from openrouter.types import BaseModel -from typing_extensions import TypedDict - - -class CompletionUsageTypedDict(TypedDict): - prompt_tokens: float - completion_tokens: float - total_tokens: float - - -class CompletionUsage(BaseModel): - prompt_tokens: float - - completion_tokens: float - - total_tokens: float diff --git a/src/openrouter/models_.py b/src/openrouter/models_.py index a3d8d13..f45fa28 100644 --- a/src/openrouter/models_.py +++ b/src/openrouter/models_.py @@ -394,7 +394,9 @@ def list_for_user( timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.ModelsListResponse: - r"""List models filtered by user provider preferences + r"""List models filtered by user provider preferences, privacy settings, and guardrails + + List models filtered by user provider preferences, [privacy settings](https://openrouter.ai/docs/guides/privacy/logging), and [guardrails](https://openrouter.ai/docs/guides/features/guardrails). If requesting through `eu.openrouter.ai/api/v1/...` the results will be filtered to models that satisfy [EU in-region routing](https://openrouter.ai/docs/guides/privacy/logging#enterprise-eu-in-region-routing). :param security: :param retries: Override the default retry configuration for this method @@ -447,7 +449,7 @@ def list_for_user( security_source=get_security_from_env(security, components.Security), ), request=req, - error_status_codes=["401", "4XX", "500", "5XX"], + error_status_codes=["401", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) @@ -459,6 +461,11 @@ def list_for_user( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) + if utils.match_response(http_res, "404", "application/json"): + response_data = unmarshal_json_response( + errors.NotFoundResponseErrorData, http_res + ) + raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res @@ -489,7 +496,9 @@ async def list_for_user_async( timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.ModelsListResponse: - r"""List models filtered by user provider preferences + r"""List models filtered by user provider preferences, privacy settings, and guardrails + + List models filtered by user provider preferences, [privacy settings](https://openrouter.ai/docs/guides/privacy/logging), and [guardrails](https://openrouter.ai/docs/guides/features/guardrails). If requesting through `eu.openrouter.ai/api/v1/...` the results will be filtered to models that satisfy [EU in-region routing](https://openrouter.ai/docs/guides/privacy/logging#enterprise-eu-in-region-routing). :param security: :param retries: Override the default retry configuration for this method @@ -542,7 +551,7 @@ async def list_for_user_async( security_source=get_security_from_env(security, components.Security), ), request=req, - error_status_codes=["401", "4XX", "500", "5XX"], + error_status_codes=["401", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) @@ -554,6 +563,11 @@ async def list_for_user_async( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) + if utils.match_response(http_res, "404", "application/json"): + response_data = unmarshal_json_response( + errors.NotFoundResponseErrorData, http_res + ) + raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res diff --git a/src/openrouter/sdk.py b/src/openrouter/sdk.py index 03b39eb..062548f 100644 --- a/src/openrouter/sdk.py +++ b/src/openrouter/sdk.py @@ -20,7 +20,6 @@ from openrouter.api_keys import APIKeys from openrouter.beta import Beta from openrouter.chat import Chat - from openrouter.completions import Completions from openrouter.credits import Credits from openrouter.embeddings import Embeddings from openrouter.endpoints import Endpoints @@ -32,7 +31,7 @@ class OpenRouter(BaseSDK): - r"""OpenRouter API: OpenAI-compatible Chat Completions and Completions API with additional OpenRouter features + r"""OpenRouter API: OpenAI-compatible API with additional OpenRouter features https://openrouter.ai/docs - OpenRouter Documentation """ @@ -58,7 +57,6 @@ class OpenRouter(BaseSDK): o_auth: "OAuth" r"""OAuth authentication endpoints""" chat: "Chat" - completions: "Completions" _sub_sdk_map = { "beta": ("openrouter.beta", "Beta"), "analytics": ("openrouter.analytics", "Analytics"), @@ -72,7 +70,6 @@ class OpenRouter(BaseSDK): "guardrails": ("openrouter.guardrails", "Guardrails"), "o_auth": ("openrouter.oauth", "OAuth"), "chat": ("openrouter.chat", "Chat"), - "completions": ("openrouter.completions", "Completions"), } def __init__( diff --git a/uv.lock b/uv.lock index 25699b8..6b1deff 100644 --- a/uv.lock +++ b/uv.lock @@ -211,7 +211,7 @@ wheels = [ [[package]] name = "openrouter" -version = "0.1.3" +version = "0.2.0" source = { editable = "." } dependencies = [ { name = "httpcore" },