openai.OpenRouterClient
OpenRouter's chat-completions gateway.
Signature
class openai.OpenRouterClientOpenRouter's chat-completions gateway.
A plain bearer-auth chat-completions endpoint at
https://openrouter.ai/api/v1, keyed by OPENROUTER_API_KEY. Model ids are
namespaced by upstream provider ("openai/gpt-4o-mini",
"anthropic/claude-3.5-sonnet", …).
App-attribution headers are not a special option: pass them through the
ordinary headers field —
headers = {"HTTP-Referer": "https://myapp.com", "X-Title": "My App"}.
OpenRouter-specific body fields (provider, route, transforms) go
through request_body.
Source:<builtin>/openai/openrouter.bamlbytes 571–5100
Fields
model
stringapi_key
ai.Credential | nullbase_url
ai.Credential | nullrequest_body
baml.json.json | nullheaders
map<string, string> | nullquery_params
map<string, string> | nulltemperature
float | nullmax_tokens
int | nulltop_p
float | nullstop
string[] | nullseed
int | nullcapture_wire
boolStatic methods
new
(Creates a client. Construction reads no environment variable, so declaring one is always safe; credentials and endpoints resolve when a request is built.
Instance methods
The provider record: everything the shared chat core needs to know about this endpoint.
params
(The per-request parameters handed to the shared chat core.
Parameters
preview: omit the credential, for rendering a request without sending it.
resolved_api_key
(self) -> string | null throws baml.errors.Io | baml.errors.ParseErrorThe request-time credential: the explicit value, else
OPENROUTER_API_KEY. Null is reported as a configuration error when
the request is built.
resolved_base_url
(self) -> string throws baml.errors.Io | baml.errors.ParseErrorThe request-time base URL, or https://openrouter.ai/api/v1.
Implementations
ai.Client for openai.OpenRouterClient
Instance methods
id
(self) -> stringinvoke
(render
(Source:<builtin>/openai/openrouter.bamlbytes 3927–4666
ai.stream.StreamingClient for openai.OpenRouterClient
Instance methods
invoke_stream
(Source:<builtin>/openai/openrouter.bamlbytes 4672–5098