Compare commits

..
Author SHA1 Message Date
OpenRouter SDK Bot 1c1fa61807 chore: update OpenAPI spec [sdk-bot] 2026-04-12 00:16:07 +00:00
4e84bb736b chore: update OpenAPI spec from monorepo (#98)
Co-authored-by: OpenRouter SDK Bot <sdk-bot@openrouter.ai>
2026-04-10 21:16:40 -04:00
947e92e68d chore: update OpenAPI spec from monorepo (#99)
Co-authored-by: OpenRouter SDK Bot <sdk-bot@openrouter.ai>
2026-04-10 21:16:13 -04:00
bdbd8becc2 chore: update OpenAPI spec from monorepo (#97)
Co-authored-by: OpenRouter SDK Bot <sdk-bot@openrouter.ai>
2026-04-10 21:15:46 -04:00
6ef088e7c7 chore: update OpenAPI spec from monorepo (#100)
Co-authored-by: OpenRouter SDK Bot <sdk-bot@openrouter.ai>
2026-04-10 21:15:45 -04:00
e4e5cc259a chore: update OpenAPI spec from monorepo (#101)
Co-authored-by: OpenRouter SDK Bot <sdk-bot@openrouter.ai>
2026-04-10 21:14:47 -04:00
Matt AppersonandGitHub 06bea2ae0f chore: set forwardCompatibleUnionsByDefault to tagged-only (#76) 2026-04-08 10:46:15 -04:00
Matt AppersonandGitHub 6b1b7e6a9d fix: add overlay to convert boolean query params to boolean type (#75) 2026-04-08 09:22:13 -04:00
Matt AppersonandGitHub dd8e6bdac2 fix: add generic overlay to remove redundant allOf inline enums (#73) 2026-04-03 18:37:50 -04:00
Matt Apperson e6b0242969 chore: clean up removed docs and update generated SDK files
Remove obsolete component documentation and update speakeasy-generated
files to match the latest OpenAPI spec regeneration.
2026-04-02 10:21:41 -04:00
OpenRouter SDK Bot 5ab44f08f0 feat: regenerate SDK with updated OpenAPI spec
Speakeasy regeneration with latest schema changes including
type renames and new server tool models.
2026-03-27 15:18:14 -04:00
robert-j-yandGitHub e72a84e82d chore: sync from monorepo (#61) 2026-02-23 17:02:29 -06:00
OpenRouter Team c734c52d9c Commits included in this export:
- 56d382078cfce7fa597d1da2bce531af2d060b47
  - 9ef6db7e04c9401536763a321b05d00311cef31a
  - bf855082e30820d466f0f86a6d6e87de2ecfb06f
  - 335b1cbe361214e48b945b987b4e164457aa817b
  - 648485fdc7f9d8ae86fd857eccedcc5e41fb2e69
  - 80c49474a15a2bd549a5f26efad3858aa45b7c7b
  - 70e8ac317f9c4472db3decd024d1819650df4182
  - 9f2a6659ab6dbf111a0c29e4366328c3d2048826
  - a3a28b1fc6ec7d2941232a4ebde8c5f470497876
  - 4b5dc9193480b7c5c9ddb882ccf3ee2128ca0d51
  - bb413e979a46ef67c2f266743f7ebd798af42afb
  - b60e92d5dcec83f31986164f51c010d1728b2b17
  - 45687f423707f5838461585c568a024a19eb2f06
  - 3103d3ca68b6e42ccdb6136588ec2b6edc8dcab0
  - fd9f991606027cd86116317c71f8eb7b4e2aa3eb
  - 0f312019161edd76c1e5923d142c788d22f096d5
  - 5dbab2094bc744db4a90b3097520d897e5d0d634
  - 4c47d1af1735db18a1c1a7f463e801c7f71ad4e5

GitOrigin-RevId: 56d382078cfce7fa597d1da2bce531af2d060b47
2026-02-23 21:34:42 +00:00
Shashank GoyalandGitHub b2098ff28e chore: sync from monorepo (#49) 2026-02-05 20:45:13 -05:00
OpenRouter Team 1cad51abb6 Commits included in this export:
- 6ddaaa6989d725bbe966e45f7aed0c1bd72f9153
  - 4779741b6ba710b1299612b82e8544516bd9dd6a
  - 22083fcc8f58884d8212d6f3314b231c4ddd21cd
  - a925a620f97196d509e073a163caac053bd82316
  - 5c05d8829784601ffd151acef1a6978c266f913d
  - 6f4fff535fbf4274255c255ae23620b8e00e614f
  - ef358e96cb01e469b77d44683603a602b0813116
  - e6299b4ebfe5c2eed6c598771f0fd99f84555401
  - 24d3f0ee1c2aa19a62f7902836034080b9246813
  - 68922847c2969b773887310eb7aa9a814e199c5a
  - 729ee2338c39df22461526153e7f4ba868fd498e
  - e1074ff86fccf5e48406b7595298873106d3cc5a
  - 123bbdaf841d299162a82ee2573adfbb70a45b8f
  - ac457b8a8dad98fdf5ddcae8dd4711361cea3084
  - ea825199f4c59dd68fec01cf8d18a582963c9f25
  - 4d48e4f6bb936e785787314a965298da6b78fea0
  - 718729a573ee98893a4408d5a52ab4686661fe54
  - b867adcde6b64f3f2a11c4626254b39098e4b0b4
  - 21912c097b4066d109766c6b4492826595cd57c5
  - bc1ed85adc976a4634ca8a41b82e4fc2c39a864f
  - d145c89c941937a312ed1357590d2bfda9a3603d
  - 12f05b5dee397ead47cfcd545a7a2e3c7ff57524
  - dd28f75a19a015809797c7abf3f8758f7c37262e
  - c96e569781e07ab44172d9c69940ec17bafd81f4
  - c9d5a90e3c2b5077a2bdd49773f1a46d1a5a79c7
  - 58b08f87116ceab9076de2fdc0a4c74c919b44c4

GitOrigin-RevId: 6ddaaa6989d725bbe966e45f7aed0c1bd72f9153
2026-02-05 23:15:21 +00:00
robert-j-yandGitHub 0c791b04d1 chore: sync from monorepo (#36) 2026-01-21 17:28:27 -08:00
OpenRouter Team 5f2c0ee2ea Project import generated by Copybara.
GitOrigin-RevId: 2592bdc8b4b7c695a3d689390aedc9a42914acc8
2026-01-22 01:26:28 +00:00
robert-j-yandGitHub 5832c0495b chore: regenerate SDK with version 0.1.2 (#34) 2026-01-21 13:47:48 -08:00
Robert Yeakel f5dfc30997 chore: regenerate SDK with version 0.1.2 2026-01-21 13:45:46 -08:00
Shashank GoyalandGitHub a56ffbf5f3 Update speakeasy gen.yaml (#33) 2026-01-21 16:17:11 -05:00
Shashank Goyal cc2b002c5c Update speakeasy gen.yaml 2026-01-21 16:16:16 -05:00
Shashank Goyal 9774c726fd Bring project back to correct version number 2026-01-21 16:03:44 -05:00
Matt AppersonandGitHub 3a40848aab fix: update OpenAPI spec with router field (#32) 2026-01-13 20:40:08 -05:00
Matt AppersonandGitHub f190e3f950 feat: fix types and add reasoning_details to chat responses (#27) 2025-12-16 16:16:22 -05:00
Matt AppersonandGitHub d433ce35e8 chore: regenerate Python SDK with updated OpenAPI spec (#26) 2025-12-12 15:17:08 -05:00
Matt Apperson 61e5216764 chore: regenerate Python SDK with updated OpenAPI spec
Updates include:
- Updated OpenAPI spec with new component schemas
- Restructured component documentation with nested parameter types
- Added new components for plugin and provider configurations
- Updated chat generation params and response request structures
- Version bump and dependency updates
2025-12-12 15:13:12 -05:00
Matt AppersonandGitHub 67ef52b03e chore: Python SDK updates and regeneration (#24) 2025-12-04 13:09:00 -05:00
Matt Apperson d4474da1b8 more updates 2025-12-04 13:07:08 -05:00
Matt Apperson aed8199b2b updates 2025-12-04 13:07:01 -05:00
Matt AppersonandGitHub 06b2ccc54a chore: regenerate Python SDK v0.1.1 with new overlays (#23) 2025-12-04 10:48:48 -05:00
Matt Apperson 6cd0d2a76d latest updates 2025-12-04 10:46:19 -05:00
Matt AppersonandGitHub a1dae775cb chore: regenerate Python SDK v0.0.17 (#18) 2025-11-18 13:59:14 -05:00
Matt Apperson 10a76ba502 chore: regenerate SDK to v0.0.19 with speakeasy 2025-11-18 13:58:48 -05:00
Matt Apperson f4ffd51f40 chore: regenerate Python SDK v0.0.17
Update Python SDK with Speakeasy regeneration:
- Bump version from 0.0.16 to 0.0.17
- Refactor OpenAPI schema definitions:
  - Inline BigNumberUnion type into usage sites
  - Reorganize ProviderName enum location
  - Simplify provider order/only/ignore array types
  - Add plugins schema definitions
- Update gen.lock with new configChecksum
2025-11-18 13:56:41 -05:00
Matt AppersonandGitHub 20c63f6f13 feat: add monorepo sync notification workflow (#17) 2025-11-15 16:16:37 -05:00
Matt Apperson 0f9cb9787a feat: add monorepo sync notification workflow
Automatically notifies openrouter-web monorepo when changes are pushed to main.
This triggers the subtree sync workflow to create a PR with updates.

Requires MONOREPO_SYNC_TOKEN secret to be configured.
2025-11-15 15:53:15 -05:00
Matt AppersonandGitHub 6c5dfcfb2b chore: 🐝 Update SDK - Generate 0.0.16 (#16) 2025-11-15 13:50:49 -05:00
speakeasy-github[bot]andspeakeasy-bot afbf99e8bf empty commit to trigger [run-tests] workflow 2025-11-15 18:17:41 +00:00
speakeasybot 6895d9d45b ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.658.1 2025-11-15 18:17:32 +00:00
Matt Apperson e824ca8a57 remove banner 2025-11-13 14:35:17 -05:00
Matt AppersonandGitHub e70f43e916 Add Apache License 2.0
Added the Apache License 2.0 to the project.
2025-11-13 14:34:40 -05:00
Matt Apperson 94ba44c933 fixes 2025-11-13 14:21:27 -05:00
Matt Apperson d13e797ad1 fix 2025-11-13 14:14:19 -05:00
Matt Apperson 3629471122 names 2025-11-13 14:09:48 -05:00
Matt Apperson c702382b4b lint fix 2025-11-13 14:02:45 -05:00
Matt Apperson 599fd1454c bump 2025-11-13 13:52:26 -05:00
Matt Apperson a0b2566851 fix permissions 2025-11-13 13:45:14 -05:00
Matt Apperson 71ab77e5e8 wip setup 2025-11-13 13:40:55 -05:00
Matt Apperson 05f81a553c add oauth helpers 2025-11-13 13:12:32 -05:00
Matt Apperson dede1d21ec settings updates 2025-11-13 13:03:31 -05:00
Matt Apperson 43cf059ae0 update docs 2025-11-13 12:48:16 -05:00
Matt Apperson 5fc522c72f Initial commit: OpenRouter Python SDK
Auto-generated Python SDK for OpenRouter API, providing comprehensive client library with:
- Chat completions and streaming support
- Embeddings API
- Model and provider information
- API key management
- Analytics and usage tracking
- OAuth authentication flows
- Full type hints and error handling
2025-11-13 10:56:25 -05:00
809 changed files with 88507 additions and 13169 deletions
+11
View File
@@ -0,0 +1,11 @@
{
"permissions": {
"allow": [
"Bash(python3:*)",
"Bash(git push:*)",
"Bash(gh pr create:*)"
],
"deny": [],
"ask": []
}
}
-5
View File
@@ -1,9 +1,4 @@
<div align="center">
<a href="https://codespaces.new/speakeasy-sdks/openrouter-python-sdk.git/tree/main"><img src="https://github.com/codespaces/badge.svg" /></a>
</div>
<br>
> **Remember to shutdown a GitHub Codespace when it is not in use!**
# Dev Containers Quick Start
+1
View File
@@ -0,0 +1 @@
pylintrc
+46
View File
@@ -0,0 +1,46 @@
name: Notify Monorepo of Changes
on:
push:
branches:
- main
jobs:
notify-monorepo:
runs-on: ubuntu-latest
steps:
- name: Send repository dispatch to monorepo
run: |
# Determine which event type to send based on repository name
REPO_NAME="${GITHUB_REPOSITORY#*/}" # Gets 'python-sdk' from 'OpenRouterTeam/python-sdk'
case "$REPO_NAME" in
"typescript-sdk")
EVENT_TYPE="sync-typescript-sdk"
;;
"python-sdk")
EVENT_TYPE="sync-python-sdk"
;;
"ai-sdk-provider")
EVENT_TYPE="sync-ai-sdk-provider"
;;
"cli")
EVENT_TYPE="sync-cli"
;;
*)
echo "Unknown repository: $REPO_NAME"
exit 1
;;
esac
echo "Sending repository_dispatch event: $EVENT_TYPE"
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.MONOREPO_SYNC_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OpenRouterTeam/openrouter-web/dispatches \
-d "{\"event_type\":\"$EVENT_TYPE\",\"client_payload\":{\"repository\":\"$GITHUB_REPOSITORY\",\"ref\":\"$GITHUB_REF\",\"sha\":\"$GITHUB_SHA\"}}"
echo "✅ Notification sent to monorepo"
+1
View File
@@ -30,4 +30,5 @@ jobs:
set_version: ${{ github.event.inputs.set_version }}
secrets:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
pypi_token: ${{ secrets.PYPI_TOKEN }}
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
@@ -1,19 +1,23 @@
name: Speakeasy Tagging
name: Publish
permissions:
checks: write
contents: write
pull-requests: write
statuses: write
id-token: write
"on":
push:
branches:
- main
paths:
- .speakeasy/gen.lock
workflow_dispatch: {}
jobs:
tag:
uses: speakeasy-api/sdk-generation-action/.github/workflows/tag.yaml@v15
publish:
uses: speakeasy-api/sdk-generation-action/.github/workflows/sdk-publish.yaml@v15
with:
registry_tags: main
target: open-router
secrets:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
pypi_token: ${{ secrets.PYPI_TOKEN }}
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
+15 -2
View File
@@ -1,12 +1,25 @@
.venv/
venv/
src/*.egg-info/
**/__pycache__/
.pytest_cache/
.python-version
.DS_Store
pyrightconfig.json
**/.speakeasy/temp/
**/.speakeasy/logs/
.speakeasy/reports
# Build artifacts
/dist
__pycache__/
*.py[cod]
*.egg-info/
*.egg
# Speakeasy generation artifacts (generated in OSS repo, not here)
.speakeasy/*.lock
.speakeasy/*.openapi.yaml
/docs
# Environment
.env
.env.local
.env.*.local
.DS_Store
.venv/
+5018 -295
View File
File diff suppressed because it is too large Load Diff
+30 -9
View File
@@ -6,7 +6,7 @@ generation:
sdkClassName: OpenRouter
maintainOpenAPIOrder: true
usageSnippets:
optionalPropertyRendering: withExample
optionalPropertyRendering: never
sdkInitStyle: constructor
useClassNamesForArrayFields: true
fixes:
@@ -19,49 +19,70 @@ generation:
auth:
oAuth2ClientCredentialsEnabled: true
oAuth2PasswordEnabled: true
hoistGlobalSecurity: true
inferSSEOverload: true
sdkHooksConfigAccess: true
schemas:
allOfMergeStrategy: shallowMerge
requestBodyFieldName: ""
persistentEdits: {}
tests:
generateTests: false
generateNewTests: true
skipResponseBodyAssertions: false
preApplyUnionDiscriminators: true
python:
version: 0.5.2
version: 0.8.1
additionalDependencies:
dev: {}
main: {}
allowedRedefinedBuiltins:
- id
- object
- input
- models
- hash
asyncMode: both
authors:
- Speakeasy
- OpenRouter
baseErrorName: OpenRouterError
clientServerStatusCodesAsErrors: true
constFieldCasing: upper
defaultErrorName: OpenRouterDefaultError
description: Python Client SDK Generated by Speakeasy.
enableCustomCodeRegions: true
description: Official Python Client SDK for OpenRouter.
enableCustomCodeRegions: false
enumFormat: union
envVarPrefix: OPENROUTER
fixFlags:
asyncPaginationSep2025: true
responseRequiredSep2024: true
flattenGlobalSecurity: true
flattenRequests: true
flatteningOrder: parameters-first
forwardCompatibleUnionsByDefault: "tagged-only"
imports:
option: openapi
paths:
callbacks: ""
callbacks: callbacks
errors: errors
operations: ""
shared: ""
webhooks: ""
operations: operations
shared: components
webhooks: webhooks
inferSSEOverload: true
inferUnionDiscriminators: true
inputModelSuffix: input
legacyPyright: false
license: Apache-2.0
maxMethodParams: 999
methodArguments: infer-optional-args
moduleName: ""
multipartArrayFormat: legacy
outputModelSuffix: output
packageManager: uv
packageName: openrouter
preApplyUnionDiscriminators: false
pytestFilterWarnings: []
pytestTimeout: 0
responseFormat: flat
sseFlatResponse: true
templateVersion: v2
+19100 -1451
View File
File diff suppressed because it is too large Load Diff
+10
View File
@@ -0,0 +1,10 @@
lintVersion: 1.0.0
defaultRuleset: openrouter
rulesets:
openrouter:
rulesets:
- speakeasy-recommended
- speakeasy-generation
rules:
oas3-missing-example:
severity: "off"
File diff suppressed because it is too large Load Diff
+18829 -973
View File
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,52 @@
overlay: 1.0.0
x-speakeasy-jsonpath: rfc9535
info:
title: Add HTTP-Referer and X-OpenRouter-Title as global parameters
version: 0.0.0
actions:
# Add global parameters for app identification
- target: $
description: Add x-speakeasy-globals for HTTP-Referer, X-OpenRouter-Title, and X-OpenRouter-Categories headers
update:
x-speakeasy-globals:
parameters:
- $ref: "#/components/parameters/AppIdentifier"
- $ref: "#/components/parameters/AppDisplayName"
- $ref: "#/components/parameters/AppCategories"
# Add component parameters
- target: $.components
description: Add parameters for app identification headers
update:
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.
This is used to track API usage per application.
AppDisplayName:
name: X-OpenRouter-Title
in: header
schema:
type: string
description: |
The app display name allows you to customize how your app appears in OpenRouter's dashboard.
AppCategories:
name: X-OpenRouter-Categories
in: header
schema:
type: string
description: |
Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
# Add header parameters to all paths so Speakeasy matches them with globals
- target: $.paths[*]
description: Reference app identification headers on all paths so Speakeasy injects them via globals
update:
parameters:
- $ref: "#/components/parameters/AppIdentifier"
- $ref: "#/components/parameters/AppDisplayName"
- $ref: "#/components/parameters/AppCategories"
@@ -0,0 +1,11 @@
overlay: 1.0.0
x-speakeasy-jsonpath: rfc9535
info:
title: Simplify redundant allOf inline schemas
version: 0.0.0
actions:
- target: "$..allOf[?@.enum && !@['$ref']]"
description: >
Remove inline enum definitions that duplicate a $ref enum in the same
allOf. These are artifacts from zod-openapi .extend() serialization.
remove: true
@@ -0,0 +1,10 @@
overlay: 1.0.0
x-speakeasy-jsonpath: rfc9535
info:
title: Convert boolean query params from string to boolean
version: 0.0.0
actions:
- target: $..parameters[?@.schema["x-openrouter-type"] == "boolean"].schema
description: Convert x-openrouter-type boolean params from string to boolean
update:
type: boolean
@@ -0,0 +1,10 @@
overlay: 1.0.0
x-speakeasy-jsonpath: rfc9535
info:
title: Add open enums
version: 0.0.0
actions:
- target: $..[?length(@.enum) > 1]
description: Automatically open all enums that have length > 1
update:
x-speakeasy-unknown-values: allow
@@ -0,0 +1,15 @@
overlay: 1.0.0
x-speakeasy-jsonpath: rfc9535
info:
title: Remove RSS+XML response schemas and related parameters
version: 0.0.0
actions:
- target: $..responses.*.content["application/rss+xml"]
description: Remove application/rss+xml response schemas
remove: true
- target: $..parameters[?@.name == "use_rss"]
description: Remove use_rss parameter
remove: true
- target: $..parameters[?@.name == "use_rss_chat_links"]
description: Remove use_rss_chat_links parameter
remove: true
+21 -13
View File
@@ -1,36 +1,44 @@
speakeasyVersion: 1.611.1
speakeasyVersion: 1.680.0
sources:
OpenRouter Chat Completions API:
OpenRouter API:
sourceNamespace: open-router-chat-completions-api
sourceRevisionDigest: sha256:30b19a8759608792fb4d27f6bf28d5982d7e2a8cf5b3faf34ba3507a62f9f106
sourceBlobDigest: sha256:454f1b880a0882a70f78eacccb2c33e3d9d19134a0738b0e21487984a7bf2e63
sourceRevisionDigest: sha256:0795e89fdc7634204a5e1c93c441069d7bfb349fc1c7f43a53db24f0803c72fa
sourceBlobDigest: sha256:bb920e0d3ed7fb2c204d06aa436d9ce9a3635727d3a6147a7a2798333458d12a
tags:
- latest
- speakeasy-sdk-regen-1755878373
- 1.0.0
targets:
open-router:
source: OpenRouter Chat Completions API
source: OpenRouter API
sourceNamespace: open-router-chat-completions-api
sourceRevisionDigest: sha256:30b19a8759608792fb4d27f6bf28d5982d7e2a8cf5b3faf34ba3507a62f9f106
sourceBlobDigest: sha256:454f1b880a0882a70f78eacccb2c33e3d9d19134a0738b0e21487984a7bf2e63
sourceRevisionDigest: sha256:0795e89fdc7634204a5e1c93c441069d7bfb349fc1c7f43a53db24f0803c72fa
sourceBlobDigest: sha256:bb920e0d3ed7fb2c204d06aa436d9ce9a3635727d3a6147a7a2798333458d12a
codeSamplesNamespace: open-router-python-code-samples
codeSamplesRevisionDigest: sha256:c368e0601d6b667625dd99ffcd53e69e3dc98a4b518a45444add6457dde83b22
workflow:
workflowVersion: 1.0.0
speakeasyVersion: latest
speakeasyVersion: 1.680.0
sources:
OpenRouter Chat Completions API:
OpenRouter API:
inputs:
- location: .speakeasy/in.openapi.yaml
overlays:
- location: .speakeasy/overlays/open-enums.overlay.yaml
- location: .speakeasy/overlays/remove-rss-responses.overlay.yaml
- location: .speakeasy/overlays/add-headers.overlay.yaml
output: .speakeasy/out.openapi.yaml
registry:
location: registry.speakeasyapi.dev/sheldon-vaughn-test/sandbox/open-router-chat-completions-api
location: registry.speakeasyapi.dev/openrouter/sdk/open-router-chat-completions-api
targets:
open-router:
target: python
source: OpenRouter Chat Completions API
source: OpenRouter API
publish:
pypi:
token: $pypi_token
codeSamples:
registry:
location: registry.speakeasyapi.dev/sheldon-vaughn-test/sandbox/open-router-chat-completions-api-python-code-samples
location: registry.speakeasyapi.dev/openrouter/sdk/open-router-python-code-samples
labelOverride:
fixedValue: Python (SDK)
blocking: false
+14 -5
View File
@@ -1,19 +1,28 @@
workflowVersion: 1.0.0
speakeasyVersion: latest
speakeasyVersion: 1.680.0
sources:
OpenRouter Chat Completions API:
OpenRouter API:
inputs:
- location: .speakeasy/in.openapi.yaml
overlays:
- location: .speakeasy/overlays/open-enums.overlay.yaml
- location: .speakeasy/overlays/remove-rss-responses.overlay.yaml
- location: .speakeasy/overlays/add-headers.overlay.yaml
- location: .speakeasy/overlays/allof-simplify.overlay.yaml
- location: .speakeasy/overlays/boolean-query-params.overlay.yaml
output: .speakeasy/out.openapi.yaml
registry:
location: registry.speakeasyapi.dev/sheldon-vaughn-test/sandbox/open-router-chat-completions-api
location: registry.speakeasyapi.dev/openrouter/sdk/open-router-chat-completions-api
targets:
open-router:
target: python
source: OpenRouter Chat Completions API
source: OpenRouter API
publish:
pypi:
token: $pypi_token
codeSamples:
registry:
location: registry.speakeasyapi.dev/sheldon-vaughn-test/sandbox/open-router-chat-completions-api-python-code-samples
location: registry.speakeasyapi.dev/openrouter/sdk/open-router-python-code-samples
labelOverride:
fixedValue: Python (SDK)
blocking: false
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+127
View File
@@ -0,0 +1,127 @@
# OpenRouter Python SDK
The OpenRouter Python SDK is a type-safe toolkit for building AI applications with access to 300+ language models through a unified API.
## Why use the OpenRouter SDK?
Integrating AI models into applications involves handling different provider APIs, managing model-specific requirements, and avoiding common implementation mistakes. The OpenRouter SDK standardizes these integrations and protects you from footguns.
```python
from openrouter import OpenRouter
import os
with OpenRouter(
api_key=os.getenv("OPENROUTER_API_KEY")
) as client:
response = client.chat.send(
model="minimax/minimax-m2",
messages=[
{"role": "user", "content": "Explain quantum computing"}
]
)
```
The SDK provides three core benefits:
### Auto-generated from API specifications
The SDK is automatically generated from OpenRouter's OpenAPI specs and updated with every API change. New models, parameters, and features appear in your IDE autocomplete immediately. No manual updates. No version drift.
```python
# When new models launch, they're available instantly
response = client.chat.send(
model="minimax/minimax-m2"
)
```
### Type-safe by default
Every parameter, response field, and configuration option is fully typed with Python type hints and validated with Pydantic. Invalid configurations are caught at runtime with clear error messages.
```python
response = client.chat.send(
model="minimax/minimax-m2",
messages=[
{"role": "user", "content": "Hello"}
# ← Pydantic validates message structure
],
temperature=0.7, # ← Type-checked and validated
stream=True # ← Response type changes based on this
)
```
**Actionable error messages:**
```python
# Instead of generic errors, get specific guidance:
# "Model 'openai/o1-preview' requires at least 2 messages.
# You provided 1 message. Add a system or user message."
```
**Type-safe streaming:**
```python
stream = client.chat.send(
model="minimax/minimax-m2",
messages=[{"role": "user", "content": "Write a story"}],
stream=True
)
for event in stream:
# Full type information for streaming responses
content = event.choices[0].delta.content if event.choices else None
```
**Async support:**
```python
import asyncio
async def main():
async with OpenRouter(
api_key=os.getenv("OPENROUTER_API_KEY")
) as client:
response = await client.chat.send_async(
model="minimax/minimax-m2",
messages=[{"role": "user", "content": "Hello"}]
)
print(response.choices[0].message.content)
asyncio.run(main())
```
## Installation
```bash
# Using uv (recommended)
uv add openrouter
# Using pip
pip install openrouter
# Using poetry
poetry add openrouter
```
**Requirements:** Python 3.9 or higher
Get your API key from [openrouter.ai/settings/keys](https://openrouter.ai/settings/keys).
## Quick start
```python
from openrouter import OpenRouter
import os
with OpenRouter(
api_key=os.getenv("OPENROUTER_API_KEY")
) as client:
response = client.chat.send(
model="minimax/minimax-m2",
messages=[
{"role": "user", "content": "Hello!"}
]
)
print(response.choices[0].message.content)
```
+72 -409
View File
@@ -1,50 +1,16 @@
# OpenRouter SDK (Beta)
The [OpenRouter SDK](https://openrouter.ai/docs/sdks/python) is a Python toolkit designed to help you build AI-powered features and solutions. Giving you easy access to over 300 models across providers in an easy and type-safe way.
To learn more about how to use the OpenRouter SDK, check out our [API Reference](https://openrouter.ai/docs/sdks/python/reference) and [Documentation](https://openrouter.ai/docs/sdks/python).
<div align="center">
<img width="500" height="300" alt="image" src="https://github.com/user-attachments/assets/19d8ad52-cb56-4f87-8bce-9a9c2233ac16" />
<h1>OpenRouter Python SDK</h1>
<p>Developer-friendly Python SDK specifically catered to leverage the <strong>OpenRouter</strong> API.</p>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge" /></a>
</div>
<!-- No Summary [summary] -->
<!-- Start Summary [summary] -->
## Summary
OpenRouter Chat Completions API: OpenAI-compatible Chat Completions API with additional OpenRouter features
For more information about the API: [OpenRouter Documentation](https://openrouter.ai/docs)
<!-- End Summary [summary] -->
<!-- Start Table of Contents [toc] -->
## Table of Contents
<!-- $toc-max-depth=2 -->
* [SDK Installation](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#sdk-installation)
* [IDE Support](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#ide-support)
* [SDK Example Usage](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#sdk-example-usage)
* [Authentication](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#authentication)
* [Available Resources and Operations](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#available-resources-and-operations)
* [Server-sent event streaming](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#server-sent-event-streaming)
* [Retries](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#retries)
* [Error Handling](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#error-handling)
* [Server Selection](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#server-selection)
* [Custom HTTP Client](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#custom-http-client)
* [Resource Management](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#resource-management)
* [Debugging](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#debugging)
* [Development](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#development)
* [Maturity](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#maturity)
* [Contributions](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#contributions)
<!-- End Table of Contents [toc] -->
<!-- No Table of Contents [toc] -->
<!-- Start SDK Installation [installation] -->
## SDK Installation
> [!TIP]
> To finish publishing your SDK to PyPI you must [run your first generation action](https://www.speakeasy.com/docs/github-setup#step-by-step-guide).
> [!NOTE]
> **Python version upgrade policy**
>
@@ -57,7 +23,7 @@ The SDK can be installed with *uv*, *pip*, or *poetry* package managers.
*uv* is a fast Python package installer and resolver, designed as a drop-in replacement for pip and pip-tools. It's recommended for its speed and modern Python tooling capabilities.
```bash
uv add git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
uv add openrouter
```
### PIP
@@ -65,7 +31,7 @@ uv add git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
*PIP* is the default package installer for Python, enabling easy installation and management of packages from PyPI via the command line.
```bash
pip install git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
pip install openrouter
```
### Poetry
@@ -73,7 +39,7 @@ pip install git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
*Poetry* is a modern tool that simplifies dependency management and package publishing by using a single `pyproject.toml` file to handle project metadata and dependencies.
```bash
poetry add git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
poetry add openrouter
```
### Shell and script usage with `uv`
@@ -108,6 +74,12 @@ Once that is saved to a file, you can run it with `uv run script.py` where
`script.py` can be replaced with the actual file name.
<!-- End SDK Installation [installation] -->
<!-- Start Requirements [requirements] -->
## Requirements
This SDK requires Python 3.9 or higher. For Python version support policy, see the SDK Installation section above.
<!-- End Requirements [requirements] -->
<!-- Start IDE Support [idesupport] -->
## IDE Support
@@ -118,10 +90,8 @@ Generally, the SDK will work well with most IDEs out of the box. However, when u
- [PyCharm Pydantic Plugin](https://docs.pydantic.dev/latest/integrations/pycharm/)
<!-- End IDE Support [idesupport] -->
<!-- Start SDK Example Usage [usage] -->
## SDK Example Usage
### Example
<!-- No SDK Example Usage [usage] -->
## SDK Usage
```python
# Synchronous Example
@@ -133,20 +103,25 @@ with OpenRouter(
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.chat.complete(messages=[
res = open_router.chat.send(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
], model="anthropic/claude-4.5-sonnet", provider={
"zdr": True,
"sort": "price",
}, stream=True)
# Handle response
print(res)
for event in event_stream:
# handle event
print(event, flush=True)
```
</br>
The same SDK client can also be used to make asynchronous requests by importing asyncio.
```python
# Asynchronous Example
import asyncio
@@ -159,375 +134,40 @@ async def main():
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = await open_router.chat.complete_async(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
# Handle response
print(res)
asyncio.run(main())
```
<!-- End SDK Example Usage [usage] -->
<!-- Start Authentication [security] -->
## Authentication
### Per-Client Security Schemes
This SDK supports the following security scheme globally:
| Name | Type | Scheme | Environment Variable |
| --------- | ---- | ----------- | -------------------- |
| `api_key` | http | HTTP Bearer | `OPENROUTER_API_KEY` |
To authenticate with the API the `api_key` parameter must be set when initializing the SDK client instance. For example:
```python
from openrouter import OpenRouter
import os
with OpenRouter(
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.chat.complete(messages=[
res = await open_router.chat.send_async(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
], model="anthropic/claude-4.5-sonnet", provider={
"zdr": True,
"sort": "price",
}, stream=True)
# Handle response
print(res)
```
<!-- End Authentication [security] -->
<!-- Start Available Resources and Operations [operations] -->
## Available Resources and Operations
<details open>
<summary>Available methods</summary>
### [chat](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/docs/sdks/chat/README.md)
* [complete](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/docs/sdks/chat/README.md#complete) - Create a chat completion
* [complete_stream](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/docs/sdks/chat/README.md#complete_stream) - Create a chat completion
</details>
<!-- End Available Resources and Operations [operations] -->
<!-- Start Server-sent event streaming [eventstream] -->
## Server-sent event streaming
[Server-sent events][mdn-sse] are used to stream content from certain
operations. These operations will expose the stream as [Generator][generator] that
can be consumed using a simple `for` loop. The loop will
terminate when the server no longer has any events to send and closes the
underlying connection.
The stream is also a [Context Manager][context-manager] and can be used with the `with` statement and will close the
underlying connection when the context is exited.
```python
from openrouter import OpenRouter
import os
with OpenRouter(
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.chat.complete_stream(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=True, temperature=1, top_p=1)
with res as event_stream:
for event in event_stream:
async for event in event_stream:
# handle event
print(event, flush=True)
asyncio.run(main())
```
[mdn-sse]: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
[generator]: https://book.pythontips.com/en/latest/generators.html
[context-manager]: https://book.pythontips.com/en/latest/context_managers.html
<!-- End Server-sent event streaming [eventstream] -->
<!-- No Authentication [security] -->
<!-- Start Retries [retries] -->
## Retries
<!-- No Available Resources and Operations [operations] -->
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
<!-- No Standalone functions [standalone-funcs] -->
To change the default retry strategy for a single API call, simply provide a `RetryConfig` object to the call:
```python
from openrouter import OpenRouter
from openrouter.utils import BackoffStrategy, RetryConfig
import os
<!-- No React hooks with TanStack Query [react-query] -->
<!-- No Server-sent event streaming [eventstream] -->
with OpenRouter(
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
<!-- No Retries [retries] -->
res = open_router.chat.complete(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1,
RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))
<!-- No Error Handling [errors] -->
# Handle response
print(res)
<!-- No Server Selection [server] -->
```
If you'd like to override the default retry strategy for all operations that support retries, you can use the `retry_config` optional parameter when initializing the SDK:
```python
from openrouter import OpenRouter
from openrouter.utils import BackoffStrategy, RetryConfig
import os
with OpenRouter(
retry_config=RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False),
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.chat.complete(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
# Handle response
print(res)
```
<!-- End Retries [retries] -->
<!-- Start Error Handling [errors] -->
## Error Handling
[`OpenRouterError`](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/./src/openrouter/errors/openroutererror.py) is the base class for all HTTP error responses. It has the following properties:
| Property | Type | Description |
| ------------------ | ---------------- | --------------------------------------------------------------------------------------- |
| `err.message` | `str` | Error message |
| `err.status_code` | `int` | HTTP response status code eg `404` |
| `err.headers` | `httpx.Headers` | HTTP response headers |
| `err.body` | `str` | HTTP body. Can be empty string if no body is returned. |
| `err.raw_response` | `httpx.Response` | Raw HTTP response |
| `err.data` | | Optional. Some errors may contain structured data. [See Error Classes](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/#error-classes). |
### Example
```python
from openrouter import OpenRouter, errors
import os
with OpenRouter(
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = None
try:
res = open_router.chat.complete(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
# Handle response
print(res)
except errors.OpenRouterError as e:
# The base class for HTTP error responses
print(e.message)
print(e.status_code)
print(e.body)
print(e.headers)
print(e.raw_response)
# Depending on the method different errors may be thrown
if isinstance(e, errors.ChatCompletionError):
print(e.data.error) # models.Error
```
### Error Classes
**Primary errors:**
* [`OpenRouterError`](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/./src/openrouter/errors/openroutererror.py): The base class for HTTP error responses.
* [`ChatCompletionError`](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/./src/openrouter/errors/chatcompletionerror.py): Chat completion error response.
<details><summary>Less common errors (5)</summary>
<br />
**Network errors:**
* [`httpx.RequestError`](https://www.python-httpx.org/exceptions/#httpx.RequestError): Base class for request errors.
* [`httpx.ConnectError`](https://www.python-httpx.org/exceptions/#httpx.ConnectError): HTTP client was unable to make a request to a server.
* [`httpx.TimeoutException`](https://www.python-httpx.org/exceptions/#httpx.TimeoutException): HTTP request timed out.
**Inherit from [`OpenRouterError`](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/./src/openrouter/errors/openroutererror.py)**:
* [`ResponseValidationError`](https://github.com/speakeasy-sdks/openrouter-python-sdk/blob/master/./src/openrouter/errors/responsevalidationerror.py): Type mismatch between the response data and the expected Pydantic model. Provides access to the Pydantic validation error via the `cause` attribute.
</details>
<!-- End Error Handling [errors] -->
<!-- Start Server Selection [server] -->
## Server Selection
### Server Variables
The default server `https://{provider_url}/api/v1` contains variables and is set to `https://openrouter.ai/api/v1` by default. To override default values, the following parameters are available when initializing the SDK client instance:
| Variable | Parameter | Default | Description |
| -------------- | ------------------- | ----------------- | ----------- |
| `provider_url` | `provider_url: str` | `"openrouter.ai"` | |
#### Example
```python
from openrouter import OpenRouter
import os
with OpenRouter(
provider_url="https://ruddy-guacamole.info/"
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.chat.complete(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
# Handle response
print(res)
```
### Override Server URL Per-Client
The default server can be overridden globally by passing a URL to the `server_url: str` optional parameter when initializing the SDK client instance. For example:
```python
from openrouter import OpenRouter
import os
with OpenRouter(
server_url="https://openrouter.ai/api/v1",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.chat.complete(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
# Handle response
print(res)
```
<!-- End Server Selection [server] -->
<!-- Start Custom HTTP Client [http-client] -->
## Custom HTTP Client
The Python SDK makes API calls using the [httpx](https://www.python-httpx.org/) HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with your own HTTP client instance.
Depending on whether you are using the sync or async version of the SDK, you can pass an instance of `HttpClient` or `AsyncHttpClient` respectively, which are Protocol's ensuring that the client has the necessary methods to make API calls.
This allows you to wrap the client with your own custom logic, such as adding custom headers, logging, or error handling, or you can just pass an instance of `httpx.Client` or `httpx.AsyncClient` directly.
For example, you could specify a header for every request that this sdk makes as follows:
```python
from openrouter import OpenRouter
import httpx
http_client = httpx.Client(headers={"x-custom-header": "someValue"})
s = OpenRouter(client=http_client)
```
or you could wrap the client with your own custom logic:
```python
from openrouter import OpenRouter
from openrouter.httpclient import AsyncHttpClient
import httpx
class CustomClient(AsyncHttpClient):
client: AsyncHttpClient
def __init__(self, client: AsyncHttpClient):
self.client = client
async def send(
self,
request: httpx.Request,
*,
stream: bool = False,
auth: Union[
httpx._types.AuthTypes, httpx._client.UseClientDefault, None
] = httpx.USE_CLIENT_DEFAULT,
follow_redirects: Union[
bool, httpx._client.UseClientDefault
] = httpx.USE_CLIENT_DEFAULT,
) -> httpx.Response:
request.headers["Client-Level-Header"] = "added by client"
return await self.client.send(
request, stream=stream, auth=auth, follow_redirects=follow_redirects
)
def build_request(
self,
method: str,
url: httpx._types.URLTypes,
*,
content: Optional[httpx._types.RequestContent] = None,
data: Optional[httpx._types.RequestData] = None,
files: Optional[httpx._types.RequestFiles] = None,
json: Optional[Any] = None,
params: Optional[httpx._types.QueryParamTypes] = None,
headers: Optional[httpx._types.HeaderTypes] = None,
cookies: Optional[httpx._types.CookieTypes] = None,
timeout: Union[
httpx._types.TimeoutTypes, httpx._client.UseClientDefault
] = httpx.USE_CLIENT_DEFAULT,
extensions: Optional[httpx._types.RequestExtensions] = None,
) -> httpx.Request:
return self.client.build_request(
method,
url,
content=content,
data=data,
files=files,
json=json,
params=params,
headers=headers,
cookies=cookies,
timeout=timeout,
extensions=extensions,
)
s = OpenRouter(async_client=CustomClient(httpx.AsyncClient()))
```
<!-- End Custom HTTP Client [http-client] -->
<!-- No Custom HTTP Client [http-client] -->
<!-- Start Resource Management [resource-management] -->
## Resource Management
@@ -542,6 +182,9 @@ import os
def main():
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
# Rest of application here...
@@ -551,6 +194,9 @@ def main():
async def amain():
async with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
# Rest of application here...
@@ -578,15 +224,32 @@ You can also enable a default debug logger by setting an environment variable `O
# Development
## Running Tests
To run the test suite, you'll need to set up your environment with an OpenRouter API key.
### Local Development
1. Copy the example environment file:
```bash
cp .env.example .env
```
2. Edit `.env` and add your OpenRouter API key:
```bash
OPENROUTER_API_KEY=your_api_key_here
```
3. Run the tests:
```bash
pytest
```
## Maturity
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage
to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally
looking for the latest version.
## Contributions
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation.
We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.
### SDK Created by [Speakeasy](https://www.speakeasy.com/?utm_source=open-router&utm_campaign=python)
looking for the latest version.
+72 -409
View File
@@ -1,50 +1,16 @@
# OpenRouter SDK (Beta)
The [OpenRouter SDK](https://openrouter.ai/docs/sdks/python) is a Python toolkit designed to help you build AI-powered features and solutions. Giving you easy access to over 300 models across providers in an easy and type-safe way.
To learn more about how to use the OpenRouter SDK, check out our [API Reference](https://openrouter.ai/docs/sdks/python/reference) and [Documentation](https://openrouter.ai/docs/sdks/python).
<div align="center">
<img width="500" height="300" alt="image" src="https://github.com/user-attachments/assets/19d8ad52-cb56-4f87-8bce-9a9c2233ac16" />
<h1>OpenRouter Python SDK</h1>
<p>Developer-friendly Python SDK specifically catered to leverage the <strong>OpenRouter</strong> API.</p>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge" /></a>
</div>
<!-- No Summary [summary] -->
<!-- Start Summary [summary] -->
## Summary
OpenRouter Chat Completions API: OpenAI-compatible Chat Completions API with additional OpenRouter features
For more information about the API: [OpenRouter Documentation](https://openrouter.ai/docs)
<!-- End Summary [summary] -->
<!-- Start Table of Contents [toc] -->
## Table of Contents
<!-- $toc-max-depth=2 -->
* [SDK Installation](#sdk-installation)
* [IDE Support](#ide-support)
* [SDK Example Usage](#sdk-example-usage)
* [Authentication](#authentication)
* [Available Resources and Operations](#available-resources-and-operations)
* [Server-sent event streaming](#server-sent-event-streaming)
* [Retries](#retries)
* [Error Handling](#error-handling)
* [Server Selection](#server-selection)
* [Custom HTTP Client](#custom-http-client)
* [Resource Management](#resource-management)
* [Debugging](#debugging)
* [Development](#development)
* [Maturity](#maturity)
* [Contributions](#contributions)
<!-- End Table of Contents [toc] -->
<!-- No Table of Contents [toc] -->
<!-- Start SDK Installation [installation] -->
## SDK Installation
> [!TIP]
> To finish publishing your SDK to PyPI you must [run your first generation action](https://www.speakeasy.com/docs/github-setup#step-by-step-guide).
> [!NOTE]
> **Python version upgrade policy**
>
@@ -57,7 +23,7 @@ The SDK can be installed with *uv*, *pip*, or *poetry* package managers.
*uv* is a fast Python package installer and resolver, designed as a drop-in replacement for pip and pip-tools. It's recommended for its speed and modern Python tooling capabilities.
```bash
uv add git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
uv add openrouter
```
### PIP
@@ -65,7 +31,7 @@ uv add git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
*PIP* is the default package installer for Python, enabling easy installation and management of packages from PyPI via the command line.
```bash
pip install git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
pip install openrouter
```
### Poetry
@@ -73,7 +39,7 @@ pip install git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
*Poetry* is a modern tool that simplifies dependency management and package publishing by using a single `pyproject.toml` file to handle project metadata and dependencies.
```bash
poetry add git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
poetry add openrouter
```
### Shell and script usage with `uv`
@@ -108,6 +74,12 @@ Once that is saved to a file, you can run it with `uv run script.py` where
`script.py` can be replaced with the actual file name.
<!-- End SDK Installation [installation] -->
<!-- Start Requirements [requirements] -->
## Requirements
This SDK requires Python 3.9 or higher. For Python version support policy, see the SDK Installation section above.
<!-- End Requirements [requirements] -->
<!-- Start IDE Support [idesupport] -->
## IDE Support
@@ -118,10 +90,8 @@ Generally, the SDK will work well with most IDEs out of the box. However, when u
- [PyCharm Pydantic Plugin](https://docs.pydantic.dev/latest/integrations/pycharm/)
<!-- End IDE Support [idesupport] -->
<!-- Start SDK Example Usage [usage] -->
## SDK Example Usage
### Example
<!-- No SDK Example Usage [usage] -->
## SDK Usage
```python
# Synchronous Example
@@ -133,20 +103,25 @@ with OpenRouter(
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.chat.complete(messages=[
res = open_router.chat.send(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
], model="anthropic/claude-4.5-sonnet", provider={
"zdr": True,
"sort": "price",
}, stream=True)
# Handle response
print(res)
for event in event_stream:
# handle event
print(event, flush=True)
```
</br>
The same SDK client can also be used to make asynchronous requests by importing asyncio.
```python
# Asynchronous Example
import asyncio
@@ -159,375 +134,40 @@ async def main():
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = await open_router.chat.complete_async(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
# Handle response
print(res)
asyncio.run(main())
```
<!-- End SDK Example Usage [usage] -->
<!-- Start Authentication [security] -->
## Authentication
### Per-Client Security Schemes
This SDK supports the following security scheme globally:
| Name | Type | Scheme | Environment Variable |
| --------- | ---- | ----------- | -------------------- |
| `api_key` | http | HTTP Bearer | `OPENROUTER_API_KEY` |
To authenticate with the API the `api_key` parameter must be set when initializing the SDK client instance. For example:
```python
from openrouter import OpenRouter
import os
with OpenRouter(
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.chat.complete(messages=[
res = await open_router.chat.send_async(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
], model="anthropic/claude-4.5-sonnet", provider={
"zdr": True,
"sort": "price",
}, stream=True)
# Handle response
print(res)
```
<!-- End Authentication [security] -->
<!-- Start Available Resources and Operations [operations] -->
## Available Resources and Operations
<details open>
<summary>Available methods</summary>
### [chat](docs/sdks/chat/README.md)
* [complete](docs/sdks/chat/README.md#complete) - Create a chat completion
* [complete_stream](docs/sdks/chat/README.md#complete_stream) - Create a chat completion
</details>
<!-- End Available Resources and Operations [operations] -->
<!-- Start Server-sent event streaming [eventstream] -->
## Server-sent event streaming
[Server-sent events][mdn-sse] are used to stream content from certain
operations. These operations will expose the stream as [Generator][generator] that
can be consumed using a simple `for` loop. The loop will
terminate when the server no longer has any events to send and closes the
underlying connection.
The stream is also a [Context Manager][context-manager] and can be used with the `with` statement and will close the
underlying connection when the context is exited.
```python
from openrouter import OpenRouter
import os
with OpenRouter(
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.chat.complete_stream(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=True, temperature=1, top_p=1)
with res as event_stream:
for event in event_stream:
async for event in event_stream:
# handle event
print(event, flush=True)
asyncio.run(main())
```
[mdn-sse]: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
[generator]: https://book.pythontips.com/en/latest/generators.html
[context-manager]: https://book.pythontips.com/en/latest/context_managers.html
<!-- End Server-sent event streaming [eventstream] -->
<!-- No Authentication [security] -->
<!-- Start Retries [retries] -->
## Retries
<!-- No Available Resources and Operations [operations] -->
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
<!-- No Standalone functions [standalone-funcs] -->
To change the default retry strategy for a single API call, simply provide a `RetryConfig` object to the call:
```python
from openrouter import OpenRouter
from openrouter.utils import BackoffStrategy, RetryConfig
import os
<!-- No React hooks with TanStack Query [react-query] -->
<!-- No Server-sent event streaming [eventstream] -->
with OpenRouter(
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
<!-- No Retries [retries] -->
res = open_router.chat.complete(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1,
RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))
<!-- No Error Handling [errors] -->
# Handle response
print(res)
<!-- No Server Selection [server] -->
```
If you'd like to override the default retry strategy for all operations that support retries, you can use the `retry_config` optional parameter when initializing the SDK:
```python
from openrouter import OpenRouter
from openrouter.utils import BackoffStrategy, RetryConfig
import os
with OpenRouter(
retry_config=RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False),
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.chat.complete(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
# Handle response
print(res)
```
<!-- End Retries [retries] -->
<!-- Start Error Handling [errors] -->
## Error Handling
[`OpenRouterError`](./src/openrouter/errors/openroutererror.py) is the base class for all HTTP error responses. It has the following properties:
| Property | Type | Description |
| ------------------ | ---------------- | --------------------------------------------------------------------------------------- |
| `err.message` | `str` | Error message |
| `err.status_code` | `int` | HTTP response status code eg `404` |
| `err.headers` | `httpx.Headers` | HTTP response headers |
| `err.body` | `str` | HTTP body. Can be empty string if no body is returned. |
| `err.raw_response` | `httpx.Response` | Raw HTTP response |
| `err.data` | | Optional. Some errors may contain structured data. [See Error Classes](#error-classes). |
### Example
```python
from openrouter import OpenRouter, errors
import os
with OpenRouter(
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = None
try:
res = open_router.chat.complete(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
# Handle response
print(res)
except errors.OpenRouterError as e:
# The base class for HTTP error responses
print(e.message)
print(e.status_code)
print(e.body)
print(e.headers)
print(e.raw_response)
# Depending on the method different errors may be thrown
if isinstance(e, errors.ChatCompletionError):
print(e.data.error) # models.Error
```
### Error Classes
**Primary errors:**
* [`OpenRouterError`](./src/openrouter/errors/openroutererror.py): The base class for HTTP error responses.
* [`ChatCompletionError`](./src/openrouter/errors/chatcompletionerror.py): Chat completion error response.
<details><summary>Less common errors (5)</summary>
<br />
**Network errors:**
* [`httpx.RequestError`](https://www.python-httpx.org/exceptions/#httpx.RequestError): Base class for request errors.
* [`httpx.ConnectError`](https://www.python-httpx.org/exceptions/#httpx.ConnectError): HTTP client was unable to make a request to a server.
* [`httpx.TimeoutException`](https://www.python-httpx.org/exceptions/#httpx.TimeoutException): HTTP request timed out.
**Inherit from [`OpenRouterError`](./src/openrouter/errors/openroutererror.py)**:
* [`ResponseValidationError`](./src/openrouter/errors/responsevalidationerror.py): Type mismatch between the response data and the expected Pydantic model. Provides access to the Pydantic validation error via the `cause` attribute.
</details>
<!-- End Error Handling [errors] -->
<!-- Start Server Selection [server] -->
## Server Selection
### Server Variables
The default server `https://{provider_url}/api/v1` contains variables and is set to `https://openrouter.ai/api/v1` by default. To override default values, the following parameters are available when initializing the SDK client instance:
| Variable | Parameter | Default | Description |
| -------------- | ------------------- | ----------------- | ----------- |
| `provider_url` | `provider_url: str` | `"openrouter.ai"` | |
#### Example
```python
from openrouter import OpenRouter
import os
with OpenRouter(
provider_url="https://ruddy-guacamole.info/"
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.chat.complete(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
# Handle response
print(res)
```
### Override Server URL Per-Client
The default server can be overridden globally by passing a URL to the `server_url: str` optional parameter when initializing the SDK client instance. For example:
```python
from openrouter import OpenRouter
import os
with OpenRouter(
server_url="https://openrouter.ai/api/v1",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.chat.complete(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
# Handle response
print(res)
```
<!-- End Server Selection [server] -->
<!-- Start Custom HTTP Client [http-client] -->
## Custom HTTP Client
The Python SDK makes API calls using the [httpx](https://www.python-httpx.org/) HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with your own HTTP client instance.
Depending on whether you are using the sync or async version of the SDK, you can pass an instance of `HttpClient` or `AsyncHttpClient` respectively, which are Protocol's ensuring that the client has the necessary methods to make API calls.
This allows you to wrap the client with your own custom logic, such as adding custom headers, logging, or error handling, or you can just pass an instance of `httpx.Client` or `httpx.AsyncClient` directly.
For example, you could specify a header for every request that this sdk makes as follows:
```python
from openrouter import OpenRouter
import httpx
http_client = httpx.Client(headers={"x-custom-header": "someValue"})
s = OpenRouter(client=http_client)
```
or you could wrap the client with your own custom logic:
```python
from openrouter import OpenRouter
from openrouter.httpclient import AsyncHttpClient
import httpx
class CustomClient(AsyncHttpClient):
client: AsyncHttpClient
def __init__(self, client: AsyncHttpClient):
self.client = client
async def send(
self,
request: httpx.Request,
*,
stream: bool = False,
auth: Union[
httpx._types.AuthTypes, httpx._client.UseClientDefault, None
] = httpx.USE_CLIENT_DEFAULT,
follow_redirects: Union[
bool, httpx._client.UseClientDefault
] = httpx.USE_CLIENT_DEFAULT,
) -> httpx.Response:
request.headers["Client-Level-Header"] = "added by client"
return await self.client.send(
request, stream=stream, auth=auth, follow_redirects=follow_redirects
)
def build_request(
self,
method: str,
url: httpx._types.URLTypes,
*,
content: Optional[httpx._types.RequestContent] = None,
data: Optional[httpx._types.RequestData] = None,
files: Optional[httpx._types.RequestFiles] = None,
json: Optional[Any] = None,
params: Optional[httpx._types.QueryParamTypes] = None,
headers: Optional[httpx._types.HeaderTypes] = None,
cookies: Optional[httpx._types.CookieTypes] = None,
timeout: Union[
httpx._types.TimeoutTypes, httpx._client.UseClientDefault
] = httpx.USE_CLIENT_DEFAULT,
extensions: Optional[httpx._types.RequestExtensions] = None,
) -> httpx.Request:
return self.client.build_request(
method,
url,
content=content,
data=data,
files=files,
json=json,
params=params,
headers=headers,
cookies=cookies,
timeout=timeout,
extensions=extensions,
)
s = OpenRouter(async_client=CustomClient(httpx.AsyncClient()))
```
<!-- End Custom HTTP Client [http-client] -->
<!-- No Custom HTTP Client [http-client] -->
<!-- Start Resource Management [resource-management] -->
## Resource Management
@@ -542,6 +182,9 @@ import os
def main():
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
# Rest of application here...
@@ -551,6 +194,9 @@ def main():
async def amain():
async with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
# Rest of application here...
@@ -578,15 +224,32 @@ You can also enable a default debug logger by setting an environment variable `O
# Development
## Running Tests
To run the test suite, you'll need to set up your environment with an OpenRouter API key.
### Local Development
1. Copy the example environment file:
```bash
cp .env.example .env
```
2. Edit `.env` and add your OpenRouter API key:
```bash
OPENROUTER_API_KEY=your_api_key_here
```
3. Run the tests:
```bash
pytest
```
## Maturity
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage
to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally
looking for the latest version.
## Contributions
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation.
We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.
### SDK Created by [Speakeasy](https://www.speakeasy.com/?utm_source=open-router&utm_campaign=python)
looking for the latest version.
+5 -3
View File
@@ -1,9 +1,11 @@
## 2025-08-22 15:59:18
## 2025-11-15 18:16:18
### Changes
Based on:
- OpenAPI Doc
- Speakeasy CLI 1.606.2 (2.687.1) https://github.com/speakeasy-api/speakeasy
- Speakeasy CLI 1.658.1 (2.755.6) https://github.com/speakeasy-api/speakeasy
### Generated
- [python v0.1.3] .
- [python v0.0.16] .
### Releases
- [PyPI v0.0.16] https://pypi.org/project/openrouter/0.0.16 - .
+17 -16
View File
@@ -6,23 +6,24 @@ import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.chat.complete(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
res = open_router.beta.responses.send(service_tier="auto", stream=False)
# Handle response
print(res)
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
```
</br>
The same SDK client can also be used to make asynchronous requests by importing asyncio.
```python
# Asynchronous Example
import asyncio
@@ -32,18 +33,18 @@ import os
async def main():
async with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = await open_router.chat.complete_async(messages=[
{
"role": "user",
"content": "Hello, how are you?",
},
], stream=False, temperature=1, top_p=1)
res = await open_router.beta.responses.send_async(service_tier="auto", stream=False)
# Handle response
print(res)
async with res as event_stream:
async for event in event_stream:
# handle event
print(event, flush=True)
asyncio.run(main())
```
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

+10
View File
@@ -0,0 +1,10 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="400" viewBox="0 0 1200 400">
<title>OpenRouter</title>
<path fill="currentColor" d="M431.4 196.2c0 11.2-2.1 20.8-6.2 28.8a45 45 0 0 1-41 25 44.8 44.8 0 0 1-41-25c-4.2-8-6.2-17.7-6.2-28.8 0-11.2 2-20.8 6.1-28.8a44.9 44.9 0 0 1 41.1-25 45 45 0 0 1 41 25c4.1 8 6.2 17.6 6.2 28.8m-15.7 0c0-8.5-1.4-15.7-4.1-21.6a30.6 30.6 0 0 0-11.3-13.3c-4.7-3-10.1-4.5-16.1-4.5a30 30 0 0 0-16.2 4.5c-4.7 3-8.4 7.5-11.2 13.3-2.7 5.9-4.1 13-4.1 21.6 0 8.5 1.4 15.7 4.1 21.5A30.7 30.7 0 0 0 368 231c4.8 3 10.2 4.6 16.2 4.6s11.4-1.5 16.1-4.6c4.8-3 8.5-7.4 11.3-13.3 2.7-5.8 4.1-13 4.1-21.5Zm34 81.8V170h15v12.7h1.3c.9-1.6 2.1-3.5 3.8-5.6a22 22 0 0 1 18.7-8.1 30.6 30.6 0 0 1 28.7 18.6c2.9 6 4.3 13.3 4.3 21.8s-1.4 15.8-4.2 21.8a33 33 0 0 1-11.7 14 30 30 0 0 1-17 4.9c-4.7 0-8.6-.8-11.6-2.4a22 22 0 0 1-7.1-5.6c-1.7-2.2-3-4.1-4-5.8h-.8V278h-15.3m15-68.7c0 5.5.7 10.3 2.3 14.5 1.6 4.2 4 7.4 7 9.7 3 2.4 6.7 3.5 11.1 3.5 4.6 0 8.4-1.2 11.5-3.6 3-2.5 5.4-5.8 7-10 1.6-4.2 2.4-8.9 2.4-14.1 0-5.2-.8-9.9-2.4-14a21.7 21.7 0 0 0-7-9.7 18 18 0 0 0-11.5-3.6c-4.4 0-8.1 1.1-11.2 3.4-3 2.3-5.3 5.5-7 9.6a40 40 0 0 0-2.3 14.3ZM572.4 250c-7.8 0-14.4-1.6-20-5-5.6-3.3-9.9-8-12.9-14s-4.5-13.2-4.5-21.3c0-8 1.5-15.1 4.5-21.3a35 35 0 0 1 12.7-14.4 38.5 38.5 0 0 1 32-3 31.3 31.3 0 0 1 19 19.2c2 5 2.9 11 2.9 18.2v5.4h-62.5v-11.5h47.5c0-4-.8-7.6-2.5-10.7a18.6 18.6 0 0 0-17.2-10c-4.3 0-8 1-11.2 3a22.3 22.3 0 0 0-10 19.2v9c0 5.2 1 9.6 2.8 13.3 1.9 3.7 4.5 6.5 7.8 8.4a23 23 0 0 0 11.7 2.9c3 0 5.6-.4 8-1.3a16.4 16.4 0 0 0 10.2-10l14.4 2.7c-1.1 4.3-3.2 8-6.2 11.2-3 3.2-6.7 5.6-11.2 7.4a41.7 41.7 0 0 1-15.3 2.6Zm66-48.2v46.7h-15.3V170H638v12.8h1c1.8-4.2 4.6-7.5 8.5-10 3.8-2.6 8.7-3.8 14.6-3.8 5.4 0 10 1.1 14 3.3 4.1 2.3 7.2 5.6 9.4 10a36 36 0 0 1 3.4 16.3v50h-15.3v-48.2a19 19 0 0 0-4.5-13.3c-3-3.3-7-4.9-12.2-4.9a19 19 0 0 0-9.4 2.3 16.4 16.4 0 0 0-6.5 6.8 21.8 21.8 0 0 0-2.4 10.6Zm72 46.7V143.8h37.3c8 0 14.8 1.4 20.2 4.2 5.4 2.8 9.4 6.7 12 11.6a35 35 0 0 1 4 17c0 6.5-1.3 12.1-4 17a27.3 27.3 0 0 1-12 11.3c-5.4 2.7-12.2 4-20.3 4h-28.2v-13.6h26.8c5.1 0 9.3-.7 12.5-2.2 3.2-1.4 5.6-3.6 7-6.4a21 21 0 0 0 2.3-10c0-4-.7-7.4-2.2-10.3a15.2 15.2 0 0 0-7.1-6.7 29.3 29.3 0 0 0-12.7-2.3h-19.9v91.2h-15.7m51.7-47.3 25.8 47.3h-18l-25.3-47.3h17.5Zm73 48.8a34.1 34.1 0 0 1-32-19.2 47 47 0 0 1-4.6-21.3c0-8.1 1.5-15.2 4.5-21.3a34.1 34.1 0 0 1 32-19.3 34.1 34.1 0 0 1 32 19.3 45 45 0 0 1 4.7 21.3 47 47 0 0 1-4.6 21.3 34.1 34.1 0 0 1-32 19.2m0-12.8c4.8 0 8.8-1.3 11.9-3.8 3.1-2.5 5.4-5.9 7-10a42 42 0 0 0 2.2-14c0-5-.7-9.5-2.2-13.8a22.8 22.8 0 0 0-7-10.1 18.2 18.2 0 0 0-11.9-3.8c-4.8 0-8.8 1.2-12 3.8-3 2.6-5.4 6-7 10.2a40.5 40.5 0 0 0-2.2 13.8c0 5 .8 9.6 2.3 13.8 1.5 4.2 3.8 7.6 7 10.1 3.1 2.5 7.1 3.8 12 3.8ZM938.6 216v-46h15.3v78.6h-15v-13.7h-.8a24.4 24.4 0 0 1-23.5 14.7 26 26 0 0 1-13.4-3.4 23 23 0 0 1-9-10 36.3 36.3 0 0 1-3.4-16.2v-50h15.3v48.1a18 18 0 0 0 4.4 12.8c3 3.2 6.9 4.8 11.6 4.8a19 19 0 0 0 15.7-8.7c1.9-2.9 2.8-6.6 2.8-11Zm72.5-46v12.3h-43V170h43m-31.4-18.8H995v74.3c0 3 .4 5.2 1.3 6.7.9 1.4 2 2.5 3.5 3 1.4.5 3 .8 4.6.8a176.6 176.6 0 0 0 5.4-.7l2.7 12.6a27.2 27.2 0 0 1-10 1.7c-4 0-7.7-.7-11.2-2.2a19.3 19.3 0 0 1-8.4-7c-2.1-3-3.2-7-3.2-11.7v-77.5Zm82.1 99c-7.7 0-14.4-1.7-20-5-5.5-3.4-9.8-8-12.8-14.1-3-6-4.6-13.2-4.6-21.3a47 47 0 0 1 4.6-21.3c3-6.1 7.2-11 12.6-14.4a38.5 38.5 0 0 1 32-3 31.3 31.3 0 0 1 19 19.2c2 5 3 11 3 18.2v5.4H1033v-11.5h47.4c0-4-.8-7.6-2.4-10.7a18.7 18.7 0 0 0-17.3-10c-4.3 0-8 1-11.2 3a22.9 22.9 0 0 0-9.9 19.2v9c0 5.2.9 9.6 2.8 13.3 1.8 3.7 4.4 6.5 7.8 8.4a23 23 0 0 0 11.7 2.9 24 24 0 0 0 7.9-1.3 16.7 16.7 0 0 0 10.2-9.9l14.4 2.6a26 26 0 0 1-6.2 11.2 30 30 0 0 1-11.2 7.4 41.6 41.6 0 0 1-15.3 2.6Zm50.7-1.6V170h14.8v12.5h.8c1.5-4.2 4-7.6 7.6-10 3.7-2.5 7.8-3.7 12.4-3.7a68 68 0 0 1 6.5.4v14.6a31.9 31.9 0 0 0-8-1 20 20 0 0 0-9.6 2.4 17.2 17.2 0 0 0-9.2 15.4v48h-15.3Z"/>
<g fill="currentColor" stroke="currentColor">
<path stroke-width="35.3" d="M46.2 200.5c5.9 0 28.6-5.1 40.3-11.8 11.8-6.6 11.8-6.6 36.1-23.9 30.8-21.8 52.5-14.5 88.2-14.5"/>
<path stroke-width=".4" d="M245.3 150.5 185 185.3v-69.6l60.3 34.8Z"/>
<path stroke-width="35.3" d="M45 200.5c5.9 0 28.6 5 40.4 11.7 11.7 6.7 11.7 6.7 36 24 30.8 21.8 52.5 14.5 88.2 14.5"/>
<path stroke-width=".4" d="m244.1 250.4-60.3-34.7v69.5l60.3-34.8Z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.2 KiB

+18
View File
@@ -0,0 +1,18 @@
# ActivityItem
## Fields
| Field | Type | Required | Description | Example |
| --------------------------------------------------- | --------------------------------------------------- | --------------------------------------------------- | --------------------------------------------------- | --------------------------------------------------- |
| `date_` | *str* | :heavy_check_mark: | Date of the activity (YYYY-MM-DD format) | 2025-08-24 |
| `model` | *str* | :heavy_check_mark: | Model slug (e.g., "openai/gpt-4.1") | openai/gpt-4.1 |
| `model_permaslug` | *str* | :heavy_check_mark: | Model permaslug (e.g., "openai/gpt-4.1-2025-04-14") | openai/gpt-4.1-2025-04-14 |
| `endpoint_id` | *str* | :heavy_check_mark: | Unique identifier for the endpoint | 550e8400-e29b-41d4-a716-446655440000 |
| `provider_name` | *str* | :heavy_check_mark: | Name of the provider serving this endpoint | OpenAI |
| `usage` | *float* | :heavy_check_mark: | Total cost in USD (OpenRouter credits spent) | 0.015 |
| `byok_usage_inference` | *float* | :heavy_check_mark: | BYOK inference cost in USD (external credits spent) | 0.012 |
| `requests` | *float* | :heavy_check_mark: | Number of requests made | 5 |
| `prompt_tokens` | *float* | :heavy_check_mark: | Total prompt tokens used | 50 |
| `completion_tokens` | *float* | :heavy_check_mark: | Total completion tokens generated | 125 |
| `reasoning_tokens` | *float* | :heavy_check_mark: | Total reasoning tokens used | 25 |
+14
View File
@@ -0,0 +1,14 @@
# Architecture
Model architecture information
## Fields
| Field | Type | Required | Description | Example |
| ------------------------------------------------------------------ | ------------------------------------------------------------------ | ------------------------------------------------------------------ | ------------------------------------------------------------------ | ------------------------------------------------------------------ |
| `tokenizer` | [Nullable[components.Tokenizer]](../components/tokenizer.md) | :heavy_check_mark: | N/A | GPT |
| `instruct_type` | [Nullable[components.InstructType]](../components/instructtype.md) | :heavy_check_mark: | Instruction format type | |
| `modality` | *Nullable[str]* | :heavy_check_mark: | Primary modality of the model | text |
| `input_modalities` | List[[components.InputModality](../components/inputmodality.md)] | :heavy_check_mark: | Supported input modalities | |
| `output_modalities` | List[[components.OutputModality](../components/outputmodality.md)] | :heavy_check_mark: | Supported output modalities | |
@@ -0,0 +1,12 @@
# BadGatewayResponseErrorData
Error data for BadGatewayResponse
## Fields
| Field | Type | Required | Description |
| -------------------------- | -------------------------- | -------------------------- | -------------------------- |
| `code` | *int* | :heavy_check_mark: | N/A |
| `message` | *str* | :heavy_check_mark: | N/A |
| `metadata` | Dict[str, *Nullable[Any]*] | :heavy_minus_sign: | N/A |
@@ -0,0 +1,12 @@
# BadRequestResponseErrorData
Error data for BadRequestResponse
## Fields
| Field | Type | Required | Description |
| -------------------------- | -------------------------- | -------------------------- | -------------------------- |
| `code` | *int* | :heavy_check_mark: | N/A |
| `message` | *str* | :heavy_check_mark: | N/A |
| `metadata` | Dict[str, *Nullable[Any]*] | :heavy_minus_sign: | N/A |
+13
View File
@@ -0,0 +1,13 @@
# By
The provider sorting strategy (price, throughput, latency)
## Values
| Name | Value |
| ------------ | ------------ |
| `PRICE` | price |
| `THROUGHPUT` | throughput |
| `LATENCY` | latency |
| `EXACTO` | exacto |
+10
View File
@@ -0,0 +1,10 @@
# ChatStreamOptions
Streaming configuration options
## Fields
| Field | Type | Required | Description | Example |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ~~`include_usage`~~ | *Optional[bool]* | :heavy_minus_sign: | : warning: ** DEPRECATED **: This will be removed in a future release, please migrate away from it as soon as possible.<br/><br/>Deprecated: This field has no effect. Full usage details are always included. | true |
+25
View File
@@ -0,0 +1,25 @@
# Code
## Values
| Name | Value |
| -------------------------------- | -------------------------------- |
| `SERVER_ERROR` | server_error |
| `RATE_LIMIT_EXCEEDED` | rate_limit_exceeded |
| `INVALID_PROMPT` | invalid_prompt |
| `VECTOR_STORE_TIMEOUT` | vector_store_timeout |
| `INVALID_IMAGE` | invalid_image |
| `INVALID_IMAGE_FORMAT` | invalid_image_format |
| `INVALID_BASE64_IMAGE` | invalid_base64_image |
| `INVALID_IMAGE_URL` | invalid_image_url |
| `IMAGE_TOO_LARGE` | image_too_large |
| `IMAGE_TOO_SMALL` | image_too_small |
| `IMAGE_PARSE_ERROR` | image_parse_error |
| `IMAGE_CONTENT_POLICY_VIOLATION` | image_content_policy_violation |
| `INVALID_IMAGE_MODE` | invalid_image_mode |
| `IMAGE_FILE_TOO_LARGE` | image_file_too_large |
| `UNSUPPORTED_IMAGE_MEDIA_TYPE` | unsupported_image_media_type |
| `EMPTY_IMAGE_FILE` | empty_image_file |
| `FAILED_TO_DOWNLOAD_IMAGE` | failed_to_download_image |
| `IMAGE_FILE_NOT_FOUND` | image_file_not_found |
@@ -7,7 +7,7 @@ Detailed completion token usage
| Field | Type | Required | Description |
| ---------------------------- | ---------------------------- | ---------------------------- | ---------------------------- |
| `reasoning_tokens` | *Optional[float]* | :heavy_minus_sign: | Tokens used for reasoning |
| `audio_tokens` | *Optional[float]* | :heavy_minus_sign: | Tokens used for audio output |
| `accepted_prediction_tokens` | *Optional[float]* | :heavy_minus_sign: | Accepted prediction tokens |
| `rejected_prediction_tokens` | *Optional[float]* | :heavy_minus_sign: | Rejected prediction tokens |
| `reasoning_tokens` | *OptionalNullable[float]* | :heavy_minus_sign: | Tokens used for reasoning |
| `audio_tokens` | *OptionalNullable[float]* | :heavy_minus_sign: | Tokens used for audio output |
| `accepted_prediction_tokens` | *OptionalNullable[float]* | :heavy_minus_sign: | Accepted prediction tokens |
| `rejected_prediction_tokens` | *OptionalNullable[float]* | :heavy_minus_sign: | Rejected prediction tokens |
+10
View File
@@ -0,0 +1,10 @@
# CostDetails
## Fields
| Field | Type | Required | Description |
| -------------------------------- | -------------------------------- | -------------------------------- | -------------------------------- |
| `upstream_inference_cost` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
| `upstream_inference_input_cost` | *float* | :heavy_check_mark: | N/A |
| `upstream_inference_output_cost` | *float* | :heavy_check_mark: | N/A |
+10
View File
@@ -0,0 +1,10 @@
# Data
Model count data
## Fields
| Field | Type | Required | Description | Example |
| -------------------------------- | -------------------------------- | -------------------------------- | -------------------------------- | -------------------------------- |
| `count` | *float* | :heavy_check_mark: | Total number of available models | 150 |
@@ -1,9 +1,9 @@
# ChatCompletionCreateParamsDataCollection
# DataCollection
Data collection setting. If no available model provider meets the requirement, your request will return an error.
- allow: (default) allow providers which store user data non-transiently and may train on it
- deny: use only providers which do not collect user data.
- deny: use only providers which do not collect user data.
## Values
+15
View File
@@ -0,0 +1,15 @@
# DefaultParameters
Default parameters for this model
## Fields
| Field | Type | Required | Description |
| ------------------------- | ------------------------- | ------------------------- | ------------------------- |
| `temperature` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
| `top_p` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
| `top_k` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A |
| `frequency_penalty` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
| `presence_penalty` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
| `repetition_penalty` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
@@ -0,0 +1,12 @@
# EdgeNetworkTimeoutResponseErrorData
Error data for EdgeNetworkTimeoutResponse
## Fields
| Field | Type | Required | Description |
| -------------------------- | -------------------------- | -------------------------- | -------------------------- |
| `code` | *int* | :heavy_check_mark: | N/A |
| `message` | *str* | :heavy_check_mark: | N/A |
| `metadata` | Dict[str, *Nullable[Any]*] | :heavy_minus_sign: | N/A |
@@ -1,13 +1,15 @@
# ChatStreamCompletionCreateParamsReasoningEffort
# Effort
Reasoning effort
Constrains effort on reasoning for reasoning models
## Values
| Name | Value |
| --------- | --------- |
| `XHIGH` | xhigh |
| `HIGH` | high |
| `MEDIUM` | medium |
| `LOW` | low |
| `MINIMAL` | minimal |
| `MINIMAL` | minimal |
| `NONE` | none |
+13
View File
@@ -0,0 +1,13 @@
# EndpointStatus
## Values
| Name | Value |
| ---------- | ---------- |
| `ZERO` | 0 |
| `MINUS_1` | -1 |
| `MINUS_2` | -2 |
| `MINUS_3` | -3 |
| `MINUS_5` | -5 |
| `MINUS_10` | -10 |
+11
View File
@@ -0,0 +1,11 @@
# Error
Error information
## Fields
| Field | Type | Required | Description | Example |
| ------------------- | ------------------- | ------------------- | ------------------- | ------------------- |
| `message` | *str* | :heavy_check_mark: | Error message | Rate limit exceeded |
| `code` | *float* | :heavy_check_mark: | Error code | 429 |
+11
View File
@@ -0,0 +1,11 @@
# FileCitation
## Fields
| Field | Type | Required | Description |
| ---------------------------------------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------- |
| `type` | [components.FileCitationType](../components/filecitationtype.md) | :heavy_check_mark: | N/A |
| `file_id` | *str* | :heavy_check_mark: | N/A |
| `filename` | *str* | :heavy_check_mark: | N/A |
| `index` | *float* | :heavy_check_mark: | N/A |
+8
View File
@@ -0,0 +1,8 @@
# FileCitationType
## Values
| Name | Value |
| --------------- | --------------- |
| `FILE_CITATION` | file_citation |
+10
View File
@@ -0,0 +1,10 @@
# FilePath
## Fields
| Field | Type | Required | Description |
| -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- |
| `type` | [components.FilePathType](../components/filepathtype.md) | :heavy_check_mark: | N/A |
| `file_id` | *str* | :heavy_check_mark: | N/A |
| `index` | *float* | :heavy_check_mark: | N/A |
@@ -1,8 +1,8 @@
# ChatCompletionContentPartImageType
# FilePathType
## Values
| Name | Value |
| ----------- | ----------- |
| `IMAGE_URL` | image_url |
| `FILE_PATH` | file_path |
@@ -0,0 +1,12 @@
# ForbiddenResponseErrorData
Error data for ForbiddenResponse
## Fields
| Field | Type | Required | Description |
| -------------------------- | -------------------------- | -------------------------- | -------------------------- |
| `code` | *int* | :heavy_check_mark: | N/A |
| `message` | *str* | :heavy_check_mark: | N/A |
| `metadata` | Dict[str, *Nullable[Any]*] | :heavy_minus_sign: | N/A |
+11
View File
@@ -0,0 +1,11 @@
# ImageGenerationStatus
## Values
| Name | Value |
| ------------- | ------------- |
| `IN_PROGRESS` | in_progress |
| `COMPLETED` | completed |
| `GENERATING` | generating |
| `FAILED` | failed |
+12
View File
@@ -0,0 +1,12 @@
# InputModality
## Values
| Name | Value |
| ------- | ------- |
| `TEXT` | text |
| `IMAGE` | image |
| `FILE` | file |
| `AUDIO` | audio |
| `VIDEO` | video |
+8
View File
@@ -0,0 +1,8 @@
# InputTokensDetails
## Fields
| Field | Type | Required | Description |
| ------------------ | ------------------ | ------------------ | ------------------ |
| `cached_tokens` | *float* | :heavy_check_mark: | N/A |
+31
View File
@@ -0,0 +1,31 @@
# InstructType
Instruction format type
## Values
| Name | Value |
| --------------- | --------------- |
| `NONE` | none |
| `AIROBOROS` | airoboros |
| `ALPACA` | alpaca |
| `ALPACA_MODIF` | alpaca-modif |
| `CHATML` | chatml |
| `CLAUDE` | claude |
| `CODE_LLAMA` | code-llama |
| `GEMMA` | gemma |
| `LLAMA2` | llama2 |
| `LLAMA3` | llama3 |
| `MISTRAL` | mistral |
| `NEMOTRON` | nemotron |
| `NEURAL` | neural |
| `OPENCHAT` | openchat |
| `PHI3` | phi3 |
| `RWKV` | rwkv |
| `VICUNA` | vicuna |
| `ZEPHYR` | zephyr |
| `DEEPSEEK_R1` | deepseek-r1 |
| `DEEPSEEK_V3_1` | deepseek-v3.1 |
| `QWQ` | qwq |
| `QWEN3` | qwen3 |
@@ -0,0 +1,12 @@
# InternalServerResponseErrorData
Error data for InternalServerResponse
## Fields
| Field | Type | Required | Description |
| -------------------------- | -------------------------- | -------------------------- | -------------------------- |
| `code` | *int* | :heavy_check_mark: | N/A |
| `message` | *str* | :heavy_check_mark: | N/A |
| `metadata` | Dict[str, *Nullable[Any]*] | :heavy_minus_sign: | N/A |
+15
View File
@@ -0,0 +1,15 @@
# ListEndpointsResponse
List of available endpoints for a model
## Fields
| Field | Type | Required | Description | Example |
| ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id` | *str* | :heavy_check_mark: | Unique identifier for the model | openai/gpt-4 |
| `name` | *str* | :heavy_check_mark: | Display name of the model | GPT-4 |
| `created` | *float* | :heavy_check_mark: | Unix timestamp of when the model was created | 1692901234 |
| `description` | *str* | :heavy_check_mark: | Description of the model | GPT-4 is a large multimodal model that can solve difficult problems with greater accuracy. |
| `architecture` | [components.Architecture](../components/architecture.md) | :heavy_check_mark: | N/A | {<br/>"tokenizer": "GPT",<br/>"instruct_type": "chatml",<br/>"modality": "text-\u003etext",<br/>"input_modalities": [<br/>"text"<br/>],<br/>"output_modalities": [<br/>"text"<br/>]<br/>} |
| `endpoints` | List[[components.PublicEndpoint](../components/publicendpoint.md)] | :heavy_check_mark: | List of available endpoints for this model | |
+10
View File
@@ -0,0 +1,10 @@
# Modality
## Values
| Name | Value |
| ------- | ------- |
| `TEXT` | text |
| `IMAGE` | image |
| `AUDIO` | audio |
+24
View File
@@ -0,0 +1,24 @@
# Model
Information about an AI model available on OpenRouter
## Fields
| Field | Type | Required | Description | Example |
| ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id` | *str* | :heavy_check_mark: | Unique identifier for the model | openai/gpt-4 |
| `canonical_slug` | *str* | :heavy_check_mark: | Canonical slug for the model | openai/gpt-4 |
| `hugging_face_id` | *OptionalNullable[str]* | :heavy_minus_sign: | Hugging Face model identifier, if applicable | microsoft/DialoGPT-medium |
| `name` | *str* | :heavy_check_mark: | Display name of the model | GPT-4 |
| `created` | *float* | :heavy_check_mark: | Unix timestamp of when the model was created | 1692901234 |
| `description` | *Optional[str]* | :heavy_minus_sign: | Description of the model | GPT-4 is a large multimodal model that can solve difficult problems with greater accuracy. |
| `pricing` | [components.PublicPricing](../components/publicpricing.md) | :heavy_check_mark: | Pricing information for the model | {<br/>"prompt": "0.00003",<br/>"completion": "0.00006",<br/>"request": "0",<br/>"image": "0"<br/>} |
| `context_length` | *Nullable[float]* | :heavy_check_mark: | Maximum context length in tokens | 8192 |
| `architecture` | [components.ModelArchitecture](../components/modelarchitecture.md) | :heavy_check_mark: | Model architecture information | {<br/>"tokenizer": "GPT",<br/>"instruct_type": "chatml",<br/>"modality": "text-\u003etext",<br/>"input_modalities": [<br/>"text"<br/>],<br/>"output_modalities": [<br/>"text"<br/>]<br/>} |
| `top_provider` | [components.TopProviderInfo](../components/topproviderinfo.md) | :heavy_check_mark: | Information about the top provider for this model | {<br/>"context_length": 8192,<br/>"max_completion_tokens": 4096,<br/>"is_moderated": true<br/>} |
| `per_request_limits` | [Nullable[components.PerRequestLimits]](../components/perrequestlimits.md) | :heavy_check_mark: | Per-request token limits | {<br/>"prompt_tokens": 1000,<br/>"completion_tokens": 1000<br/>} |
| `supported_parameters` | List[[components.Parameter](../components/parameter.md)] | :heavy_check_mark: | List of supported parameters for this model | |
| `default_parameters` | [Nullable[components.DefaultParameters]](../components/defaultparameters.md) | :heavy_check_mark: | Default parameters for this model | {<br/>"temperature": 0.7,<br/>"top_p": 0.9,<br/>"top_k": 0,<br/>"frequency_penalty": 0,<br/>"presence_penalty": 0,<br/>"repetition_penalty": 1<br/>} |
| `knowledge_cutoff` | *OptionalNullable[str]* | :heavy_minus_sign: | The date up to which the model was trained on data. ISO 8601 date string (YYYY-MM-DD) or null if unknown. | 2024-10-01 |
| `expiration_date` | *OptionalNullable[str]* | :heavy_minus_sign: | The date after which the model may be removed. ISO 8601 date string (YYYY-MM-DD) or null if no expiration. | 2025-06-01 |
+14
View File
@@ -0,0 +1,14 @@
# ModelArchitecture
Model architecture information
## Fields
| Field | Type | Required | Description | Example |
| ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ |
| `tokenizer` | [Optional[components.ModelGroup]](../components/modelgroup.md) | :heavy_minus_sign: | Tokenizer type used by the model | GPT |
| `instruct_type` | [OptionalNullable[components.ModelArchitectureInstructType]](../components/modelarchitectureinstructtype.md) | :heavy_minus_sign: | Instruction format type | chatml |
| `modality` | *Nullable[str]* | :heavy_check_mark: | Primary modality of the model | text->text |
| `input_modalities` | List[[components.InputModality](../components/inputmodality.md)] | :heavy_check_mark: | Supported input modalities | |
| `output_modalities` | List[[components.OutputModality](../components/outputmodality.md)] | :heavy_check_mark: | Supported output modalities | |
@@ -0,0 +1,31 @@
# ModelArchitectureInstructType
Instruction format type
## Values
| Name | Value |
| --------------- | --------------- |
| `NONE` | none |
| `AIROBOROS` | airoboros |
| `ALPACA` | alpaca |
| `ALPACA_MODIF` | alpaca-modif |
| `CHATML` | chatml |
| `CLAUDE` | claude |
| `CODE_LLAMA` | code-llama |
| `GEMMA` | gemma |
| `LLAMA2` | llama2 |
| `LLAMA3` | llama3 |
| `MISTRAL` | mistral |
| `NEMOTRON` | nemotron |
| `NEURAL` | neural |
| `OPENCHAT` | openchat |
| `PHI3` | phi3 |
| `RWKV` | rwkv |
| `VICUNA` | vicuna |
| `ZEPHYR` | zephyr |
| `DEEPSEEK_R1` | deepseek-r1 |
| `DEEPSEEK_V3_1` | deepseek-v3.1 |
| `QWQ` | qwq |
| `QWEN3` | qwen3 |
+28
View File
@@ -0,0 +1,28 @@
# ModelGroup
Tokenizer type used by the model
## Values
| Name | Value |
| ----------- | ----------- |
| `ROUTER` | Router |
| `MEDIA` | Media |
| `OTHER` | Other |
| `GPT` | GPT |
| `CLAUDE` | Claude |
| `GEMINI` | Gemini |
| `GROK` | Grok |
| `COHERE` | Cohere |
| `NOVA` | Nova |
| `QWEN` | Qwen |
| `YI` | Yi |
| `DEEP_SEEK` | DeepSeek |
| `MISTRAL` | Mistral |
| `LLAMA2` | Llama2 |
| `LLAMA3` | Llama3 |
| `LLAMA4` | Llama4 |
| `PA_LM` | PaLM |
| `RWKV` | RWKV |
| `QWEN3` | Qwen3 |
+10
View File
@@ -0,0 +1,10 @@
# ModelsCountResponse
Model count data
## Fields
| Field | Type | Required | Description | Example |
| ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | ---------------------------------------- |
| `data` | [components.Data](../components/data.md) | :heavy_check_mark: | Model count data | {<br/>"count": 150<br/>} |
+10
View File
@@ -0,0 +1,10 @@
# ModelsListResponse
List of available models
## Fields
| Field | Type | Required | Description |
| ------------------------------------------------ | ------------------------------------------------ | ------------------------------------------------ | ------------------------------------------------ |
| `data` | List[[components.Model](../components/model.md)] | :heavy_check_mark: | List of available models |
@@ -0,0 +1,12 @@
# NotFoundResponseErrorData
Error data for NotFoundResponse
## Fields
| Field | Type | Required | Description |
| -------------------------- | -------------------------- | -------------------------- | -------------------------- |
| `code` | *int* | :heavy_check_mark: | N/A |
| `message` | *str* | :heavy_check_mark: | N/A |
| `metadata` | Dict[str, *Nullable[Any]*] | :heavy_minus_sign: | N/A |
@@ -0,0 +1,23 @@
# OpenAIResponsesAnnotation
## Supported Types
### `components.FileCitation`
```python
value: components.FileCitation = /* values here */
```
### `components.URLCitation`
```python
value: components.URLCitation = /* values here */
```
### `components.FilePath`
```python
value: components.FilePath = /* values here */
```
@@ -1,11 +1,9 @@
# ChatCompletionCreateParamsResponseFormatGrammar
Custom grammar response format
# OpenAIResponsesRefusalContent
## Fields
| Field | Type | Required | Description |
| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| `type` | [models.ChatCompletionCreateParamsTypeGrammar](../models/chatcompletioncreateparamstypegrammar.md) | :heavy_check_mark: | N/A |
| `grammar` | *str* | :heavy_check_mark: | Custom grammar for text generation |
| `type` | [components.OpenAIResponsesRefusalContentType](../components/openairesponsesrefusalcontenttype.md) | :heavy_check_mark: | N/A |
| `refusal` | *str* | :heavy_check_mark: | N/A |
@@ -1,8 +1,8 @@
# ChatCompletionCreateParamsTypeGrammar
# OpenAIResponsesRefusalContentType
## Values
| Name | Value |
| --------- | --------- |
| `GRAMMAR` | grammar |
| `REFUSAL` | refusal |
@@ -0,0 +1,13 @@
# OpenAIResponsesResponseStatus
## Values
| Name | Value |
| ------------- | ------------- |
| `COMPLETED` | completed |
| `INCOMPLETE` | incomplete |
| `IN_PROGRESS` | in_progress |
| `FAILED` | failed |
| `CANCELLED` | cancelled |
| `QUEUED` | queued |
@@ -0,0 +1,8 @@
# OpenAIResponsesToolChoice
## Fields
| Field | Type | Required | Description |
| ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | ---------------------------------------- |
| `type` | [components.Type](../components/type.md) | :heavy_check_mark: | N/A |
@@ -1,4 +1,4 @@
# ChatCompletionToolChoiceOptionAuto
# OpenAIResponsesToolChoiceAuto
## Values
@@ -0,0 +1,9 @@
# OpenAIResponsesToolChoiceFunction
## Fields
| Field | Type | Required | Description |
| ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `type` | [components.OpenAIResponsesToolChoiceTypeFunction](../components/openairesponsestoolchoicetypefunction.md) | :heavy_check_mark: | N/A |
| `name` | *str* | :heavy_check_mark: | N/A |
@@ -1,4 +1,4 @@
# ChatCompletionToolChoiceOptionNone
# OpenAIResponsesToolChoiceNone
## Values
@@ -1,4 +1,4 @@
# ChatCompletionToolChoiceOptionRequired
# OpenAIResponsesToolChoiceRequired
## Values
@@ -1,4 +1,4 @@
# ChatCompletionMessageToolCallType
# OpenAIResponsesToolChoiceTypeFunction
## Values
@@ -0,0 +1,8 @@
# OpenAIResponsesToolChoiceTypeWebSearchPreview
## Values
| Name | Value |
| -------------------- | -------------------- |
| `WEB_SEARCH_PREVIEW` | web_search_preview |
@@ -0,0 +1,8 @@
# OpenAIResponsesToolChoiceTypeWebSearchPreview20250311
## Values
| Name | Value |
| ------------------------------- | ------------------------------- |
| `WEB_SEARCH_PREVIEW_2025_03_11` | web_search_preview_2025_03_11 |
@@ -0,0 +1,35 @@
# OpenAIResponsesToolChoiceUnion
## Supported Types
### `components.OpenAIResponsesToolChoiceAuto`
```python
value: components.OpenAIResponsesToolChoiceAuto = /* values here */
```
### `components.OpenAIResponsesToolChoiceNone`
```python
value: components.OpenAIResponsesToolChoiceNone = /* values here */
```
### `components.OpenAIResponsesToolChoiceRequired`
```python
value: components.OpenAIResponsesToolChoiceRequired = /* values here */
```
### `components.OpenAIResponsesToolChoiceFunction`
```python
value: components.OpenAIResponsesToolChoiceFunction = /* values here */
```
### `components.OpenAIResponsesToolChoice`
```python
value: components.OpenAIResponsesToolChoice = /* values here */
```
@@ -0,0 +1,9 @@
# OpenAIResponsesTruncation
## Values
| Name | Value |
| ---------- | ---------- |
| `AUTO` | auto |
| `DISABLED` | disabled |
@@ -1,14 +1,11 @@
# ReasoningDetailSummary
Reasoning summary detail
# OutputItemImageGenerationCall
## Fields
| Field | Type | Required | Description |
| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| `type` | [models.ReasoningDetailSummaryType](../models/reasoningdetailsummarytype.md) | :heavy_check_mark: | N/A |
| `summary` | *str* | :heavy_check_mark: | N/A |
| `id` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A |
| `format_` | [OptionalNullable[models.ReasoningDetailSummaryFormat]](../models/reasoningdetailsummaryformat.md) | :heavy_minus_sign: | N/A |
| `index` | *Optional[float]* | :heavy_minus_sign: | N/A |
| Field | Type | Required | Description | Example |
| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| `type` | [components.OutputItemImageGenerationCallType](../components/outputitemimagegenerationcalltype.md) | :heavy_check_mark: | N/A | |
| `id` | *str* | :heavy_check_mark: | N/A | |
| `result` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A | |
| `status` | [components.ImageGenerationStatus](../components/imagegenerationstatus.md) | :heavy_check_mark: | N/A | completed |
@@ -1,8 +1,8 @@
# ChatCompletionChunkObject
# OutputItemImageGenerationCallType
## Values
| Name | Value |
| ----------------------- | ----------------------- |
| `CHAT_COMPLETION_CHUNK` | chat.completion.chunk |
| `IMAGE_GENERATION_CALL` | image_generation_call |
+13
View File
@@ -0,0 +1,13 @@
# OutputMessage
## Fields
| Field | Type | Required | Description |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id` | *str* | :heavy_check_mark: | N/A |
| `role` | [components.OutputMessageRole](../components/outputmessagerole.md) | :heavy_check_mark: | N/A |
| `type` | [components.OutputMessageType](../components/outputmessagetype.md) | :heavy_check_mark: | N/A |
| `status` | [Optional[components.OutputMessageStatusUnion]](../components/outputmessagestatusunion.md) | :heavy_minus_sign: | N/A |
| `content` | List[[components.OutputMessageContent](../components/outputmessagecontent.md)] | :heavy_check_mark: | N/A |
| `phase` | [OptionalNullable[components.OutputMessagePhaseUnion]](../components/outputmessagephaseunion.md) | :heavy_minus_sign: | The phase of an assistant message. Use `commentary` for an intermediate assistant message and `final_answer` for the final assistant message. For follow-up requests with models like `gpt-5.3-codex` and later, preserve and resend phase on all assistant messages. Omitting it can degrade performance. Not used for user messages. |
+17
View File
@@ -0,0 +1,17 @@
# OutputMessageContent
## Supported Types
### `components.ResponseOutputText`
```python
value: components.ResponseOutputText = /* values here */
```
### `components.OpenAIResponsesRefusalContent`
```python
value: components.OpenAIResponsesRefusalContent = /* values here */
```
@@ -1,4 +1,4 @@
# ChatCompletionMessageRole
# OutputMessageRole
## Values
@@ -1,8 +1,8 @@
# ChatCompletionAssistantMessageParamRole
# OutputMessageStatusCompleted
## Values
| Name | Value |
| ----------- | ----------- |
| `ASSISTANT` | assistant |
| `COMPLETED` | completed |
@@ -1,8 +1,8 @@
# ChatCompletionCreateParamsIDModeration
# OutputMessageStatusIncomplete
## Values
| Name | Value |
| ------------ | ------------ |
| `MODERATION` | moderation |
| `INCOMPLETE` | incomplete |
@@ -1,8 +1,8 @@
# ChatCompletionContentPartAudioType
# OutputMessageStatusInProgress
## Values
| Name | Value |
| ------------- | ------------- |
| `INPUT_AUDIO` | input_audio |
| `IN_PROGRESS` | in_progress |
@@ -0,0 +1,23 @@
# OutputMessageStatusUnion
## Supported Types
### `components.OutputMessageStatusCompleted`
```python
value: components.OutputMessageStatusCompleted = /* values here */
```
### `components.OutputMessageStatusIncomplete`
```python
value: components.OutputMessageStatusIncomplete = /* values here */
```
### `components.OutputMessageStatusInProgress`
```python
value: components.OutputMessageStatusInProgress = /* values here */
```
+8
View File
@@ -0,0 +1,8 @@
# OutputMessageType
## Values
| Name | Value |
| --------- | --------- |
| `MESSAGE` | message |
+12
View File
@@ -0,0 +1,12 @@
# OutputModality
## Values
| Name | Value |
| ------------ | ------------ |
| `TEXT` | text |
| `IMAGE` | image |
| `EMBEDDINGS` | embeddings |
| `AUDIO` | audio |
| `VIDEO` | video |
+8
View File
@@ -0,0 +1,8 @@
# OutputTokensDetails
## Fields
| Field | Type | Required | Description |
| ------------------ | ------------------ | ------------------ | ------------------ |
| `reasoning_tokens` | *float* | :heavy_check_mark: | N/A |
+31
View File
@@ -0,0 +1,31 @@
# Parameter
## Values
| Name | Value |
| --------------------- | --------------------- |
| `TEMPERATURE` | temperature |
| `TOP_P` | top_p |
| `TOP_K` | top_k |
| `MIN_P` | min_p |
| `TOP_A` | top_a |
| `FREQUENCY_PENALTY` | frequency_penalty |
| `PRESENCE_PENALTY` | presence_penalty |
| `REPETITION_PENALTY` | repetition_penalty |
| `MAX_TOKENS` | max_tokens |
| `LOGIT_BIAS` | logit_bias |
| `LOGPROBS` | logprobs |
| `TOP_LOGPROBS` | top_logprobs |
| `SEED` | seed |
| `RESPONSE_FORMAT` | response_format |
| `STRUCTURED_OUTPUTS` | structured_outputs |
| `STOP` | stop |
| `TOOLS` | tools |
| `TOOL_CHOICE` | tool_choice |
| `PARALLEL_TOOL_CALLS` | parallel_tool_calls |
| `INCLUDE_REASONING` | include_reasoning |
| `REASONING` | reasoning |
| `REASONING_EFFORT` | reasoning_effort |
| `WEB_SEARCH_OPTIONS` | web_search_options |
| `VERBOSITY` | verbosity |
+11
View File
@@ -0,0 +1,11 @@
# Partition
Partitioning strategy for sorting: "model" (default) groups endpoints by model before sorting (fallback models remain fallbacks), "none" sorts all endpoints together regardless of model.
## Values
| Name | Value |
| ------- | ------- |
| `MODEL` | model |
| `NONE` | none |
@@ -0,0 +1,12 @@
# PayloadTooLargeResponseErrorData
Error data for PayloadTooLargeResponse
## Fields
| Field | Type | Required | Description |
| -------------------------- | -------------------------- | -------------------------- | -------------------------- |
| `code` | *int* | :heavy_check_mark: | N/A |
| `message` | *str* | :heavy_check_mark: | N/A |
| `metadata` | Dict[str, *Nullable[Any]*] | :heavy_minus_sign: | N/A |
@@ -0,0 +1,12 @@
# PaymentRequiredResponseErrorData
Error data for PaymentRequiredResponse
## Fields
| Field | Type | Required | Description |
| -------------------------- | -------------------------- | -------------------------- | -------------------------- |
| `code` | *int* | :heavy_check_mark: | N/A |
| `message` | *str* | :heavy_check_mark: | N/A |
| `metadata` | Dict[str, *Nullable[Any]*] | :heavy_minus_sign: | N/A |
+19
View File
@@ -0,0 +1,19 @@
# PDFParserEngine
The engine to use for parsing PDF files. "pdf-text" is deprecated and automatically redirected to "cloudflare-ai".
## Supported Types
### `components.PDFParserEngineEnum`
```python
value: components.PDFParserEngineEnum = /* values here */
```
### `components.PDFParserEnginePDFText`
```python
value: components.PDFParserEnginePDFText = /* values here */
```
+10
View File
@@ -0,0 +1,10 @@
# PDFParserOptions
Options for PDF parsing.
## Fields
| Field | Type | Required | Description |
| ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
| `engine` | [Optional[components.PDFParserEngine]](../components/pdfparserengine.md) | :heavy_minus_sign: | The engine to use for parsing PDF files. "pdf-text" is deprecated and automatically redirected to "cloudflare-ai". |
@@ -0,0 +1,13 @@
# PercentileLatencyCutoffs
Percentile-based latency cutoffs. All specified cutoffs must be met for an endpoint to be preferred.
## Fields
| Field | Type | Required | Description |
| ----------------------------- | ----------------------------- | ----------------------------- | ----------------------------- |
| `p50` | *OptionalNullable[float]* | :heavy_minus_sign: | Maximum p50 latency (seconds) |
| `p75` | *OptionalNullable[float]* | :heavy_minus_sign: | Maximum p75 latency (seconds) |
| `p90` | *OptionalNullable[float]* | :heavy_minus_sign: | Maximum p90 latency (seconds) |
| `p99` | *OptionalNullable[float]* | :heavy_minus_sign: | Maximum p99 latency (seconds) |
+13
View File
@@ -0,0 +1,13 @@
# PercentileStats
Latency percentiles in milliseconds over the last 30 minutes. Latency measures time to first token. Only visible when authenticated with an API key or cookie; returns null for unauthenticated requests.
## Fields
| Field | Type | Required | Description | Example |
| ------------------------ | ------------------------ | ------------------------ | ------------------------ | ------------------------ |
| `p50` | *float* | :heavy_check_mark: | Median (50th percentile) | 25.5 |
| `p75` | *float* | :heavy_check_mark: | 75th percentile | 35.2 |
| `p90` | *float* | :heavy_check_mark: | 90th percentile | 48.7 |
| `p99` | *float* | :heavy_check_mark: | 99th percentile | 85.3 |
@@ -0,0 +1,13 @@
# PercentileThroughputCutoffs
Percentile-based throughput cutoffs. All specified cutoffs must be met for an endpoint to be preferred.
## Fields
| Field | Type | Required | Description |
| ----------------------------------- | ----------------------------------- | ----------------------------------- | ----------------------------------- |
| `p50` | *OptionalNullable[float]* | :heavy_minus_sign: | Minimum p50 throughput (tokens/sec) |
| `p75` | *OptionalNullable[float]* | :heavy_minus_sign: | Minimum p75 throughput (tokens/sec) |
| `p90` | *OptionalNullable[float]* | :heavy_minus_sign: | Minimum p90 throughput (tokens/sec) |
| `p99` | *OptionalNullable[float]* | :heavy_minus_sign: | Minimum p99 throughput (tokens/sec) |
+11
View File
@@ -0,0 +1,11 @@
# PerRequestLimits
Per-request token limits
## Fields
| Field | Type | Required | Description | Example |
| ------------------------------------- | ------------------------------------- | ------------------------------------- | ------------------------------------- | ------------------------------------- |
| `prompt_tokens` | *float* | :heavy_check_mark: | Maximum prompt tokens per request | 1000 |
| `completion_tokens` | *float* | :heavy_check_mark: | Maximum completion tokens per request | 1000 |
+25
View File
@@ -0,0 +1,25 @@
# PreferredMaxLatency
Preferred maximum latency (in seconds). Can be a number (applies to p50) or an object with percentile-specific cutoffs. Endpoints above the threshold(s) may still be used, but are deprioritized in routing. When using fallback models, this may cause a fallback model to be used instead of the primary model if it meets the threshold.
## Supported Types
### `float`
```python
value: float = /* values here */
```
### `components.PercentileLatencyCutoffs`
```python
value: components.PercentileLatencyCutoffs = /* values here */
```
### `Any`
```python
value: Any = /* values here */
```

Some files were not shown because too many files have changed in this diff Show More