Compare commits

...
Author SHA1 Message Date
OpenRouter Team d68c2bab47 Commits included in this export:
- 123bbdaf841d299162a82ee2573adfbb70a45b8f
  - ac457b8a8dad98fdf5ddcae8dd4711361cea3084
  - ea825199f4c59dd68fec01cf8d18a582963c9f25
  - 4d48e4f6bb936e785787314a965298da6b78fea0
  - 718729a573ee98893a4408d5a52ab4686661fe54
  - b867adcde6b64f3f2a11c4626254b39098e4b0b4
  - 21912c097b4066d109766c6b4492826595cd57c5
  - bc1ed85adc976a4634ca8a41b82e4fc2c39a864f
  - d145c89c941937a312ed1357590d2bfda9a3603d
  - 12f05b5dee397ead47cfcd545a7a2e3c7ff57524
  - dd28f75a19a015809797c7abf3f8758f7c37262e
  - c96e569781e07ab44172d9c69940ec17bafd81f4
  - c9d5a90e3c2b5077a2bdd49773f1a46d1a5a79c7
  - 58b08f87116ceab9076de2fdc0a4c74c919b44c4

GitOrigin-RevId: 123bbdaf841d299162a82ee2573adfbb70a45b8f
2026-01-27 15:29:05 +00:00
42 changed files with 181 additions and 2010 deletions
+10 -28
View File
@@ -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.3.1
configChecksum: 9111dd60e0cc70eb4ba398a71f02a40f
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:
+1 -1
View File
@@ -31,7 +31,7 @@ generation:
skipResponseBodyAssertions: false
preApplyUnionDiscriminators: true
python:
version: 0.1.3
version: 0.3.1
additionalDependencies:
dev: {}
main: {}
+17 -313
View File
@@ -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: /
+13 -314
View File
@@ -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: /
+6 -5
View File
@@ -8,19 +8,20 @@ sources:
- latest
OpenRouter API:
sourceNamespace: open-router-chat-completions-api
sourceRevisionDigest: sha256:291e215687f85db05005d79dd87602a75b8086f39a841700fdbaaff7690b4f76
sourceBlobDigest: sha256:166639d08f0ae9687cea532ed8a93db59e63293c6a6f4d17d63f015b60d643d2
sourceRevisionDigest: sha256:5ba48c1ff7f13c2c5d9ab558e9ecd4638b65c12dd9c4e0cff7fb337674e94ceb
sourceBlobDigest: sha256:082db9694677b85116bda99811c8b957f96d1c493a3c606643479a65dad79730
tags:
- latest
- main
- 1.0.0
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:116feda356a202c5508dfe68daec83b7a490e6c311f6829eda3729cae7256e6d
workflow:
workflowVersion: 1.0.0
speakeasyVersion: 1.666.0
+2 -2
View File
@@ -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 |
@@ -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 */
```
-13
View File
@@ -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 |
-28
View File
@@ -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 |
@@ -1,8 +0,0 @@
# CompletionCreateParamsResponseFormatJSONObject
## Fields
| Field | Type | Required | Description |
| ------------------------ | ------------------------ | ------------------------ | ------------------------ |
| `type` | *Literal["json_object"]* | :heavy_check_mark: | N/A |
@@ -1,8 +0,0 @@
# CompletionCreateParamsResponseFormatPython
## Fields
| Field | Type | Required | Description |
| ------------------- | ------------------- | ------------------- | ------------------- |
| `type` | *Literal["python"]* | :heavy_check_mark: | N/A |
@@ -1,8 +0,0 @@
# CompletionCreateParamsResponseFormatText
## Fields
| Field | Type | Required | Description |
| ------------------ | ------------------ | ------------------ | ------------------ |
| `type` | *Literal["text"]* | :heavy_check_mark: | N/A |
@@ -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 */
```
@@ -1,17 +0,0 @@
# CompletionCreateParamsStop
## Supported Types
### `str`
```python
value: str = /* values here */
```
### `List[str]`
```python
value: List[str] = /* values here */
```
-10
View File
@@ -1,10 +0,0 @@
# CompletionFinishReason
## Values
| Name | Value |
| ---------------- | ---------------- |
| `STOP` | stop |
| `LENGTH` | length |
| `CONTENT_FILTER` | content_filter |
-11
View File
@@ -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 |
-15
View File
@@ -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 |
-10
View File
@@ -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 |
-29
View File
@@ -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 */
```
+35
View File
@@ -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 */
```
@@ -1,4 +1,4 @@
# ChatGenerationParamsResponseFormatJSONObject
# ResponseFormatJSONObject
## Fields
@@ -1,4 +1,4 @@
# ChatGenerationParamsResponseFormatPython
# ResponseFormatPython
## Fields
@@ -1,4 +1,4 @@
# ChatGenerationParamsResponseFormatText
# ResponseFormatText
## Fields
@@ -1,4 +1,4 @@
# ChatGenerationParamsStop
# Stop
## Supported Types
-8
View File
@@ -1,8 +0,0 @@
# StreamOptions
## Fields
| Field | Type | Required | Description |
| ------------------------ | ------------------------ | ------------------------ | ------------------------ |
| `include_usage` | *OptionalNullable[bool]* | :heavy_minus_sign: | N/A |
+2 -2
View File
@@ -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 |
-70
View File
@@ -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
<!-- UsageSnippet language="python" operationID="createCompletions" method="post" path="/completions" -->
```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 | \*/\* |
+3 -2
View File
@@ -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 | \*/\* |
+1 -1
View File
@@ -1,6 +1,6 @@
[project]
name = "openrouter"
version = "0.1.3"
version = "0.3.1"
description = "Official Python Client SDK for OpenRouter."
authors = [{ name = "OpenRouter" },]
readme = "README-PYPI.md"
+2 -2
View File
@@ -3,10 +3,10 @@
import importlib.metadata
__title__: str = "openrouter"
__version__: str = "0.1.3"
__version__: str = "0.3.1"
__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.3.1 2.768.0 1.0.0 openrouter"
try:
if __package__ is not None:
+14 -52
View File
@@ -50,17 +50,11 @@ class Chat(BaseSDK):
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 @@ class Chat(BaseSDK):
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 @@ class Chat(BaseSDK):
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 @@ class Chat(BaseSDK):
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 @@ class Chat(BaseSDK):
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 @@ class Chat(BaseSDK):
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 @@ class Chat(BaseSDK):
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 @@ class Chat(BaseSDK):
reasoning, Optional[components.Reasoning]
),
response_format=utils.get_pydantic_model(
response_format,
Optional[components.ChatGenerationParamsResponseFormatUnion],
response_format, Optional[components.ResponseFormat]
),
seed=seed,
stop=stop,
-361
View File
@@ -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)
+30 -106
View File
@@ -68,16 +68,6 @@ if TYPE_CHECKING:
ChatGenerationParamsPreferredMinThroughputUnionTypedDict,
ChatGenerationParamsProvider,
ChatGenerationParamsProviderTypedDict,
ChatGenerationParamsResponseFormatJSONObject,
ChatGenerationParamsResponseFormatJSONObjectTypedDict,
ChatGenerationParamsResponseFormatPython,
ChatGenerationParamsResponseFormatPythonTypedDict,
ChatGenerationParamsResponseFormatText,
ChatGenerationParamsResponseFormatTextTypedDict,
ChatGenerationParamsResponseFormatUnion,
ChatGenerationParamsResponseFormatUnionTypedDict,
ChatGenerationParamsStop,
ChatGenerationParamsStopTypedDict,
ChatGenerationParamsTypedDict,
Debug,
DebugTypedDict,
@@ -90,7 +80,17 @@ if TYPE_CHECKING:
Quantizations,
Reasoning,
ReasoningTypedDict,
ResponseFormat,
ResponseFormatJSONObject,
ResponseFormatJSONObjectTypedDict,
ResponseFormatPython,
ResponseFormatPythonTypedDict,
ResponseFormatText,
ResponseFormatTextTypedDict,
ResponseFormatTypedDict,
Route,
Stop,
StopTypedDict,
)
from .chatgenerationtokenusage import (
ChatGenerationTokenUsage,
@@ -177,32 +177,6 @@ if TYPE_CHECKING:
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 @@ __all__ = [
"ChatGenerationParamsPreferredMinThroughputUnionTypedDict",
"ChatGenerationParamsProvider",
"ChatGenerationParamsProviderTypedDict",
"ChatGenerationParamsResponseFormatJSONObject",
"ChatGenerationParamsResponseFormatJSONObjectTypedDict",
"ChatGenerationParamsResponseFormatPython",
"ChatGenerationParamsResponseFormatPythonTypedDict",
"ChatGenerationParamsResponseFormatText",
"ChatGenerationParamsResponseFormatTextTypedDict",
"ChatGenerationParamsResponseFormatUnion",
"ChatGenerationParamsResponseFormatUnionTypedDict",
"ChatGenerationParamsStop",
"ChatGenerationParamsStopTypedDict",
"ChatGenerationParamsTypedDict",
"ChatGenerationTokenUsage",
"ChatGenerationTokenUsageTypedDict",
@@ -1024,29 +988,8 @@ __all__ = [
"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 @@ __all__ = [
"PreferredMinThroughputTypedDict",
"Pricing",
"PricingTypedDict",
"Prompt",
"PromptTokensDetails",
"PromptTokensDetailsTypedDict",
"PromptTypedDict",
"ProviderName",
"ProviderOverloadedResponseErrorData",
"ProviderOverloadedResponseErrorDataTypedDict",
@@ -1456,12 +1397,20 @@ __all__ = [
"ReasoningTypedDict",
"RequestTimeoutResponseErrorData",
"RequestTimeoutResponseErrorDataTypedDict",
"ResponseFormat",
"ResponseFormatJSONObject",
"ResponseFormatJSONObjectTypedDict",
"ResponseFormatJSONSchema",
"ResponseFormatJSONSchemaTypedDict",
"ResponseFormatPython",
"ResponseFormatPythonTypedDict",
"ResponseFormatText",
"ResponseFormatTextConfig",
"ResponseFormatTextConfigTypedDict",
"ResponseFormatTextGrammar",
"ResponseFormatTextGrammarTypedDict",
"ResponseFormatTextTypedDict",
"ResponseFormatTypedDict",
"ResponseInputAudio",
"ResponseInputAudioFormat",
"ResponseInputAudioInputAudio",
@@ -1563,8 +1512,8 @@ __all__ = [
"ServiceUnavailableResponseErrorData",
"ServiceUnavailableResponseErrorDataTypedDict",
"SortEnum",
"StreamOptions",
"StreamOptionsTypedDict",
"Stop",
"StopTypedDict",
"SystemMessage",
"SystemMessageContent",
"SystemMessageContentTypedDict",
@@ -1688,16 +1637,6 @@ _dynamic_imports: dict[str, str] = {
"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 @@ _dynamic_imports: dict[str, str] = {
"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 @@ _dynamic_imports: dict[str, str] = {
"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",
@@ -562,22 +562,22 @@ class Reasoning(BaseModel):
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
+18 -4
View File
@@ -394,7 +394,9 @@ class Models(BaseSDK):
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 @@ class Models(BaseSDK):
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 @@ class Models(BaseSDK):
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 @@ class Models(BaseSDK):
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 @@ class Models(BaseSDK):
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 @@ class Models(BaseSDK):
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
+1 -4
View File
@@ -20,7 +20,6 @@ if TYPE_CHECKING:
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 @@ if TYPE_CHECKING:
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__(
Generated
+1 -1
View File
@@ -211,7 +211,7 @@ wheels = [
[[package]]
name = "openrouter"
version = "0.1.3"
version = "0.2.0"
source = { editable = "." }
dependencies = [
{ name = "httpcore" },