mirror of
https://github.com/wassname/openrouter-python-sdk-retry-errors.git
synced 2026-07-31 12:30:30 +08:00
Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94ba44c933 | ||
|
|
d13e797ad1 | ||
|
|
3629471122 | ||
|
|
c702382b4b | ||
|
|
599fd1454c | ||
|
|
a0b2566851 | ||
|
|
71ab77e5e8 | ||
|
|
05f81a553c | ||
|
|
dede1d21ec | ||
|
|
43cf059ae0 | ||
|
|
5fc522c72f |
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"permissions": {
|
||||||
|
"allow": [
|
||||||
|
"Bash(python3:*)"
|
||||||
|
],
|
||||||
|
"deny": [],
|
||||||
|
"ask": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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!**
|
> **Remember to shutdown a GitHub Codespace when it is not in use!**
|
||||||
|
|
||||||
# Dev Containers Quick Start
|
# Dev Containers Quick Start
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
pylintrc
|
||||||
@@ -30,4 +30,5 @@ jobs:
|
|||||||
set_version: ${{ github.event.inputs.set_version }}
|
set_version: ${{ github.event.inputs.set_version }}
|
||||||
secrets:
|
secrets:
|
||||||
github_access_token: ${{ secrets.GITHUB_TOKEN }}
|
github_access_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
pypi_token: ${{ secrets.PYPI_TOKEN }}
|
||||||
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
|
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
name: Speakeasy Tagging
|
name: Publish
|
||||||
permissions:
|
permissions:
|
||||||
checks: write
|
checks: write
|
||||||
contents: write
|
contents: write
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
statuses: write
|
statuses: write
|
||||||
|
id-token: write
|
||||||
"on":
|
"on":
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
paths:
|
||||||
|
- .speakeasy/gen.lock
|
||||||
workflow_dispatch: {}
|
workflow_dispatch: {}
|
||||||
jobs:
|
jobs:
|
||||||
tag:
|
publish:
|
||||||
uses: speakeasy-api/sdk-generation-action/.github/workflows/tag.yaml@v15
|
uses: speakeasy-api/sdk-generation-action/.github/workflows/sdk-publish.yaml@v15
|
||||||
with:
|
with:
|
||||||
registry_tags: main
|
target: open-router
|
||||||
secrets:
|
secrets:
|
||||||
github_access_token: ${{ secrets.GITHUB_TOKEN }}
|
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 }}
|
||||||
@@ -10,3 +10,4 @@ pyrightconfig.json
|
|||||||
**/.speakeasy/logs/
|
**/.speakeasy/logs/
|
||||||
.speakeasy/reports
|
.speakeasy/reports
|
||||||
.env
|
.env
|
||||||
|
.env.local
|
||||||
|
|||||||
+1019
-246
File diff suppressed because it is too large
Load Diff
+16
-6
@@ -19,29 +19,37 @@ generation:
|
|||||||
auth:
|
auth:
|
||||||
oAuth2ClientCredentialsEnabled: true
|
oAuth2ClientCredentialsEnabled: true
|
||||||
oAuth2PasswordEnabled: true
|
oAuth2PasswordEnabled: true
|
||||||
|
hoistGlobalSecurity: true
|
||||||
|
inferSSEOverload: true
|
||||||
sdkHooksConfigAccess: true
|
sdkHooksConfigAccess: true
|
||||||
|
schemas:
|
||||||
|
allOfMergeStrategy: shallowMerge
|
||||||
|
requestBodyFieldName: body
|
||||||
tests:
|
tests:
|
||||||
generateTests: false
|
generateTests: false
|
||||||
generateNewTests: true
|
generateNewTests: true
|
||||||
skipResponseBodyAssertions: false
|
skipResponseBodyAssertions: false
|
||||||
python:
|
python:
|
||||||
version: 0.5.2
|
version: 0.0.14
|
||||||
additionalDependencies:
|
additionalDependencies:
|
||||||
dev: {}
|
dev: {}
|
||||||
main: {}
|
main: {}
|
||||||
allowedRedefinedBuiltins:
|
allowedRedefinedBuiltins:
|
||||||
- id
|
- id
|
||||||
- object
|
- object
|
||||||
|
- input
|
||||||
|
asyncMode: both
|
||||||
authors:
|
authors:
|
||||||
- Speakeasy
|
- OpenRouter
|
||||||
baseErrorName: OpenRouterError
|
baseErrorName: OpenRouterError
|
||||||
clientServerStatusCodesAsErrors: true
|
clientServerStatusCodesAsErrors: true
|
||||||
defaultErrorName: OpenRouterDefaultError
|
defaultErrorName: OpenRouterDefaultError
|
||||||
description: Python Client SDK Generated by Speakeasy.
|
description: Official Python Client SDK for OpenRouter.
|
||||||
enableCustomCodeRegions: true
|
enableCustomCodeRegions: false
|
||||||
enumFormat: union
|
enumFormat: union
|
||||||
envVarPrefix: OPENROUTER
|
envVarPrefix: OPENROUTER
|
||||||
fixFlags:
|
fixFlags:
|
||||||
|
asyncPaginationSep2025: true
|
||||||
responseRequiredSep2024: true
|
responseRequiredSep2024: true
|
||||||
flattenGlobalSecurity: true
|
flattenGlobalSecurity: true
|
||||||
flattenRequests: true
|
flattenRequests: true
|
||||||
@@ -51,10 +59,11 @@ python:
|
|||||||
paths:
|
paths:
|
||||||
callbacks: ""
|
callbacks: ""
|
||||||
errors: errors
|
errors: errors
|
||||||
operations: ""
|
operations: operations
|
||||||
shared: ""
|
shared: components
|
||||||
webhooks: ""
|
webhooks: ""
|
||||||
inputModelSuffix: input
|
inputModelSuffix: input
|
||||||
|
legacyPyright: false
|
||||||
maxMethodParams: 999
|
maxMethodParams: 999
|
||||||
methodArguments: infer-optional-args
|
methodArguments: infer-optional-args
|
||||||
moduleName: ""
|
moduleName: ""
|
||||||
@@ -64,4 +73,5 @@ python:
|
|||||||
pytestFilterWarnings: []
|
pytestFilterWarnings: []
|
||||||
pytestTimeout: 0
|
pytestTimeout: 0
|
||||||
responseFormat: flat
|
responseFormat: flat
|
||||||
|
sseFlatResponse: true
|
||||||
templateVersion: v2
|
templateVersion: v2
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+8347
-1588
File diff suppressed because it is too large
Load Diff
+15
-14
@@ -1,36 +1,37 @@
|
|||||||
speakeasyVersion: 1.611.1
|
speakeasyVersion: 1.656.2
|
||||||
sources:
|
sources:
|
||||||
OpenRouter Chat Completions API:
|
-OAS:
|
||||||
sourceNamespace: open-router-chat-completions-api
|
sourceNamespace: open-router-chat-completions-api
|
||||||
sourceRevisionDigest: sha256:30b19a8759608792fb4d27f6bf28d5982d7e2a8cf5b3faf34ba3507a62f9f106
|
sourceRevisionDigest: sha256:08647b466c00989914e3a2436175152270f771f0a57d055f5bab14cc2d4be89e
|
||||||
sourceBlobDigest: sha256:454f1b880a0882a70f78eacccb2c33e3d9d19134a0738b0e21487984a7bf2e63
|
sourceBlobDigest: sha256:53027ec57392d9617cc001ece83c2fe1aa6e5dbfd52d170381c34c33c6042c23
|
||||||
tags:
|
tags:
|
||||||
- latest
|
- latest
|
||||||
- speakeasy-sdk-regen-1755878373
|
|
||||||
- 1.0.0
|
|
||||||
targets:
|
targets:
|
||||||
open-router:
|
open-router:
|
||||||
source: OpenRouter Chat Completions API
|
source: -OAS
|
||||||
sourceNamespace: open-router-chat-completions-api
|
sourceNamespace: open-router-chat-completions-api
|
||||||
sourceRevisionDigest: sha256:30b19a8759608792fb4d27f6bf28d5982d7e2a8cf5b3faf34ba3507a62f9f106
|
sourceRevisionDigest: sha256:08647b466c00989914e3a2436175152270f771f0a57d055f5bab14cc2d4be89e
|
||||||
sourceBlobDigest: sha256:454f1b880a0882a70f78eacccb2c33e3d9d19134a0738b0e21487984a7bf2e63
|
sourceBlobDigest: sha256:53027ec57392d9617cc001ece83c2fe1aa6e5dbfd52d170381c34c33c6042c23
|
||||||
workflow:
|
workflow:
|
||||||
workflowVersion: 1.0.0
|
workflowVersion: 1.0.0
|
||||||
speakeasyVersion: latest
|
speakeasyVersion: latest
|
||||||
sources:
|
sources:
|
||||||
OpenRouter Chat Completions API:
|
-OAS:
|
||||||
inputs:
|
inputs:
|
||||||
- location: .speakeasy/in.openapi.yaml
|
- location: registry.speakeasyapi.dev/openrouter/sdk/open-router-chat-completions-api:main
|
||||||
output: .speakeasy/out.openapi.yaml
|
output: .speakeasy/out.openapi.yaml
|
||||||
registry:
|
registry:
|
||||||
location: registry.speakeasyapi.dev/sheldon-vaughn-test/sandbox/open-router-chat-completions-api
|
location: registry.speakeasyapi.dev/openrouter/sdk/-oas
|
||||||
targets:
|
targets:
|
||||||
open-router:
|
open-router:
|
||||||
target: python
|
target: python
|
||||||
source: OpenRouter Chat Completions API
|
source: -OAS
|
||||||
|
publish:
|
||||||
|
pypi:
|
||||||
|
token: $pypi_token
|
||||||
codeSamples:
|
codeSamples:
|
||||||
registry:
|
registry:
|
||||||
location: registry.speakeasyapi.dev/sheldon-vaughn-test/sandbox/open-router-chat-completions-api-python-code-samples
|
location: registry.speakeasyapi.dev/openrouter/sdk/-oas-python-code-samples
|
||||||
labelOverride:
|
labelOverride:
|
||||||
fixedValue: Python (SDK)
|
fixedValue: Python (SDK)
|
||||||
blocking: false
|
blocking: false
|
||||||
|
|||||||
@@ -1,19 +1,22 @@
|
|||||||
workflowVersion: 1.0.0
|
workflowVersion: 1.0.0
|
||||||
speakeasyVersion: latest
|
speakeasyVersion: latest
|
||||||
sources:
|
sources:
|
||||||
OpenRouter Chat Completions API:
|
-OAS:
|
||||||
inputs:
|
inputs:
|
||||||
- location: .speakeasy/in.openapi.yaml
|
- location: registry.speakeasyapi.dev/openrouter/sdk/open-router-chat-completions-api:main
|
||||||
output: .speakeasy/out.openapi.yaml
|
output: .speakeasy/out.openapi.yaml
|
||||||
registry:
|
registry:
|
||||||
location: registry.speakeasyapi.dev/sheldon-vaughn-test/sandbox/open-router-chat-completions-api
|
location: registry.speakeasyapi.dev/openrouter/sdk/-oas
|
||||||
targets:
|
targets:
|
||||||
open-router:
|
open-router:
|
||||||
target: python
|
target: python
|
||||||
source: OpenRouter Chat Completions API
|
source: -OAS
|
||||||
|
publish:
|
||||||
|
pypi:
|
||||||
|
token: $pypi_token
|
||||||
codeSamples:
|
codeSamples:
|
||||||
registry:
|
registry:
|
||||||
location: registry.speakeasyapi.dev/sheldon-vaughn-test/sandbox/open-router-chat-completions-api-python-code-samples
|
location: registry.speakeasyapi.dev/openrouter/sdk/-oas-python-code-samples
|
||||||
labelOverride:
|
labelOverride:
|
||||||
fixedValue: Python (SDK)
|
fixedValue: Python (SDK)
|
||||||
blocking: false
|
blocking: false
|
||||||
|
|||||||
+127
@@ -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)
|
||||||
|
```
|
||||||
-592
@@ -1,592 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<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>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- 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] -->
|
|
||||||
|
|
||||||
<!-- 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**
|
|
||||||
>
|
|
||||||
> Once a Python version reaches its [official end of life date](https://devguide.python.org/versions/), a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.
|
|
||||||
|
|
||||||
The SDK can be installed with *uv*, *pip*, or *poetry* package managers.
|
|
||||||
|
|
||||||
### uv
|
|
||||||
|
|
||||||
*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
|
|
||||||
```
|
|
||||||
|
|
||||||
### PIP
|
|
||||||
|
|
||||||
*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
|
|
||||||
```
|
|
||||||
|
|
||||||
### Poetry
|
|
||||||
|
|
||||||
*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
|
|
||||||
```
|
|
||||||
|
|
||||||
### Shell and script usage with `uv`
|
|
||||||
|
|
||||||
You can use this SDK in a Python shell with [uv](https://docs.astral.sh/uv/) and the `uvx` command that comes with it like so:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
uvx --from openrouter python
|
|
||||||
```
|
|
||||||
|
|
||||||
It's also possible to write a standalone Python script without needing to set up a whole project like so:
|
|
||||||
|
|
||||||
```python
|
|
||||||
#!/usr/bin/env -S uv run --script
|
|
||||||
# /// script
|
|
||||||
# requires-python = ">=3.9"
|
|
||||||
# dependencies = [
|
|
||||||
# "openrouter",
|
|
||||||
# ]
|
|
||||||
# ///
|
|
||||||
|
|
||||||
from openrouter import OpenRouter
|
|
||||||
|
|
||||||
sdk = OpenRouter(
|
|
||||||
# SDK arguments
|
|
||||||
)
|
|
||||||
|
|
||||||
# Rest of script here...
|
|
||||||
```
|
|
||||||
|
|
||||||
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 IDE Support [idesupport] -->
|
|
||||||
## IDE Support
|
|
||||||
|
|
||||||
### PyCharm
|
|
||||||
|
|
||||||
Generally, the SDK will work well with most IDEs out of the box. However, when using PyCharm, you can enjoy much better integration with Pydantic by installing an additional plugin.
|
|
||||||
|
|
||||||
- [PyCharm Pydantic Plugin](https://docs.pydantic.dev/latest/integrations/pycharm/)
|
|
||||||
<!-- End IDE Support [idesupport] -->
|
|
||||||
|
|
||||||
<!-- Start SDK Example Usage [usage] -->
|
|
||||||
## SDK Example Usage
|
|
||||||
|
|
||||||
### Example
|
|
||||||
|
|
||||||
```python
|
|
||||||
# Synchronous Example
|
|
||||||
from openrouter import OpenRouter
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
with OpenRouter(
|
|
||||||
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)
|
|
||||||
```
|
|
||||||
|
|
||||||
</br>
|
|
||||||
|
|
||||||
The same SDK client can also be used to make asynchronous requests by importing asyncio.
|
|
||||||
```python
|
|
||||||
# Asynchronous Example
|
|
||||||
import asyncio
|
|
||||||
from openrouter import OpenRouter
|
|
||||||
import os
|
|
||||||
|
|
||||||
async def main():
|
|
||||||
|
|
||||||
async with OpenRouter(
|
|
||||||
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=[
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"content": "Hello, how are you?",
|
|
||||||
},
|
|
||||||
], stream=False, temperature=1, top_p=1)
|
|
||||||
|
|
||||||
# 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:
|
|
||||||
# handle event
|
|
||||||
print(event, flush=True)
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
[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] -->
|
|
||||||
|
|
||||||
<!-- Start Retries [retries] -->
|
|
||||||
## Retries
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
with OpenRouter(
|
|
||||||
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,
|
|
||||||
RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))
|
|
||||||
|
|
||||||
# Handle response
|
|
||||||
print(res)
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
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] -->
|
|
||||||
|
|
||||||
<!-- Start Resource Management [resource-management] -->
|
|
||||||
## Resource Management
|
|
||||||
|
|
||||||
The `OpenRouter` class implements the context manager protocol and registers a finalizer function to close the underlying sync and async HTTPX clients it uses under the hood. This will close HTTP connections, release memory and free up other resources held by the SDK. In short-lived Python programs and notebooks that make a few SDK method calls, resource management may not be a concern. However, in longer-lived programs, it is beneficial to create a single SDK instance via a [context manager][context-manager] and reuse it across the application.
|
|
||||||
|
|
||||||
[context-manager]: https://docs.python.org/3/reference/datamodel.html#context-managers
|
|
||||||
|
|
||||||
```python
|
|
||||||
from openrouter import OpenRouter
|
|
||||||
import os
|
|
||||||
def main():
|
|
||||||
|
|
||||||
with OpenRouter(
|
|
||||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
|
||||||
) as open_router:
|
|
||||||
# Rest of application here...
|
|
||||||
|
|
||||||
|
|
||||||
# Or when using async:
|
|
||||||
async def amain():
|
|
||||||
|
|
||||||
async with OpenRouter(
|
|
||||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
|
||||||
) as open_router:
|
|
||||||
# Rest of application here...
|
|
||||||
```
|
|
||||||
<!-- End Resource Management [resource-management] -->
|
|
||||||
|
|
||||||
<!-- Start Debugging [debug] -->
|
|
||||||
## Debugging
|
|
||||||
|
|
||||||
You can setup your SDK to emit debug logs for SDK requests and responses.
|
|
||||||
|
|
||||||
You can pass your own logger class directly into your SDK.
|
|
||||||
```python
|
|
||||||
from openrouter import OpenRouter
|
|
||||||
import logging
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
|
||||||
s = OpenRouter(debug_logger=logging.getLogger("openrouter"))
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also enable a default debug logger by setting an environment variable `OPENROUTER_DEBUG` to true.
|
|
||||||
<!-- End Debugging [debug] -->
|
|
||||||
|
|
||||||
<!-- Placeholder for Future Speakeasy SDK Sections -->
|
|
||||||
|
|
||||||
# Development
|
|
||||||
|
|
||||||
## 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)
|
|
||||||
@@ -1,50 +1,18 @@
|
|||||||
|

|
||||||
|
|
||||||
|
# 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.
|
||||||
|
|
||||||
<div align="center">
|
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).
|
||||||
<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] -->
|
<!-- No Table of Contents [toc] -->
|
||||||
## 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] -->
|
|
||||||
|
|
||||||
<!-- Start SDK Installation [installation] -->
|
<!-- Start SDK Installation [installation] -->
|
||||||
## SDK 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]
|
> [!NOTE]
|
||||||
> **Python version upgrade policy**
|
> **Python version upgrade policy**
|
||||||
>
|
>
|
||||||
@@ -57,7 +25,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.
|
*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
|
```bash
|
||||||
uv add git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
|
uv add openrouter
|
||||||
```
|
```
|
||||||
|
|
||||||
### PIP
|
### PIP
|
||||||
@@ -65,7 +33,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.
|
*PIP* is the default package installer for Python, enabling easy installation and management of packages from PyPI via the command line.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
|
pip install openrouter
|
||||||
```
|
```
|
||||||
|
|
||||||
### Poetry
|
### Poetry
|
||||||
@@ -73,7 +41,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.
|
*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
|
```bash
|
||||||
poetry add git+https://github.com/speakeasy-sdks/openrouter-python-sdk.git
|
poetry add openrouter
|
||||||
```
|
```
|
||||||
|
|
||||||
### Shell and script usage with `uv`
|
### Shell and script usage with `uv`
|
||||||
@@ -108,6 +76,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.
|
`script.py` can be replaced with the actual file name.
|
||||||
<!-- End SDK Installation [installation] -->
|
<!-- 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] -->
|
<!-- Start IDE Support [idesupport] -->
|
||||||
## IDE Support
|
## IDE Support
|
||||||
|
|
||||||
@@ -118,10 +92,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/)
|
- [PyCharm Pydantic Plugin](https://docs.pydantic.dev/latest/integrations/pycharm/)
|
||||||
<!-- End IDE Support [idesupport] -->
|
<!-- End IDE Support [idesupport] -->
|
||||||
|
|
||||||
<!-- Start SDK Example Usage [usage] -->
|
<!-- No SDK Example Usage [usage] -->
|
||||||
## SDK Example Usage
|
## SDK Usage
|
||||||
|
|
||||||
### Example
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# Synchronous Example
|
# Synchronous Example
|
||||||
@@ -133,20 +105,25 @@ with OpenRouter(
|
|||||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||||
) as open_router:
|
) as open_router:
|
||||||
|
|
||||||
res = open_router.chat.complete(messages=[
|
res = open_router.chat.send(messages=[
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": "Hello, how are you?",
|
"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
|
for event in event_stream:
|
||||||
print(res)
|
# handle event
|
||||||
|
print(event, flush=True)
|
||||||
```
|
```
|
||||||
|
|
||||||
</br>
|
</br>
|
||||||
|
|
||||||
The same SDK client can also be used to make asynchronous requests by importing asyncio.
|
The same SDK client can also be used to make asynchronous requests by importing asyncio.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# Asynchronous Example
|
# Asynchronous Example
|
||||||
import asyncio
|
import asyncio
|
||||||
@@ -159,375 +136,40 @@ async def main():
|
|||||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||||
) as open_router:
|
) as open_router:
|
||||||
|
|
||||||
res = await open_router.chat.complete_async(messages=[
|
res = await open_router.chat.send_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=[
|
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": "Hello, how are you?",
|
"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
|
async for event in event_stream:
|
||||||
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:
|
|
||||||
# handle event
|
# handle event
|
||||||
print(event, flush=True)
|
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
|
<!-- No Authentication [security] -->
|
||||||
[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] -->
|
|
||||||
|
|
||||||
<!-- Start Retries [retries] -->
|
<!-- No Available Resources and Operations [operations] -->
|
||||||
## Retries
|
|
||||||
|
|
||||||
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:
|
<!-- No React hooks with TanStack Query [react-query] -->
|
||||||
```python
|
|
||||||
from openrouter import OpenRouter
|
|
||||||
from openrouter.utils import BackoffStrategy, RetryConfig
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
<!-- No Server-sent event streaming [eventstream] -->
|
||||||
|
|
||||||
with OpenRouter(
|
<!-- No Retries [retries] -->
|
||||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
|
||||||
) as open_router:
|
|
||||||
|
|
||||||
res = open_router.chat.complete(messages=[
|
<!-- No Error Handling [errors] -->
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"content": "Hello, how are you?",
|
|
||||||
},
|
|
||||||
], stream=False, temperature=1, top_p=1,
|
|
||||||
RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))
|
|
||||||
|
|
||||||
# Handle response
|
<!-- No Server Selection [server] -->
|
||||||
print(res)
|
|
||||||
|
|
||||||
```
|
<!-- No Custom HTTP Client [http-client] -->
|
||||||
|
|
||||||
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] -->
|
|
||||||
|
|
||||||
<!-- Start Resource Management [resource-management] -->
|
<!-- Start Resource Management [resource-management] -->
|
||||||
## Resource Management
|
## Resource Management
|
||||||
@@ -578,15 +220,32 @@ You can also enable a default debug logger by setting an environment variable `O
|
|||||||
|
|
||||||
# Development
|
# 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
|
## Maturity
|
||||||
|
|
||||||
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage
|
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
|
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.
|
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)
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
## 2025-08-22 15:59:18
|
|
||||||
### Changes
|
|
||||||
Based on:
|
|
||||||
- OpenAPI Doc
|
|
||||||
- Speakeasy CLI 1.606.2 (2.687.1) https://github.com/speakeasy-api/speakeasy
|
|
||||||
### Generated
|
|
||||||
- [python v0.1.3] .
|
|
||||||
@@ -9,20 +9,72 @@ with OpenRouter(
|
|||||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||||
) as open_router:
|
) as open_router:
|
||||||
|
|
||||||
res = open_router.chat.complete(messages=[
|
res = open_router.beta.responses.send(input=[
|
||||||
{
|
{
|
||||||
|
"type": "message",
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": "Hello, how are you?",
|
"content": "Hello, how are you?",
|
||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], metadata={
|
||||||
|
"user_id": "123",
|
||||||
|
"session_id": "abc-def-ghi",
|
||||||
|
}, tools=[
|
||||||
|
{
|
||||||
|
"type": "function",
|
||||||
|
"name": "get_current_weather",
|
||||||
|
"description": "Get the current weather in a given location",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"location": {
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
], model="anthropic/claude-4.5-sonnet-20250929", text={
|
||||||
|
"format_": {
|
||||||
|
"type": "text",
|
||||||
|
},
|
||||||
|
"verbosity": "medium",
|
||||||
|
}, reasoning={
|
||||||
|
"summary": "auto",
|
||||||
|
"enabled": True,
|
||||||
|
}, temperature=0.7, top_p=0.9, prompt={
|
||||||
|
"id": "<id>",
|
||||||
|
"variables": {
|
||||||
|
"key": {
|
||||||
|
"type": "input_text",
|
||||||
|
"text": "Hello, how can I help you?",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, service_tier="auto", truncation="auto", stream=False, provider={
|
||||||
|
"data_collection": "deny",
|
||||||
|
"zdr": True,
|
||||||
|
"enforce_distillable_text": True,
|
||||||
|
"order": [
|
||||||
|
"OpenAI",
|
||||||
|
],
|
||||||
|
"only": [
|
||||||
|
"OpenAI",
|
||||||
|
],
|
||||||
|
"ignore": [
|
||||||
|
"OpenAI",
|
||||||
|
],
|
||||||
|
"quantizations": None,
|
||||||
|
"sort": "price",
|
||||||
|
})
|
||||||
|
|
||||||
# Handle response
|
with res as event_stream:
|
||||||
print(res)
|
for event in event_stream:
|
||||||
|
# handle event
|
||||||
|
print(event, flush=True)
|
||||||
```
|
```
|
||||||
|
|
||||||
</br>
|
</br>
|
||||||
|
|
||||||
The same SDK client can also be used to make asynchronous requests by importing asyncio.
|
The same SDK client can also be used to make asynchronous requests by importing asyncio.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# Asynchronous Example
|
# Asynchronous Example
|
||||||
import asyncio
|
import asyncio
|
||||||
@@ -35,15 +87,66 @@ async def main():
|
|||||||
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
api_key=os.getenv("OPENROUTER_API_KEY", ""),
|
||||||
) as open_router:
|
) as open_router:
|
||||||
|
|
||||||
res = await open_router.chat.complete_async(messages=[
|
res = await open_router.beta.responses.send_async(input=[
|
||||||
{
|
{
|
||||||
|
"type": "message",
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": "Hello, how are you?",
|
"content": "Hello, how are you?",
|
||||||
},
|
},
|
||||||
], stream=False, temperature=1, top_p=1)
|
], metadata={
|
||||||
|
"user_id": "123",
|
||||||
|
"session_id": "abc-def-ghi",
|
||||||
|
}, tools=[
|
||||||
|
{
|
||||||
|
"type": "function",
|
||||||
|
"name": "get_current_weather",
|
||||||
|
"description": "Get the current weather in a given location",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"location": {
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
], model="anthropic/claude-4.5-sonnet-20250929", text={
|
||||||
|
"format_": {
|
||||||
|
"type": "text",
|
||||||
|
},
|
||||||
|
"verbosity": "medium",
|
||||||
|
}, reasoning={
|
||||||
|
"summary": "auto",
|
||||||
|
"enabled": True,
|
||||||
|
}, temperature=0.7, top_p=0.9, prompt={
|
||||||
|
"id": "<id>",
|
||||||
|
"variables": {
|
||||||
|
"key": {
|
||||||
|
"type": "input_text",
|
||||||
|
"text": "Hello, how can I help you?",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, service_tier="auto", truncation="auto", stream=False, provider={
|
||||||
|
"data_collection": "deny",
|
||||||
|
"zdr": True,
|
||||||
|
"enforce_distillable_text": True,
|
||||||
|
"order": [
|
||||||
|
"OpenAI",
|
||||||
|
],
|
||||||
|
"only": [
|
||||||
|
"OpenAI",
|
||||||
|
],
|
||||||
|
"ignore": [
|
||||||
|
"OpenAI",
|
||||||
|
],
|
||||||
|
"quantizations": None,
|
||||||
|
"sort": "price",
|
||||||
|
})
|
||||||
|
|
||||||
# Handle response
|
async with res as event_stream:
|
||||||
print(res)
|
async for event in event_stream:
|
||||||
|
# handle event
|
||||||
|
print(event, flush=True)
|
||||||
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
```
|
```
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
@@ -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 |
@@ -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 |
|
||||||
@@ -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,13 @@
|
|||||||
|
# AssistantMessage
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ |
|
||||||
|
| `role` | *Literal["assistant"]* | :heavy_check_mark: | N/A |
|
||||||
|
| `content` | [OptionalNullable[components.AssistantMessageContent]](../components/assistantmessagecontent.md) | :heavy_minus_sign: | N/A |
|
||||||
|
| `name` | *Optional[str]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `tool_calls` | List[[components.ChatMessageToolCall](../components/chatmessagetoolcall.md)] | :heavy_minus_sign: | N/A |
|
||||||
|
| `refusal` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `reasoning` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A |
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# AssistantMessageContent
|
||||||
|
|
||||||
|
|
||||||
|
## Supported Types
|
||||||
|
|
||||||
|
### `str`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: str = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
|
### `List[components.ChatMessageContentItem]`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: List[components.ChatMessageContentItem] = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
@@ -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 |
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# ChainID
|
||||||
|
|
||||||
|
|
||||||
|
## Values
|
||||||
|
|
||||||
|
| Name | Value |
|
||||||
|
| --------------------------------------------- | --------------------------------------------- |
|
||||||
|
| `ONE` | 1 |
|
||||||
|
| `ONE_HUNDRED_AND_THIRTY_SEVEN` | 137 |
|
||||||
|
| `EIGHT_THOUSAND_FOUR_HUNDRED_AND_FIFTY_THREE` | 8453 |
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
# ChatCompletionChunkChoiceFinishReason
|
# ChatCompletionFinishReason
|
||||||
|
|
||||||
|
|
||||||
## Values
|
## Values
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# ChatErrorError
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| -------------------------------------------------- | -------------------------------------------------- | -------------------------------------------------- | -------------------------------------------------- |
|
||||||
|
| `code` | [Nullable[components.Code]](../components/code.md) | :heavy_check_mark: | N/A |
|
||||||
|
| `message` | *str* | :heavy_check_mark: | N/A |
|
||||||
|
| `param` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `type` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A |
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# ChatGenerationParams
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ |
|
||||||
|
| `messages` | List[[components.Message](../components/message.md)] | :heavy_check_mark: | N/A |
|
||||||
|
| `model` | *Optional[str]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `models` | List[*str*] | :heavy_minus_sign: | N/A |
|
||||||
|
| `frequency_penalty` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `logit_bias` | Dict[str, *float*] | :heavy_minus_sign: | N/A |
|
||||||
|
| `logprobs` | *OptionalNullable[bool]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `top_logprobs` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `max_completion_tokens` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `max_tokens` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `metadata` | Dict[str, *str*] | :heavy_minus_sign: | N/A |
|
||||||
|
| `presence_penalty` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `reasoning` | [Optional[components.Reasoning]](../components/reasoning.md) | :heavy_minus_sign: | N/A |
|
||||||
|
| `response_format` | [Optional[components.ChatGenerationParamsResponseFormatUnion]](../components/chatgenerationparamsresponseformatunion.md) | :heavy_minus_sign: | N/A |
|
||||||
|
| `seed` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `stop` | [OptionalNullable[components.ChatGenerationParamsStop]](../components/chatgenerationparamsstop.md) | :heavy_minus_sign: | N/A |
|
||||||
|
| `stream` | *Optional[bool]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `stream_options` | [OptionalNullable[components.ChatStreamOptions]](../components/chatstreamoptions.md) | :heavy_minus_sign: | N/A |
|
||||||
|
| `temperature` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `tool_choice` | *Optional[Any]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `tools` | List[[components.ToolDefinitionJSON](../components/tooldefinitionjson.md)] | :heavy_minus_sign: | N/A |
|
||||||
|
| `top_p` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `user` | *Optional[str]* | :heavy_minus_sign: | N/A |
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# ChatGenerationParamsResponseFormatJSONObject
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------------ | ------------------------ | ------------------------ | ------------------------ |
|
||||||
|
| `type` | *Literal["json_object"]* | :heavy_check_mark: | N/A |
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# ChatGenerationParamsResponseFormatPython
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------- | ------------------- | ------------------- | ------------------- |
|
||||||
|
| `type` | *Literal["python"]* | :heavy_check_mark: | N/A |
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# ChatGenerationParamsResponseFormatText
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------ | ------------------ | ------------------ | ------------------ |
|
||||||
|
| `type` | *Literal["text"]* | :heavy_check_mark: | N/A |
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# ChatGenerationParamsResponseFormatUnion
|
||||||
|
|
||||||
|
|
||||||
|
## Supported Types
|
||||||
|
|
||||||
|
### `components.ChatGenerationParamsResponseFormatText`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.ChatGenerationParamsResponseFormatText = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
|
### `components.ChatGenerationParamsResponseFormatJSONObject`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.ChatGenerationParamsResponseFormatJSONObject = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
|
### `components.ResponseFormatJSONSchema`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.ResponseFormatJSONSchema = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
|
### `components.ResponseFormatTextGrammar`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.ResponseFormatTextGrammar = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
|
### `components.ChatGenerationParamsResponseFormatPython`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.ChatGenerationParamsResponseFormatPython = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
+1
-9
@@ -1,6 +1,4 @@
|
|||||||
# ChatCompletionCreateParamsStop
|
# ChatGenerationParamsStop
|
||||||
|
|
||||||
Stop sequences (up to 4)
|
|
||||||
|
|
||||||
|
|
||||||
## Supported Types
|
## Supported Types
|
||||||
@@ -17,9 +15,3 @@ value: str = /* values here */
|
|||||||
value: List[str] = /* values here */
|
value: List[str] = /* values here */
|
||||||
```
|
```
|
||||||
|
|
||||||
### `Any`
|
|
||||||
|
|
||||||
```python
|
|
||||||
value: Any = /* values here */
|
|
||||||
```
|
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# ChatGenerationTokenUsage
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ |
|
||||||
|
| `completion_tokens` | *float* | :heavy_check_mark: | N/A |
|
||||||
|
| `prompt_tokens` | *float* | :heavy_check_mark: | N/A |
|
||||||
|
| `total_tokens` | *float* | :heavy_check_mark: | N/A |
|
||||||
|
| `completion_tokens_details` | [OptionalNullable[components.CompletionTokensDetails]](../components/completiontokensdetails.md) | :heavy_minus_sign: | N/A |
|
||||||
|
| `prompt_tokens_details` | [OptionalNullable[components.PromptTokensDetails]](../components/prompttokensdetails.md) | :heavy_minus_sign: | N/A |
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# ChatMessageContentItem
|
||||||
|
|
||||||
|
|
||||||
|
## Supported Types
|
||||||
|
|
||||||
|
### `components.ChatMessageContentItemText`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.ChatMessageContentItemText = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
|
### `components.ChatMessageContentItemImage`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.ChatMessageContentItemImage = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
|
### `components.ChatMessageContentItemAudio`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.ChatMessageContentItemAudio = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
|
### `components.ChatMessageContentItemVideo`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.ChatMessageContentItemVideo = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# ChatMessageContentItemAudio
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
|
||||||
|
| `type` | *Literal["input_audio"]* | :heavy_check_mark: | N/A |
|
||||||
|
| `input_audio` | [components.ChatMessageContentItemAudioInputAudio](../components/chatmessagecontentitemaudioinputaudio.md) | :heavy_check_mark: | N/A |
|
||||||
+1
-3
@@ -1,6 +1,4 @@
|
|||||||
# ChatCompletionContentPartAudioFormat
|
# ChatMessageContentItemAudioFormat
|
||||||
|
|
||||||
Audio format
|
|
||||||
|
|
||||||
|
|
||||||
## Values
|
## Values
|
||||||
+3
-5
@@ -1,11 +1,9 @@
|
|||||||
# ChatCompletionNamedToolChoice
|
# ChatMessageContentItemAudioInputAudio
|
||||||
|
|
||||||
Named tool choice for specific function
|
|
||||||
|
|
||||||
|
|
||||||
## Fields
|
## Fields
|
||||||
|
|
||||||
| Field | Type | Required | Description |
|
| Field | Type | Required | Description |
|
||||||
| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
|
| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
|
||||||
| `type` | [models.ChatCompletionNamedToolChoiceType](../models/chatcompletionnamedtoolchoicetype.md) | :heavy_check_mark: | N/A |
|
| `data` | *str* | :heavy_check_mark: | N/A |
|
||||||
| `function` | [models.ChatCompletionNamedToolChoiceFunction](../models/chatcompletionnamedtoolchoicefunction.md) | :heavy_check_mark: | N/A |
|
| `format_` | [components.ChatMessageContentItemAudioFormat](../components/chatmessagecontentitemaudioformat.md) | :heavy_check_mark: | N/A |
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# ChatMessageContentItemImage
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------------------------------------ | ------------------------------------------------ | ------------------------------------------------ | ------------------------------------------------ |
|
||||||
|
| `type` | *Literal["image_url"]* | :heavy_check_mark: | N/A |
|
||||||
|
| `image_url` | [components.ImageURL](../components/imageurl.md) | :heavy_check_mark: | N/A |
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
# Detail
|
# ChatMessageContentItemImageDetail
|
||||||
|
|
||||||
Image detail level for vision models
|
|
||||||
|
|
||||||
|
|
||||||
## Values
|
## Values
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# ChatMessageContentItemText
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------ | ------------------ | ------------------ | ------------------ |
|
||||||
|
| `type` | *Literal["text"]* | :heavy_check_mark: | N/A |
|
||||||
|
| `text` | *str* | :heavy_check_mark: | N/A |
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# ChatMessageContentItemVideo
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------------------------------------ | ------------------------------------------------ | ------------------------------------------------ | ------------------------------------------------ |
|
||||||
|
| `type` | *Literal["input_video"]* | :heavy_check_mark: | N/A |
|
||||||
|
| `video_url` | [components.VideoURL](../components/videourl.md) | :heavy_check_mark: | N/A |
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# ChatMessageTokenLogprob
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- |
|
||||||
|
| `token` | *str* | :heavy_check_mark: | N/A |
|
||||||
|
| `logprob` | *float* | :heavy_check_mark: | N/A |
|
||||||
|
| `bytes_` | List[*float*] | :heavy_check_mark: | N/A |
|
||||||
|
| `top_logprobs` | List[[components.TopLogprob](../components/toplogprob.md)] | :heavy_check_mark: | N/A |
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# ChatMessageTokenLogprobs
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ |
|
||||||
|
| `content` | List[[components.ChatMessageTokenLogprob](../components/chatmessagetokenlogprob.md)] | :heavy_check_mark: | N/A |
|
||||||
|
| `refusal` | List[[components.ChatMessageTokenLogprob](../components/chatmessagetokenlogprob.md)] | :heavy_check_mark: | N/A |
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
# URLCitationAnnotationDetail
|
# ChatMessageToolCall
|
||||||
|
|
||||||
URL citation annotation
|
|
||||||
|
|
||||||
|
|
||||||
## Fields
|
## Fields
|
||||||
|
|
||||||
| Field | Type | Required | Description |
|
| Field | Type | Required | Description |
|
||||||
| -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
|
| -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
|
||||||
| `type` | [models.URLCitationAnnotationDetailType](../models/urlcitationannotationdetailtype.md) | :heavy_check_mark: | N/A |
|
| `id` | *str* | :heavy_check_mark: | N/A |
|
||||||
| `url_citation` | [models.URLCitation](../models/urlcitation.md) | :heavy_check_mark: | N/A |
|
| `type` | *Literal["function"]* | :heavy_check_mark: | N/A |
|
||||||
|
| `function` | [components.ChatMessageToolCallFunction](../components/chatmessagetoolcallfunction.md) | :heavy_check_mark: | N/A |
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# ChatMessageToolCallFunction
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------ | ------------------ | ------------------ | ------------------ |
|
||||||
|
| `name` | *str* | :heavy_check_mark: | N/A |
|
||||||
|
| `arguments` | *str* | :heavy_check_mark: | N/A |
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# ChatResponse
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ |
|
||||||
|
| `id` | *str* | :heavy_check_mark: | N/A |
|
||||||
|
| `choices` | List[[components.ChatResponseChoice](../components/chatresponsechoice.md)] | :heavy_check_mark: | N/A |
|
||||||
|
| `created` | *float* | :heavy_check_mark: | N/A |
|
||||||
|
| `model` | *str* | :heavy_check_mark: | N/A |
|
||||||
|
| `object` | *Literal["chat.completion"]* | :heavy_check_mark: | N/A |
|
||||||
|
| `system_fingerprint` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `usage` | [Optional[components.ChatGenerationTokenUsage]](../components/chatgenerationtokenusage.md) | :heavy_minus_sign: | N/A |
|
||||||
+5
-5
@@ -1,11 +1,11 @@
|
|||||||
# ChatCompletionCreateParamsPluginWeb
|
# ChatResponseChoice
|
||||||
|
|
||||||
|
|
||||||
## Fields
|
## Fields
|
||||||
|
|
||||||
| Field | Type | Required | Description |
|
| Field | Type | Required | Description |
|
||||||
| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
|
| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
|
||||||
| `id` | [models.ChatCompletionCreateParamsIDWeb](../models/chatcompletioncreateparamsidweb.md) | :heavy_check_mark: | N/A |
|
| `finish_reason` | [Nullable[components.ChatCompletionFinishReason]](../components/chatcompletionfinishreason.md) | :heavy_check_mark: | N/A |
|
||||||
| `max_results` | *Optional[float]* | :heavy_minus_sign: | N/A |
|
| `index` | *float* | :heavy_check_mark: | N/A |
|
||||||
| `search_prompt` | *Optional[str]* | :heavy_minus_sign: | N/A |
|
| `message` | [components.AssistantMessage](../components/assistantmessage.md) | :heavy_check_mark: | N/A |
|
||||||
| `engine` | [Optional[models.ChatCompletionCreateParamsEngine]](../models/chatcompletioncreateparamsengine.md) | :heavy_minus_sign: | N/A |
|
| `logprobs` | [OptionalNullable[components.ChatMessageTokenLogprobs]](../components/chatmessagetokenlogprobs.md) | :heavy_minus_sign: | N/A |
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
# ChatCompletionChoice
|
# ChatStreamingChoice
|
||||||
|
|
||||||
Chat completion choice
|
|
||||||
|
|
||||||
|
|
||||||
## Fields
|
## Fields
|
||||||
|
|
||||||
| Field | Type | Required | Description |
|
| Field | Type | Required | Description |
|
||||||
| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
|
| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
|
||||||
| `finish_reason` | [Nullable[models.ChatCompletionChoiceFinishReason]](../models/chatcompletionchoicefinishreason.md) | :heavy_check_mark: | Reason the completion finished |
|
| `delta` | [components.ChatStreamingMessageChunk](../components/chatstreamingmessagechunk.md) | :heavy_check_mark: | N/A |
|
||||||
| `index` | *float* | :heavy_check_mark: | Choice index |
|
| `finish_reason` | [Nullable[components.ChatCompletionFinishReason]](../components/chatcompletionfinishreason.md) | :heavy_check_mark: | N/A |
|
||||||
| `message` | [models.ChatCompletionMessage](../models/chatcompletionmessage.md) | :heavy_check_mark: | Assistant message in completion response |
|
| `index` | *float* | :heavy_check_mark: | N/A |
|
||||||
| `logprobs` | [OptionalNullable[models.ChatCompletionTokenLogprobs]](../models/chatcompletiontokenlogprobs.md) | :heavy_minus_sign: | Log probabilities for the completion |
|
| `logprobs` | [OptionalNullable[components.ChatMessageTokenLogprobs]](../components/chatmessagetokenlogprobs.md) | :heavy_minus_sign: | N/A |
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# ChatStreamingMessageChunk
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
|
||||||
|
| `role` | [Optional[components.ChatStreamingMessageChunkRole]](../components/chatstreamingmessagechunkrole.md) | :heavy_minus_sign: | N/A |
|
||||||
|
| `content` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `reasoning` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `refusal` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `tool_calls` | List[[components.ChatStreamingMessageToolCall](../components/chatstreamingmessagetoolcall.md)] | :heavy_minus_sign: | N/A |
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
# ChatCompletionAssistantMessageParamRole
|
# ChatStreamingMessageChunkRole
|
||||||
|
|
||||||
|
|
||||||
## Values
|
## Values
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# ChatStreamingMessageToolCall
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
|
||||||
|
| `index` | *float* | :heavy_check_mark: | N/A |
|
||||||
|
| `id` | *Optional[str]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `type` | *Optional[Literal["function"]]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `function` | [Optional[components.ChatStreamingMessageToolCallFunction]](../components/chatstreamingmessagetoolcallfunction.md) | :heavy_minus_sign: | N/A |
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# ChatStreamingMessageToolCallFunction
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------ | ------------------ | ------------------ | ------------------ |
|
||||||
|
| `name` | *Optional[str]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `arguments` | *Optional[str]* | :heavy_minus_sign: | N/A |
|
||||||
+2
-4
@@ -1,10 +1,8 @@
|
|||||||
# ChatCompletionCreateParamsResponseFormatText
|
# ChatStreamingResponseChunk
|
||||||
|
|
||||||
Default text response format
|
|
||||||
|
|
||||||
|
|
||||||
## Fields
|
## Fields
|
||||||
|
|
||||||
| Field | Type | Required | Description |
|
| Field | Type | Required | Description |
|
||||||
| -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
|
| -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
|
||||||
| `type` | [models.ChatCompletionCreateParamsTypeText](../models/chatcompletioncreateparamstypetext.md) | :heavy_check_mark: | N/A |
|
| `data` | [components.ChatStreamingResponseChunkData](../components/chatstreamingresponsechunkdata.md) | :heavy_check_mark: | N/A |
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# ChatStreamingResponseChunkData
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
|
||||||
|
| `id` | *str* | :heavy_check_mark: | N/A |
|
||||||
|
| `choices` | List[[components.ChatStreamingChoice](../components/chatstreamingchoice.md)] | :heavy_check_mark: | N/A |
|
||||||
|
| `created` | *float* | :heavy_check_mark: | N/A |
|
||||||
|
| `model` | *str* | :heavy_check_mark: | N/A |
|
||||||
|
| `object` | *Literal["chat.completion.chunk"]* | :heavy_check_mark: | N/A |
|
||||||
|
| `system_fingerprint` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `error` | [Optional[components.ChatStreamingResponseChunkError]](../components/chatstreamingresponsechunkerror.md) | :heavy_minus_sign: | N/A |
|
||||||
|
| `usage` | [Optional[components.ChatGenerationTokenUsage]](../components/chatgenerationtokenusage.md) | :heavy_minus_sign: | N/A |
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# ChatStreamingResponseChunkError
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------ | ------------------ | ------------------ | ------------------ |
|
||||||
|
| `message` | *str* | :heavy_check_mark: | N/A |
|
||||||
|
| `code` | *float* | :heavy_check_mark: | N/A |
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# ChatStreamOptions
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------ | ------------------ | ------------------ | ------------------ |
|
||||||
|
| `include_usage` | *Optional[bool]* | :heavy_minus_sign: | N/A |
|
||||||
@@ -1,23 +1,17 @@
|
|||||||
# ChatCompletionCreateParamsImage
|
# Code
|
||||||
|
|
||||||
|
|
||||||
## Supported Types
|
## Supported Types
|
||||||
|
|
||||||
### `float`
|
|
||||||
|
|
||||||
```python
|
|
||||||
value: float = /* values here */
|
|
||||||
```
|
|
||||||
|
|
||||||
### `str`
|
### `str`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
value: str = /* values here */
|
value: str = /* values here */
|
||||||
```
|
```
|
||||||
|
|
||||||
### `Any`
|
### `float`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
value: Any = /* values here */
|
value: float = /* values here */
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# CodeEnum
|
||||||
|
|
||||||
|
|
||||||
|
## 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 |
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# CompletionChoice
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
|
||||||
|
| `text` | *str* | :heavy_check_mark: | N/A |
|
||||||
|
| `index` | *float* | :heavy_check_mark: | N/A |
|
||||||
|
| `logprobs` | [Nullable[components.CompletionLogprobs]](../components/completionlogprobs.md) | :heavy_check_mark: | N/A |
|
||||||
|
| `finish_reason` | [Nullable[components.CompletionFinishReason]](../components/completionfinishreason.md) | :heavy_check_mark: | N/A |
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# CompletionCreateParams
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
|
||||||
|
| `model` | *Optional[str]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `models` | List[*str*] | :heavy_minus_sign: | N/A |
|
||||||
|
| `prompt` | [components.Prompt](../components/prompt.md) | :heavy_check_mark: | N/A |
|
||||||
|
| `best_of` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `echo` | *OptionalNullable[bool]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `frequency_penalty` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `logit_bias` | Dict[str, *float*] | :heavy_minus_sign: | N/A |
|
||||||
|
| `logprobs` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `max_tokens` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `n` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `presence_penalty` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `seed` | *OptionalNullable[int]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `stop` | [OptionalNullable[components.CompletionCreateParamsStop]](../components/completioncreateparamsstop.md) | :heavy_minus_sign: | N/A |
|
||||||
|
| `stream` | *Optional[bool]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `stream_options` | [OptionalNullable[components.StreamOptions]](../components/streamoptions.md) | :heavy_minus_sign: | N/A |
|
||||||
|
| `suffix` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `temperature` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `top_p` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `user` | *Optional[str]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `metadata` | Dict[str, *str*] | :heavy_minus_sign: | N/A |
|
||||||
|
| `response_format` | [OptionalNullable[components.CompletionCreateParamsResponseFormatUnion]](../components/completioncreateparamsresponseformatunion.md) | :heavy_minus_sign: | N/A |
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# CompletionCreateParamsResponseFormatJSONObject
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------------ | ------------------------ | ------------------------ | ------------------------ |
|
||||||
|
| `type` | *Literal["json_object"]* | :heavy_check_mark: | N/A |
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# CompletionCreateParamsResponseFormatPython
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------- | ------------------- | ------------------- | ------------------- |
|
||||||
|
| `type` | *Literal["python"]* | :heavy_check_mark: | N/A |
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# CompletionCreateParamsResponseFormatText
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------ | ------------------ | ------------------ | ------------------ |
|
||||||
|
| `type` | *Literal["text"]* | :heavy_check_mark: | N/A |
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# CompletionCreateParamsResponseFormatUnion
|
||||||
|
|
||||||
|
|
||||||
|
## Supported Types
|
||||||
|
|
||||||
|
### `components.CompletionCreateParamsResponseFormatText`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.CompletionCreateParamsResponseFormatText = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
|
### `components.CompletionCreateParamsResponseFormatJSONObject`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.CompletionCreateParamsResponseFormatJSONObject = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
|
### `components.ResponseFormatJSONSchema`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.ResponseFormatJSONSchema = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
|
### `components.ResponseFormatTextGrammar`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.ResponseFormatTextGrammar = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
|
### `components.CompletionCreateParamsResponseFormatPython`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.CompletionCreateParamsResponseFormatPython = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
+1
-9
@@ -1,6 +1,4 @@
|
|||||||
# ChatStreamCompletionCreateParamsStop
|
# CompletionCreateParamsStop
|
||||||
|
|
||||||
Stop sequences (up to 4)
|
|
||||||
|
|
||||||
|
|
||||||
## Supported Types
|
## Supported Types
|
||||||
@@ -17,9 +15,3 @@ value: str = /* values here */
|
|||||||
value: List[str] = /* values here */
|
value: List[str] = /* values here */
|
||||||
```
|
```
|
||||||
|
|
||||||
### `Any`
|
|
||||||
|
|
||||||
```python
|
|
||||||
value: Any = /* values here */
|
|
||||||
```
|
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# CompletionFinishReason
|
||||||
|
|
||||||
|
|
||||||
|
## Values
|
||||||
|
|
||||||
|
| Name | Value |
|
||||||
|
| ---------------- | ---------------- |
|
||||||
|
| `STOP` | stop |
|
||||||
|
| `LENGTH` | length |
|
||||||
|
| `CONTENT_FILTER` | content_filter |
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# CompletionLogprobs
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------------ | ------------------------ | ------------------------ | ------------------------ |
|
||||||
|
| `tokens` | List[*str*] | :heavy_check_mark: | N/A |
|
||||||
|
| `token_logprobs` | List[*float*] | :heavy_check_mark: | N/A |
|
||||||
|
| `top_logprobs` | List[Dict[str, *float*]] | :heavy_check_mark: | N/A |
|
||||||
|
| `text_offset` | List[*float*] | :heavy_check_mark: | N/A |
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# CompletionResponse
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------------------------------------------------------------ | ------------------------------------------------------------------------ | ------------------------------------------------------------------------ | ------------------------------------------------------------------------ |
|
||||||
|
| `id` | *str* | :heavy_check_mark: | N/A |
|
||||||
|
| `object` | *Literal["text_completion"]* | :heavy_check_mark: | N/A |
|
||||||
|
| `created` | *float* | :heavy_check_mark: | N/A |
|
||||||
|
| `model` | *str* | :heavy_check_mark: | N/A |
|
||||||
|
| `system_fingerprint` | *Optional[str]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `choices` | List[[components.CompletionChoice](../components/completionchoice.md)] | :heavy_check_mark: | N/A |
|
||||||
|
| `usage` | [Optional[components.CompletionUsage]](../components/completionusage.md) | :heavy_minus_sign: | N/A |
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# CompletionTokensDetails
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ---------------------------- | ---------------------------- | ---------------------------- | ---------------------------- |
|
||||||
|
| `reasoning_tokens` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `audio_tokens` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `accepted_prediction_tokens` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `rejected_prediction_tokens` | *OptionalNullable[float]* | :heavy_minus_sign: | N/A |
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# CompletionUsage
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------- | ------------------- | ------------------- | ------------------- |
|
||||||
|
| `prompt_tokens` | *float* | :heavy_check_mark: | N/A |
|
||||||
|
| `completion_tokens` | *float* | :heavy_check_mark: | N/A |
|
||||||
|
| `total_tokens` | *float* | :heavy_check_mark: | N/A |
|
||||||
@@ -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 |
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# CreateChargeRequest
|
||||||
|
|
||||||
|
Create a Coinbase charge for crypto payment
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ---------------------------------------------- | ---------------------------------------------- | ---------------------------------------------- | ---------------------------------------------- |
|
||||||
|
| `amount` | *float* | :heavy_check_mark: | N/A |
|
||||||
|
| `sender` | *str* | :heavy_check_mark: | N/A |
|
||||||
|
| `chain_id` | [components.ChainID](../components/chainid.md) | :heavy_check_mark: | N/A |
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
# ChatCompletionCreateParamsDataCollection
|
# DataCollection
|
||||||
|
|
||||||
Data collection setting. If no available model provider meets the requirement, your request will return an error.
|
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
|
- allow: (default) allow providers which store user data non-transiently and may train on it
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# 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 |
|
||||||
|
| `frequency_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 |
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# Effort
|
||||||
|
|
||||||
|
|
||||||
|
## Values
|
||||||
|
|
||||||
|
| Name | Value |
|
||||||
|
| --------- | --------- |
|
||||||
|
| `MINIMAL` | minimal |
|
||||||
|
| `LOW` | low |
|
||||||
|
| `MEDIUM` | medium |
|
||||||
|
| `HIGH` | high |
|
||||||
@@ -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 |
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# ChatCompletionCreateParamsEngine
|
# Engine
|
||||||
|
|
||||||
|
|
||||||
## Values
|
## Values
|
||||||
@@ -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 |
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# FileCitationType
|
||||||
|
|
||||||
|
|
||||||
|
## Values
|
||||||
|
|
||||||
|
| Name | Value |
|
||||||
|
| --------------- | --------------- |
|
||||||
|
| `FILE_CITATION` | file_citation |
|
||||||
@@ -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 @@
|
|||||||
# ContentTypeImageURL
|
# FilePathType
|
||||||
|
|
||||||
|
|
||||||
## Values
|
## Values
|
||||||
|
|
||||||
| Name | Value |
|
| 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 |
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
# ChatCompletionCreateParamsIDFileParser
|
# IDFileParser
|
||||||
|
|
||||||
|
|
||||||
## Values
|
## Values
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
# ChatCompletionCreateParamsIDModeration
|
# IDModeration
|
||||||
|
|
||||||
|
|
||||||
## Values
|
## Values
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# ChatCompletionCreateParamsIDWeb
|
# IDWeb
|
||||||
|
|
||||||
|
|
||||||
## Values
|
## Values
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Ignore
|
||||||
|
|
||||||
|
|
||||||
|
## Supported Types
|
||||||
|
|
||||||
|
### `components.ProviderName`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.ProviderName = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
|
### `str`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: str = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# ImageGenerationStatus
|
||||||
|
|
||||||
|
|
||||||
|
## Values
|
||||||
|
|
||||||
|
| Name | Value |
|
||||||
|
| ------------- | ------------- |
|
||||||
|
| `IN_PROGRESS` | in_progress |
|
||||||
|
| `COMPLETED` | completed |
|
||||||
|
| `GENERATING` | generating |
|
||||||
|
| `FAILED` | failed |
|
||||||
+3
-2
@@ -1,8 +1,9 @@
|
|||||||
# ChatCompletionCreateParamsPluginChainOfThought
|
# ImageURL
|
||||||
|
|
||||||
|
|
||||||
## Fields
|
## Fields
|
||||||
|
|
||||||
| Field | Type | Required | Description |
|
| Field | Type | Required | Description |
|
||||||
| ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ |
|
| ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ |
|
||||||
| `id` | [models.ChatCompletionCreateParamsIDChainOfThought](../models/chatcompletioncreateparamsidchainofthought.md) | :heavy_check_mark: | N/A |
|
| `url` | *str* | :heavy_check_mark: | N/A |
|
||||||
|
| `detail` | [Optional[components.ChatMessageContentItemImageDetail]](../components/chatmessagecontentitemimagedetail.md) | :heavy_minus_sign: | N/A |
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# InputModality
|
||||||
|
|
||||||
|
|
||||||
|
## Values
|
||||||
|
|
||||||
|
| Name | Value |
|
||||||
|
| ------- | ------- |
|
||||||
|
| `TEXT` | text |
|
||||||
|
| `IMAGE` | image |
|
||||||
|
| `FILE` | file |
|
||||||
|
| `AUDIO` | audio |
|
||||||
|
| `VIDEO` | video |
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# InputTokensDetails
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------ | ------------------ | ------------------ | ------------------ |
|
||||||
|
| `cached_tokens` | *float* | :heavy_check_mark: | N/A |
|
||||||
@@ -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 |
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# JSONSchemaConfig
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| ------------------------ | ------------------------ | ------------------------ | ------------------------ |
|
||||||
|
| `name` | *str* | :heavy_check_mark: | N/A |
|
||||||
|
| `description` | *Optional[str]* | :heavy_minus_sign: | N/A |
|
||||||
|
| `schema_` | Dict[str, *Any*] | :heavy_minus_sign: | N/A |
|
||||||
|
| `strict` | *OptionalNullable[bool]* | :heavy_minus_sign: | N/A |
|
||||||
@@ -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 | |
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# MaxPrice
|
||||||
|
|
||||||
|
The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion.
|
||||||
|
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
| Field | Type | Required | Description |
|
||||||
|
| --------------------------------------------------------- | --------------------------------------------------------- | --------------------------------------------------------- | --------------------------------------------------------- |
|
||||||
|
| `prompt` | *Optional[Any]* | :heavy_minus_sign: | A value in string or number format that is a large number |
|
||||||
|
| `completion` | *Optional[Any]* | :heavy_minus_sign: | A value in string or number format that is a large number |
|
||||||
|
| `image` | *Optional[Any]* | :heavy_minus_sign: | A value in string or number format that is a large number |
|
||||||
|
| `audio` | *Optional[Any]* | :heavy_minus_sign: | A value in string or number format that is a large number |
|
||||||
|
| `request` | *Optional[Any]* | :heavy_minus_sign: | A value in string or number format that is a large number |
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# Message
|
||||||
|
|
||||||
|
|
||||||
|
## Supported Types
|
||||||
|
|
||||||
|
### `components.SystemMessage`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.SystemMessage = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
|
### `components.UserMessage`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.UserMessage = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
|
### `components.MessageDeveloper`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.MessageDeveloper = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
|
### `components.AssistantMessage`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.AssistantMessage = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
|
### `components.ToolResponseMessage`
|
||||||
|
|
||||||
|
```python
|
||||||
|
value: components.ToolResponseMessage = /* values here */
|
||||||
|
```
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user