SDKs and frameworks
OpenAI Python SDK
Two changes point the OpenAI Python SDK at TokRouter — base_url and api_key.
pip install openaiimport os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["TOKROUTER_API_KEY"],
base_url="https://api.tokrouter.dev/v1",
)
# Non-streaming
resp = client.chat.completions.create(
model="gpt-5.4-mini",
messages=[{"role": "user", "content": "Explain SSO in one sentence"}],
)
print(resp.choices[0].message.content)
# Streaming
for chunk in client.chat.completions.create(
model="gpt-5.4-mini",
messages=[{"role": "user", "content": "Write a four-line poem"}],
stream=True,
):
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="", flush=True)Call Claude with the OpenAI SDK
resp = client.chat.completions.create(
model="claude-opus-5-5",
messages=[{"role": "user", "content": "Hello"}],
)Tool calling
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
resp = client.chat.completions.create(
model="gpt-5.4",
messages=[{"role": "user", "content": "What's the weather in Beijing?"}],
tools=tools,
)
print(resp.choices[0].message.tool_calls)Field-level details: API reference · Chat Completions.