Skip to main content
The auriko Python package provides an OpenAI-compatible client for the Auriko 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

You can also pass a RoutingOptions object for IDE autocomplete and validation:
All routing fields:
FieldTypeDescription
optimizeOptimizeStrategy: "cost", "cost-focus", "ttft", "ttft-focus", "tps", "tps-focus", "balanced"
weightsdict[str, float]Custom scoring weights: cost, ttft, throughput. Overrides preset.
ttft_percentilestrTTFT scoring percentile: "p50" (default) or "p95"
throughput_percentilestrThroughput scoring percentile: "p50" (default) or "p95"
max_cost_per_1mfloatMax $ per 1M tokens (average of input + output)
max_ttft_msintMax TTFT in milliseconds
min_throughput_tpsfloatMin throughput in tokens/sec
providerslist[str]Allowlist of providers
exclude_providerslist[str]Blocklist of providers
preferstrPreferred provider (soft preference)
modeMode"pool" (default) or "fallback"
allow_fallbacksboolEnable fallback on failure
max_fallback_attemptsintMax fallback retries
data_policyDataPolicy"none", "no_training", "zdr"
only_byokboolOnly use BYOK providers
only_platformboolOnly use platform providers
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 the reasoning_effort parameter:
You can also pass provider-specific parameters through extensions:
See Extensions and Thinking for provider details and streaming thinking output.

Request metadata

Attach metadata to requests for tracking and analytics:
Valid metadata fields: 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

After consuming all chunks, access stream-level metadata:
Use a context manager for automatic cleanup:
Or close manually with stream.close().
Routing metadata, usage, and response headers are available only after consuming all chunks.
See Streaming Guide for full patterns including tool call streaming.

Tool calling

See Tool Calling Guide for multi-turn tool conversations.

Read response headers

Every response and error includes a response_headers object with typed accessors:
PropertyHeaderType
request_idx-request-idstr | None
rate_limit_remainingx-ratelimit-remaining-requestsint | None
rate_limit_limitx-ratelimit-limit-requestsint | None
rate_limit_resetx-ratelimit-reset-requestsstr | None
credits_balance_microdollarsx-credits-balance-microdollarsint | None
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

The Usage object on every response carries optional detail breakdowns:
FieldSub-fieldsType
prompt_tokens_detailscached_tokensOptional[int]
completion_tokens_detailsreasoning_tokensOptional[int]
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:
See Error Handling Guide for retry patterns and map_openai_error().

Use identity and model discovery APIs

Query identity and model information:

Model listing choices

MethodReturnsUse when
list()All models with provider availability, pricing, data policyYou need the full model catalog
retrieve(model_id)Single model: provider availability, pricing, data policyYou have a model ID and need its details
list_registry()Flat list: id, family, display_nameYou need a quick model ID lookup
list_directory()Rich detail: provider entries, context windows, capabilities, pricing tiersYou need to compare providers or check capabilities
list_providers()Provider catalog: display name, description, data policyYou need to see available providers
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

Use async with for automatic connection cleanup:
Or close explicitly: await client.close()

Use with OpenAI-compatible frameworks

AurikoAsyncOpenAI (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 any AsyncOpenAI 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:
The callback must be synchronous. An async callable raises TypeError at construction.

Pass routing options

Pass routing options via the extra_body kwarg. RoutingOptions.to_extra_body() returns a dict shaped for the Auriko API:
RoutingOptions lives in auriko.route_types. It is not exported at top-level.

Framework wiring

Each supported framework accepts an external AsyncOpenAI instance via its own kwarg:
FrameworkConstructor call
OpenAI Agents SDKOpenAIChatCompletionsModel(model="gpt-5.4", openai_client=client)
LangChain ChatOpenAIChatOpenAI(model="gpt-5.4", async_client=client.chat.completions, api_key="placeholder")
LlamaIndex OpenAIOpenAI(model="gpt-5.4", async_openai_client=client, api_key="placeholder")
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 AurikoAsyncOpenAI.

AurikoAsyncOpenAI (experimental) or AsyncClient?

Use AurikoAsyncOpenAI when a framework needs an AsyncOpenAI instance. Use auriko.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.
AurikoAsyncOpenAI is Python-only. TypeScript consumers can use @auriko/ai-sdk-provider with the Vercel AI SDK, or the OpenAI TS SDK with baseURL: 'https://api.auriko.ai/v1'.

Use context managers

Use a context manager for automatic cleanup:

SDK scope

The Auriko SDK covers: inference (chat completions and the Response API, both with routing), identity, and model discovery. For full platform operations, use the REST API directly.

Use type hints

The SDK provides typed responses, errors, and routing configuration. Use your IDE’s autocomplete for the best experience: