Compare commits

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

GitOrigin-RevId: e1074ff86fccf5e48406b7595298873106d3cc5a
2026-01-28 18:45:29 +00:00
51 changed files with 787 additions and 2048 deletions
+13 -29
View File
@@ -1,12 +1,12 @@
lockVersion: 2.0.0
id: cfd52247-6a25-4c6d-bbce-fe6fce0cd69d
management:
docChecksum: 7136b263714e485a5a96ee056b6e3f36
docChecksum: b46bf86766cf18470329da1fb2271f4e
docVersion: 1.0.0
speakeasyVersion: 1.666.0
generationVersion: 2.768.0
releaseVersion: 0.1.3
configChecksum: d03f8606816d7028a10e566c4ff2ac44
releaseVersion: 0.3.2
configChecksum: 684039465cd4c6f0105466ef2833908d
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
@@ -606,6 +593,8 @@ generatedFiles:
- docs/operations/metadata.md
- docs/operations/object.md
- docs/operations/objectembedding.md
- docs/operations/providername.md
- docs/operations/providerresponse.md
- docs/operations/ratelimit.md
- docs/operations/sendchatcompletionrequestresponse.md
- docs/operations/transferintent.md
@@ -627,7 +616,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 +639,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 +666,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
@@ -1021,7 +1003,7 @@ examples:
id: "<id>"
responses:
"200":
application/json: {"data": {"id": "gen-3bhGkxlo4XFrqiabUM7NDtwDzWwG", "upstream_id": "chatcmpl-791bcf62-080e-4568-87d0-94c72e3b4946", "total_cost": 0.0015, "cache_discount": 0.0002, "upstream_inference_cost": 0.0012, "created_at": "2024-07-15T23:33:19.433273+00:00", "model": "sao10k/l3-stheno-8b", "app_id": 12345, "streamed": true, "cancelled": false, "provider_name": "Infermatic", "latency": 1250, "moderation_latency": 50, "generation_time": 1200, "finish_reason": "stop", "tokens_prompt": 10, "tokens_completion": 25, "native_tokens_prompt": 10, "native_tokens_completion": 25, "native_tokens_completion_images": 0, "native_tokens_reasoning": 5, "native_tokens_cached": 3, "num_media_prompt": 1, "num_input_audio_prompt": 0, "num_media_completion": 0, "num_search_results": 5, "origin": "https://openrouter.ai/", "usage": 0.0015, "is_byok": false, "native_finish_reason": "stop", "external_user": "user-123", "api_type": "completions", "router": "openrouter/auto"}}
application/json: {"data": {"id": "gen-3bhGkxlo4XFrqiabUM7NDtwDzWwG", "upstream_id": "chatcmpl-791bcf62-080e-4568-87d0-94c72e3b4946", "total_cost": 0.0015, "cache_discount": 0.0002, "upstream_inference_cost": 0.0012, "created_at": "2024-07-15T23:33:19.433273+00:00", "model": "sao10k/l3-stheno-8b", "app_id": 12345, "streamed": true, "cancelled": false, "provider_name": "Infermatic", "latency": 1250, "moderation_latency": 50, "generation_time": 1200, "finish_reason": "stop", "tokens_prompt": 10, "tokens_completion": 25, "native_tokens_prompt": 10, "native_tokens_completion": 25, "native_tokens_completion_images": 0, "native_tokens_reasoning": 5, "native_tokens_cached": 3, "num_media_prompt": 1, "num_input_audio_prompt": 0, "num_media_completion": 0, "num_search_results": 5, "origin": "https://openrouter.ai/", "usage": 0.0015, "is_byok": false, "native_finish_reason": "stop", "external_user": "user-123", "api_type": "completions", "router": "openrouter/auto", "provider_responses": []}}
"401":
application/json: {"error": {"code": 401, "message": "Missing Authentication header"}}
"402":
@@ -1063,6 +1045,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.2
additionalDependencies:
dev: {}
main: {}
+144 -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
@@ -3542,6 +3542,7 @@ components:
- AI21
- AionLabs
- Alibaba
- Ambient
- Amazon Bedrock
- Amazon Nova
- Anthropic
@@ -8110,6 +8111,7 @@ components:
- AI21
- AionLabs
- Alibaba
- Ambient
- Amazon Bedrock
- Amazon Nova
- Anthropic
@@ -9341,263 +9343,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 +9469,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
@@ -10612,6 +10357,130 @@ paths:
nullable: true
description: Router used for the request (e.g., openrouter/auto)
example: openrouter/auto
provider_responses:
type: array
nullable: true
items:
type: object
properties:
id:
type: string
endpoint_id:
type: string
model_permaslug:
type: string
provider_name:
type: string
enum:
- AnyScale
- Atoma
- Cent-ML
- CrofAI
- Enfer
- GoPomelo
- HuggingFace
- Hyperbolic 2
- InoCloud
- Kluster
- Lambda
- Lepton
- Lynn 2
- Lynn
- Mancer
- Meta
- Modal
- Nineteen
- OctoAI
- Recursal
- Reflection
- Replicate
- SambaNova 2
- SF Compute
- Targon
- Together 2
- Ubicloud
- 01.AI
- AI21
- AionLabs
- Alibaba
- Ambient
- Amazon Bedrock
- Amazon Nova
- Anthropic
- Arcee AI
- AtlasCloud
- Avian
- Azure
- BaseTen
- BytePlus
- Black Forest Labs
- Cerebras
- Chutes
- Cirrascale
- Clarifai
- Cloudflare
- Cohere
- Crusoe
- DeepInfra
- DeepSeek
- Featherless
- Fireworks
- Friendli
- GMICloud
- Google
- Google AI Studio
- Groq
- Hyperbolic
- Inception
- Inceptron
- InferenceNet
- Infermatic
- Inflection
- Liquid
- Mara
- Mancer 2
- Minimax
- ModelRun
- Mistral
- Modular
- Moonshot AI
- Morph
- NCompass
- Nebius
- NextBit
- Novita
- Nvidia
- OpenAI
- OpenInference
- Parasail
- Perplexity
- Phala
- Relace
- SambaNova
- Seed
- SiliconFlow
- Sourceful
- Stealth
- StreamLake
- Switchpoint
- Together
- Upstage
- Venice
- WandB
- Xiaomi
- xAI
- Z.AI
- FakeProvider
status:
type: number
nullable: true
latency:
type: number
is_byok:
type: boolean
required:
- status
description: List of provider responses for this generation, including fallback attempts
required:
- id
- upstream_id
@@ -10646,6 +10515,7 @@ paths:
- external_user
- api_type
- router
- provider_responses
description: Generation data
required:
- data
@@ -10790,7 +10660,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 +10682,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 +13694,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 +13708,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 +13728,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: /
+141 -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
@@ -3561,6 +3561,7 @@ components:
- AI21
- AionLabs
- Alibaba
- Ambient
- Amazon Bedrock
- Amazon Nova
- Anthropic
@@ -8124,6 +8125,7 @@ components:
- AI21
- AionLabs
- Alibaba
- Ambient
- Amazon Bedrock
- Amazon Nova
- Anthropic
@@ -9350,264 +9352,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 +9478,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.
@@ -10621,6 +10365,131 @@ paths:
nullable: true
description: Router used for the request (e.g., openrouter/auto)
example: openrouter/auto
provider_responses:
type: array
nullable: true
items:
type: object
properties:
id:
type: string
endpoint_id:
type: string
model_permaslug:
type: string
provider_name:
type: string
enum:
- AnyScale
- Atoma
- Cent-ML
- CrofAI
- Enfer
- GoPomelo
- HuggingFace
- Hyperbolic 2
- InoCloud
- Kluster
- Lambda
- Lepton
- Lynn 2
- Lynn
- Mancer
- Meta
- Modal
- Nineteen
- OctoAI
- Recursal
- Reflection
- Replicate
- SambaNova 2
- SF Compute
- Targon
- Together 2
- Ubicloud
- 01.AI
- AI21
- AionLabs
- Alibaba
- Ambient
- Amazon Bedrock
- Amazon Nova
- Anthropic
- Arcee AI
- AtlasCloud
- Avian
- Azure
- BaseTen
- BytePlus
- Black Forest Labs
- Cerebras
- Chutes
- Cirrascale
- Clarifai
- Cloudflare
- Cohere
- Crusoe
- DeepInfra
- DeepSeek
- Featherless
- Fireworks
- Friendli
- GMICloud
- Google
- Google AI Studio
- Groq
- Hyperbolic
- Inception
- Inceptron
- InferenceNet
- Infermatic
- Inflection
- Liquid
- Mara
- Mancer 2
- Minimax
- ModelRun
- Mistral
- Modular
- Moonshot AI
- Morph
- NCompass
- Nebius
- NextBit
- Novita
- Nvidia
- OpenAI
- OpenInference
- Parasail
- Perplexity
- Phala
- Relace
- SambaNova
- Seed
- SiliconFlow
- Sourceful
- Stealth
- StreamLake
- Switchpoint
- Together
- Upstage
- Venice
- WandB
- Xiaomi
- xAI
- Z.AI
- FakeProvider
x-speakeasy-unknown-values: allow
status:
type: number
nullable: true
latency:
type: number
is_byok:
type: boolean
required:
- status
description: List of provider responses for this generation, including fallback attempts
required:
- id
- upstream_id
@@ -10655,6 +10524,7 @@ paths:
- external_user
- api_type
- router
- provider_responses
description: Generation data
required:
- data
@@ -10787,7 +10657,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 +10675,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 +13680,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 +13694,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 +13714,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:6e8165360ec62cc8b776111afb2e6d8c17e5dd46f2be6e124138a8296e2c7046
sourceBlobDigest: sha256:373dfa5b56ef18b9cdc55a2ad1a5d8b377deabfcc028ab7f940f525b3a3ca9c9
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:6e8165360ec62cc8b776111afb2e6d8c17e5dd46f2be6e124138a8296e2c7046
sourceBlobDigest: sha256:373dfa5b56ef18b9cdc55a2ad1a5d8b377deabfcc028ab7f940f525b3a3ca9c9
codeSamplesNamespace: open-router-python-code-samples
codeSamplesRevisionDigest: sha256:f19eae09ec90a23147935f07a86f75dbbc998e6bac3b820351a1e5f147fec590
codeSamplesRevisionDigest: sha256:0441c6e25f98818e2b2398041d3a974e3f26897c151a3fabfccbc2206640751a
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 */
```
+1
View File
@@ -8,6 +8,7 @@
| `AI21` | AI21 |
| `AION_LABS` | AionLabs |
| `ALIBABA` | Alibaba |
| `AMBIENT` | Ambient |
| `AMAZON_BEDROCK` | Amazon Bedrock |
| `AMAZON_NOVA` | Amazon Nova |
| `ANTHROPIC` | Anthropic |
+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
View File
@@ -8,6 +8,7 @@
| `AI21` | AI21 |
| `AION_LABS` | AionLabs |
| `ALIBABA` | Alibaba |
| `AMBIENT` | Ambient |
| `AMAZON_BEDROCK` | Amazon Bedrock |
| `AMAZON_NOVA` | Amazon Nova |
| `ANTHROPIC` | Anthropic |
@@ -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 |
+36 -35
View File
@@ -5,38 +5,39 @@ Generation data
## Fields
| Field | Type | Required | Description | Example |
| -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- |
| `id` | *str* | :heavy_check_mark: | Unique identifier for the generation | gen-3bhGkxlo4XFrqiabUM7NDtwDzWwG |
| `upstream_id` | *Nullable[str]* | :heavy_check_mark: | Upstream provider's identifier for this generation | chatcmpl-791bcf62-080e-4568-87d0-94c72e3b4946 |
| `total_cost` | *float* | :heavy_check_mark: | Total cost of the generation in USD | 0.0015 |
| `cache_discount` | *Nullable[float]* | :heavy_check_mark: | Discount applied due to caching | 0.0002 |
| `upstream_inference_cost` | *Nullable[float]* | :heavy_check_mark: | Cost charged by the upstream provider | 0.0012 |
| `created_at` | *str* | :heavy_check_mark: | ISO 8601 timestamp of when the generation was created | 2024-07-15T23:33:19.433273+00:00 |
| `model` | *str* | :heavy_check_mark: | Model used for the generation | sao10k/l3-stheno-8b |
| `app_id` | *Nullable[float]* | :heavy_check_mark: | ID of the app that made the request | 12345 |
| `streamed` | *Nullable[bool]* | :heavy_check_mark: | Whether the response was streamed | true |
| `cancelled` | *Nullable[bool]* | :heavy_check_mark: | Whether the generation was cancelled | false |
| `provider_name` | *Nullable[str]* | :heavy_check_mark: | Name of the provider that served the request | Infermatic |
| `latency` | *Nullable[float]* | :heavy_check_mark: | Total latency in milliseconds | 1250 |
| `moderation_latency` | *Nullable[float]* | :heavy_check_mark: | Moderation latency in milliseconds | 50 |
| `generation_time` | *Nullable[float]* | :heavy_check_mark: | Time taken for generation in milliseconds | 1200 |
| `finish_reason` | *Nullable[str]* | :heavy_check_mark: | Reason the generation finished | stop |
| `tokens_prompt` | *Nullable[float]* | :heavy_check_mark: | Number of tokens in the prompt | 10 |
| `tokens_completion` | *Nullable[float]* | :heavy_check_mark: | Number of tokens in the completion | 25 |
| `native_tokens_prompt` | *Nullable[float]* | :heavy_check_mark: | Native prompt tokens as reported by provider | 10 |
| `native_tokens_completion` | *Nullable[float]* | :heavy_check_mark: | Native completion tokens as reported by provider | 25 |
| `native_tokens_completion_images` | *Nullable[float]* | :heavy_check_mark: | Native completion image tokens as reported by provider | 0 |
| `native_tokens_reasoning` | *Nullable[float]* | :heavy_check_mark: | Native reasoning tokens as reported by provider | 5 |
| `native_tokens_cached` | *Nullable[float]* | :heavy_check_mark: | Native cached tokens as reported by provider | 3 |
| `num_media_prompt` | *Nullable[float]* | :heavy_check_mark: | Number of media items in the prompt | 1 |
| `num_input_audio_prompt` | *Nullable[float]* | :heavy_check_mark: | Number of audio inputs in the prompt | 0 |
| `num_media_completion` | *Nullable[float]* | :heavy_check_mark: | Number of media items in the completion | 0 |
| `num_search_results` | *Nullable[float]* | :heavy_check_mark: | Number of search results included | 5 |
| `origin` | *str* | :heavy_check_mark: | Origin URL of the request | https://openrouter.ai/ |
| `usage` | *float* | :heavy_check_mark: | Usage amount in USD | 0.0015 |
| `is_byok` | *bool* | :heavy_check_mark: | Whether this used bring-your-own-key | false |
| `native_finish_reason` | *Nullable[str]* | :heavy_check_mark: | Native finish reason as reported by provider | stop |
| `external_user` | *Nullable[str]* | :heavy_check_mark: | External user identifier | user-123 |
| `api_type` | [Nullable[operations.APIType]](../operations/apitype.md) | :heavy_check_mark: | Type of API used for the generation | |
| `router` | *Nullable[str]* | :heavy_check_mark: | Router used for the request (e.g., openrouter/auto) | openrouter/auto |
| Field | Type | Required | Description | Example |
| --------------------------------------------------------------------------- | --------------------------------------------------------------------------- | --------------------------------------------------------------------------- | --------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
| `id` | *str* | :heavy_check_mark: | Unique identifier for the generation | gen-3bhGkxlo4XFrqiabUM7NDtwDzWwG |
| `upstream_id` | *Nullable[str]* | :heavy_check_mark: | Upstream provider's identifier for this generation | chatcmpl-791bcf62-080e-4568-87d0-94c72e3b4946 |
| `total_cost` | *float* | :heavy_check_mark: | Total cost of the generation in USD | 0.0015 |
| `cache_discount` | *Nullable[float]* | :heavy_check_mark: | Discount applied due to caching | 0.0002 |
| `upstream_inference_cost` | *Nullable[float]* | :heavy_check_mark: | Cost charged by the upstream provider | 0.0012 |
| `created_at` | *str* | :heavy_check_mark: | ISO 8601 timestamp of when the generation was created | 2024-07-15T23:33:19.433273+00:00 |
| `model` | *str* | :heavy_check_mark: | Model used for the generation | sao10k/l3-stheno-8b |
| `app_id` | *Nullable[float]* | :heavy_check_mark: | ID of the app that made the request | 12345 |
| `streamed` | *Nullable[bool]* | :heavy_check_mark: | Whether the response was streamed | true |
| `cancelled` | *Nullable[bool]* | :heavy_check_mark: | Whether the generation was cancelled | false |
| `provider_name` | *Nullable[str]* | :heavy_check_mark: | Name of the provider that served the request | Infermatic |
| `latency` | *Nullable[float]* | :heavy_check_mark: | Total latency in milliseconds | 1250 |
| `moderation_latency` | *Nullable[float]* | :heavy_check_mark: | Moderation latency in milliseconds | 50 |
| `generation_time` | *Nullable[float]* | :heavy_check_mark: | Time taken for generation in milliseconds | 1200 |
| `finish_reason` | *Nullable[str]* | :heavy_check_mark: | Reason the generation finished | stop |
| `tokens_prompt` | *Nullable[float]* | :heavy_check_mark: | Number of tokens in the prompt | 10 |
| `tokens_completion` | *Nullable[float]* | :heavy_check_mark: | Number of tokens in the completion | 25 |
| `native_tokens_prompt` | *Nullable[float]* | :heavy_check_mark: | Native prompt tokens as reported by provider | 10 |
| `native_tokens_completion` | *Nullable[float]* | :heavy_check_mark: | Native completion tokens as reported by provider | 25 |
| `native_tokens_completion_images` | *Nullable[float]* | :heavy_check_mark: | Native completion image tokens as reported by provider | 0 |
| `native_tokens_reasoning` | *Nullable[float]* | :heavy_check_mark: | Native reasoning tokens as reported by provider | 5 |
| `native_tokens_cached` | *Nullable[float]* | :heavy_check_mark: | Native cached tokens as reported by provider | 3 |
| `num_media_prompt` | *Nullable[float]* | :heavy_check_mark: | Number of media items in the prompt | 1 |
| `num_input_audio_prompt` | *Nullable[float]* | :heavy_check_mark: | Number of audio inputs in the prompt | 0 |
| `num_media_completion` | *Nullable[float]* | :heavy_check_mark: | Number of media items in the completion | 0 |
| `num_search_results` | *Nullable[float]* | :heavy_check_mark: | Number of search results included | 5 |
| `origin` | *str* | :heavy_check_mark: | Origin URL of the request | https://openrouter.ai/ |
| `usage` | *float* | :heavy_check_mark: | Usage amount in USD | 0.0015 |
| `is_byok` | *bool* | :heavy_check_mark: | Whether this used bring-your-own-key | false |
| `native_finish_reason` | *Nullable[str]* | :heavy_check_mark: | Native finish reason as reported by provider | stop |
| `external_user` | *Nullable[str]* | :heavy_check_mark: | External user identifier | user-123 |
| `api_type` | [Nullable[operations.APIType]](../operations/apitype.md) | :heavy_check_mark: | Type of API used for the generation | |
| `router` | *Nullable[str]* | :heavy_check_mark: | Router used for the request (e.g., openrouter/auto) | openrouter/auto |
| `provider_responses` | List[[operations.ProviderResponse](../operations/providerresponse.md)] | :heavy_check_mark: | List of provider responses for this generation, including fallback attempts | |
+106
View File
@@ -0,0 +1,106 @@
# ProviderName
## Values
| Name | Value |
| ------------------- | ------------------- |
| `ANY_SCALE` | AnyScale |
| `ATOMA` | Atoma |
| `CENT_ML` | Cent-ML |
| `CROF_AI` | CrofAI |
| `ENFER` | Enfer |
| `GO_POMELO` | GoPomelo |
| `HUGGING_FACE` | HuggingFace |
| `HYPERBOLIC_2` | Hyperbolic 2 |
| `INO_CLOUD` | InoCloud |
| `KLUSTER` | Kluster |
| `LAMBDA` | Lambda |
| `LEPTON` | Lepton |
| `LYNN_2` | Lynn 2 |
| `LYNN` | Lynn |
| `MANCER` | Mancer |
| `META` | Meta |
| `MODAL` | Modal |
| `NINETEEN` | Nineteen |
| `OCTO_AI` | OctoAI |
| `RECURSAL` | Recursal |
| `REFLECTION` | Reflection |
| `REPLICATE` | Replicate |
| `SAMBA_NOVA_2` | SambaNova 2 |
| `SF_COMPUTE` | SF Compute |
| `TARGON` | Targon |
| `TOGETHER_2` | Together 2 |
| `UBICLOUD` | Ubicloud |
| `ONE_DOT_AI` | 01.AI |
| `AI21` | AI21 |
| `AION_LABS` | AionLabs |
| `ALIBABA` | Alibaba |
| `AMBIENT` | Ambient |
| `AMAZON_BEDROCK` | Amazon Bedrock |
| `AMAZON_NOVA` | Amazon Nova |
| `ANTHROPIC` | Anthropic |
| `ARCEE_AI` | Arcee AI |
| `ATLAS_CLOUD` | AtlasCloud |
| `AVIAN` | Avian |
| `AZURE` | Azure |
| `BASE_TEN` | BaseTen |
| `BYTE_PLUS` | BytePlus |
| `BLACK_FOREST_LABS` | Black Forest Labs |
| `CEREBRAS` | Cerebras |
| `CHUTES` | Chutes |
| `CIRRASCALE` | Cirrascale |
| `CLARIFAI` | Clarifai |
| `CLOUDFLARE` | Cloudflare |
| `COHERE` | Cohere |
| `CRUSOE` | Crusoe |
| `DEEP_INFRA` | DeepInfra |
| `DEEP_SEEK` | DeepSeek |
| `FEATHERLESS` | Featherless |
| `FIREWORKS` | Fireworks |
| `FRIENDLI` | Friendli |
| `GMI_CLOUD` | GMICloud |
| `GOOGLE` | Google |
| `GOOGLE_AI_STUDIO` | Google AI Studio |
| `GROQ` | Groq |
| `HYPERBOLIC` | Hyperbolic |
| `INCEPTION` | Inception |
| `INCEPTRON` | Inceptron |
| `INFERENCE_NET` | InferenceNet |
| `INFERMATIC` | Infermatic |
| `INFLECTION` | Inflection |
| `LIQUID` | Liquid |
| `MARA` | Mara |
| `MANCER_2` | Mancer 2 |
| `MINIMAX` | Minimax |
| `MODEL_RUN` | ModelRun |
| `MISTRAL` | Mistral |
| `MODULAR` | Modular |
| `MOONSHOT_AI` | Moonshot AI |
| `MORPH` | Morph |
| `N_COMPASS` | NCompass |
| `NEBIUS` | Nebius |
| `NEXT_BIT` | NextBit |
| `NOVITA` | Novita |
| `NVIDIA` | Nvidia |
| `OPEN_AI` | OpenAI |
| `OPEN_INFERENCE` | OpenInference |
| `PARASAIL` | Parasail |
| `PERPLEXITY` | Perplexity |
| `PHALA` | Phala |
| `RELACE` | Relace |
| `SAMBA_NOVA` | SambaNova |
| `SEED` | Seed |
| `SILICON_FLOW` | SiliconFlow |
| `SOURCEFUL` | Sourceful |
| `STEALTH` | Stealth |
| `STREAM_LAKE` | StreamLake |
| `SWITCHPOINT` | Switchpoint |
| `TOGETHER` | Together |
| `UPSTAGE` | Upstage |
| `VENICE` | Venice |
| `WAND_B` | WandB |
| `XIAOMI` | Xiaomi |
| `X_AI` | xAI |
| `Z_AI` | Z.AI |
| `FAKE_PROVIDER` | FakeProvider |
+14
View File
@@ -0,0 +1,14 @@
# ProviderResponse
## Fields
| Field | Type | Required | Description |
| ------------------------------------------------------------------ | ------------------------------------------------------------------ | ------------------------------------------------------------------ | ------------------------------------------------------------------ |
| `id` | *Optional[str]* | :heavy_minus_sign: | N/A |
| `endpoint_id` | *Optional[str]* | :heavy_minus_sign: | N/A |
| `model_permaslug` | *Optional[str]* | :heavy_minus_sign: | N/A |
| `provider_name` | [Optional[operations.ProviderName]](../operations/providername.md) | :heavy_minus_sign: | N/A |
| `status` | *Nullable[float]* | :heavy_check_mark: | N/A |
| `latency` | *Optional[float]* | :heavy_minus_sign: | N/A |
| `is_byok` | *Optional[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.2"
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.2"
__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.2 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",
+1
View File
@@ -13,6 +13,7 @@ Schema0Enum = Union[
"AI21",
"AionLabs",
"Alibaba",
"Ambient",
"Amazon Bedrock",
"Amazon Nova",
"Anthropic",
@@ -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
@@ -10,6 +10,7 @@ ProviderName = Union[
"AI21",
"AionLabs",
"Alibaba",
"Ambient",
"Amazon Bedrock",
"Amazon Nova",
"Anthropic",
+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
+9
View File
@@ -160,6 +160,9 @@ if TYPE_CHECKING:
GetGenerationRequestTypedDict,
GetGenerationResponse,
GetGenerationResponseTypedDict,
ProviderName,
ProviderResponse,
ProviderResponseTypedDict,
)
from .getguardrail import (
GetGuardrailData,
@@ -462,6 +465,9 @@ __all__ = [
"MetadataTypedDict",
"Object",
"ObjectEmbedding",
"ProviderName",
"ProviderResponse",
"ProviderResponseTypedDict",
"RateLimit",
"RateLimitTypedDict",
"SendChatCompletionRequestResponse",
@@ -619,6 +625,9 @@ _dynamic_imports: dict[str, str] = {
"GetGenerationRequestTypedDict": ".getgeneration",
"GetGenerationResponse": ".getgeneration",
"GetGenerationResponseTypedDict": ".getgeneration",
"ProviderName": ".getgeneration",
"ProviderResponse": ".getgeneration",
"ProviderResponseTypedDict": ".getgeneration",
"GetGuardrailData": ".getguardrail",
"GetGuardrailDataTypedDict": ".getguardrail",
"GetGuardrailRequest": ".getguardrail",
+179 -2
View File
@@ -5,8 +5,8 @@ from openrouter.types import BaseModel, Nullable, UNSET_SENTINEL, UnrecognizedSt
from openrouter.utils import FieldMetadata, QueryParamMetadata, validate_open_enum
from pydantic import model_serializer
from pydantic.functional_validators import PlainValidator
from typing import Literal, Union
from typing_extensions import Annotated, TypedDict
from typing import List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict
class GetGenerationRequestTypedDict(TypedDict):
@@ -29,6 +29,177 @@ APIType = Union[
r"""Type of API used for the generation"""
ProviderName = Union[
Literal[
"AnyScale",
"Atoma",
"Cent-ML",
"CrofAI",
"Enfer",
"GoPomelo",
"HuggingFace",
"Hyperbolic 2",
"InoCloud",
"Kluster",
"Lambda",
"Lepton",
"Lynn 2",
"Lynn",
"Mancer",
"Meta",
"Modal",
"Nineteen",
"OctoAI",
"Recursal",
"Reflection",
"Replicate",
"SambaNova 2",
"SF Compute",
"Targon",
"Together 2",
"Ubicloud",
"01.AI",
"AI21",
"AionLabs",
"Alibaba",
"Ambient",
"Amazon Bedrock",
"Amazon Nova",
"Anthropic",
"Arcee AI",
"AtlasCloud",
"Avian",
"Azure",
"BaseTen",
"BytePlus",
"Black Forest Labs",
"Cerebras",
"Chutes",
"Cirrascale",
"Clarifai",
"Cloudflare",
"Cohere",
"Crusoe",
"DeepInfra",
"DeepSeek",
"Featherless",
"Fireworks",
"Friendli",
"GMICloud",
"Google",
"Google AI Studio",
"Groq",
"Hyperbolic",
"Inception",
"Inceptron",
"InferenceNet",
"Infermatic",
"Inflection",
"Liquid",
"Mara",
"Mancer 2",
"Minimax",
"ModelRun",
"Mistral",
"Modular",
"Moonshot AI",
"Morph",
"NCompass",
"Nebius",
"NextBit",
"Novita",
"Nvidia",
"OpenAI",
"OpenInference",
"Parasail",
"Perplexity",
"Phala",
"Relace",
"SambaNova",
"Seed",
"SiliconFlow",
"Sourceful",
"Stealth",
"StreamLake",
"Switchpoint",
"Together",
"Upstage",
"Venice",
"WandB",
"Xiaomi",
"xAI",
"Z.AI",
"FakeProvider",
],
UnrecognizedStr,
]
class ProviderResponseTypedDict(TypedDict):
status: Nullable[float]
id: NotRequired[str]
endpoint_id: NotRequired[str]
model_permaslug: NotRequired[str]
provider_name: NotRequired[ProviderName]
latency: NotRequired[float]
is_byok: NotRequired[bool]
class ProviderResponse(BaseModel):
status: Nullable[float]
id: Optional[str] = None
endpoint_id: Optional[str] = None
model_permaslug: Optional[str] = None
provider_name: Annotated[
Optional[ProviderName], PlainValidator(validate_open_enum(False))
] = None
latency: Optional[float] = None
is_byok: Optional[bool] = None
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = [
"id",
"endpoint_id",
"model_permaslug",
"provider_name",
"latency",
"is_byok",
]
nullable_fields = ["status"]
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 GetGenerationDataTypedDict(TypedDict):
r"""Generation data"""
@@ -98,6 +269,8 @@ class GetGenerationDataTypedDict(TypedDict):
r"""Type of API used for the generation"""
router: Nullable[str]
r"""Router used for the request (e.g., openrouter/auto)"""
provider_responses: Nullable[List[ProviderResponseTypedDict]]
r"""List of provider responses for this generation, including fallback attempts"""
class GetGenerationData(BaseModel):
@@ -202,6 +375,9 @@ class GetGenerationData(BaseModel):
router: Nullable[str]
r"""Router used for the request (e.g., openrouter/auto)"""
provider_responses: Nullable[List[ProviderResponse]]
r"""List of provider responses for this generation, including fallback attempts"""
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = []
@@ -232,6 +408,7 @@ class GetGenerationData(BaseModel):
"external_user",
"api_type",
"router",
"provider_responses",
]
null_default_fields = []
+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" },