SDKs & Integration

Python SDK

Use the OpenAI Python SDK with OneRouter for sync, async, streaming, and function calling across 200+ models.

Installation

shell
pip install openai

Synchronous Usage

python
from openai import OpenAI
client = OpenAI(api_key="sk-your-key", base_url="https://api.onerouter.app/v1")
response = client.chat.completions.create(model="gpt-4o", messages=[{"role":"user","content":"Hello"}])
print(response.choices[0].message.content)

Async Usage

python
from openai import AsyncOpenAI
client = AsyncOpenAI(api_key="sk-your-key", base_url="https://api.onerouter.app/v1")
async def main():
    response = await client.chat.completions.create(model="gpt-4o", messages=[...])

Function Calling

Tool/function calling works identically — define your tools and the model will return structured JSON.

Error Handling

python
from openai import APIError, RateLimitError
try:
    response = client.chat.completions.create(...)
except RateLimitError:
    print("Rate limited — backoff and retry")
except APIError as e:
    print(f"API error: {e}")