arbytra Python package provides an OpenAI-compatible client for the Arbytra API.
Full SDK Reference
Complete API reference with all types, parameters, and examples
Installation
Requires Python 3.10 or later.
Get started
Configure
API Key
Base URL
Timeout
Retries
Create chat completions
Basic request
Send a chat completion request:With routing options
RoutingOptions object for IDE autocomplete and validation:
See Advanced Routing for detailed strategy guides.
Multi-model routing
Route a request across multiple models. The router picks the best option based on your routing strategy:model and gateway.models are mutually exclusive. Specify exactly one. Passing both raises BadRequestError.Reasoning effort
Enable extended reasoning for complex tasks using thereasoning_effort parameter:
extensions:
Request metadata
Attach metadata to requests for tracking and analytics:user_id, tags (list), trace_id, and custom_fields (dict for arbitrary key-value pairs). See the Python SDK Reference for field constraints.
Stream responses
stream.close().
Routing metadata, usage, and response headers are available only after consuming all chunks.
Tool calling
Read response headers
Every response and error includes aresponse_headers object with typed accessors:
Error objects also carry
response_headers. Use e.response_headers.request_id when filing support tickets to correlate with server logs.
See the Python SDK Reference for the complete ResponseHeaders API.
Read token usage
TheUsage object on every response carries optional detail breakdowns:
Availability depends on the provider.
completion_tokens_details.reasoning_tokens is present for OpenAI o-series, DeepSeek, xAI, and Google Gemini. It’s None for providers that don’t report reasoning token counts (Anthropic, Moonshot, Fireworks).
See Check reasoning token availability for the full breakdown.
Handle errors
Catch typed exceptions:map_openai_error().
Use identity and model discovery APIs
Query identity and model information:Model listing choices
See the Python SDK Reference for the complete API.
Use async client
Use the async client for non-blocking requests:Async streaming
Stream responses asynchronously:Async context manager
Useasync with for automatic connection cleanup:
await client.close()
Use with OpenAI-compatible frameworks
ArbytraAsyncOpenAI (experimental) is an AsyncOpenAI subclass that captures routing metadata automatically. Pass it to any framework that accepts an external AsyncOpenAI instance. The kwarg name varies across frameworks.
Install with the optional openai-compat extra:
Basic usage
Call it directly like anyAsyncOpenAI client, then read last_routing_metadata on the client after the response completes:
Capture metadata per request
last_routing_metadata is a single-slot property. Under concurrent use it reflects the most recent response. For per-request capture, pass an on_response callback:
TypeError at construction.
Pass routing options
Pass routing options via theextra_body kwarg. RoutingOptions.to_extra_body() returns a dict shaped for the Arbytra API:
RoutingOptions lives in arbytra.route_types. It is not exported at top-level.
Framework wiring
Each supported framework accepts an externalAsyncOpenAI instance via its own kwarg:
LangChain takes the
chat.completions resource rather than the full client. LangChain and LlamaIndex both still require an api_key argument for their own parent-class construction; pass any placeholder value.
For the Agents SDK path, see OpenAI Agents SDK. For the full class reference, see ArbytraAsyncOpenAI.
ArbytraAsyncOpenAI (experimental) or AsyncClient?
Use ArbytraAsyncOpenAI when a framework needs an AsyncOpenAI instance. Use arbytra.AsyncClient for direct Python code. AsyncClient exposes routing_metadata directly on each response, so you do not need to read a separate client-level property.
ArbytraAsyncOpenAI is Python-only. TypeScript consumers can use @arbytra/ai-sdk-provider with the Vercel AI SDK, or the OpenAI TS SDK with baseURL: 'https://api.arbytra.com/v1'.