OpenAI
OpenAI API Keys
To use OpenAI model with OneRouter, you’ll need to provide your OpenAI API key.
Learn more in the OpenAI API Keys Dashboard.
Using the OpenAI SDK
from openai import OpenAI
client = OpenAI(
base_url="https://llm.onerouter.pro/v1",
api_key="<API_KEY>",
)
completion = client.chat.completions.create(
byok_conf={
"provider": "openai",
"fallback": True,
"credentials": "your-openai-key"
},
model="gpt-5.1-chat",
messages=[
{
"role": "user",
"content": "What is the meaning of life?"
}
]
)
print(completion.choices[0].message.content)byok_conf: When this parameter is included in the input, OneRouter will route requests according to the BYOK configuration information specified. When this parameter is
nullornot provided, OneRouter defaults to routing to the shared provider pool.provider: Specifies the name of the provider where the request should be routed.
fallback: OneRouter always prioritizes using your provider keys when available. By default, if your key encounters a rate limit or failure, OneRouter will fall back to using shared OneRouter credits.
The default value for fallback is
True.If fallback is specified as
False, OneRouter will only use your key for requests to that provider.
credentials: The keys and credentials used for authentication with the specified provider.
Using the OneRouter API directly
import requests
import json
response = requests.post(
url="https://llm.onerouter.pro/v1/chat/completions",
headers={
"Authorization": "Bearer <API_KEY>",
"Content-Type": "application/json"
},
data=json.dumps({
"byok_conf": {
"provider": "openai",
"fallback": True,
"credentials": "your-openai-key"
},
"model": "gpt-5.1-chat",
"messages": [
{
"role": "user",
"content": "What is the meaning of life?"
}
]
})
)
print(response.json()["choices"][0]["message"]["content"])Last updated