ultrarouter docs
Guides

Python SDK

The ultrarouter Python client — sync + async, pydantic-typed.

The ultrarouter package mirrors the openai python v1 ergonomics — sync + async, built on httpx, typed with pydantic v2 (py ≥ 3.10).

ultrarouter is not on PyPI. Clone the public feat/learning-loop branch for the learning preview (0.1.0), build its wheel, and install that file. The default main branch does not carry this preview. Exact current artifact names are in /setup-recipes.json; <version> below is the version of the package you build.

git clone --branch feat/learning-loop --single-branch https://github.com/lucastonon/ultrarouter-sdk-python ../ultrarouter-sdk-python
(cd ../ultrarouter-sdk-python && uv build)
pip install ../ultrarouter-sdk-python/dist/ultrarouter-<version>-py3-none-any.whl
# with the openai drop-in adapter (the extra pulls openai from PyPI):
pip install "../ultrarouter-sdk-python/dist/ultrarouter-<version>-py3-none-any.whl[openai]"

Quickstart

from ultrarouter import UltraRouter

ur = UltraRouter(
    api_key="ur_sk_test_...",  # or set ULTRAROUTER_API_KEY / UR_API_KEY
    default_model="anthropic/claude-sonnet-4-6",
    defaults={"router": "off", "compression": "semantic_safe", "provider": {"sort": "price"}},
)

res = ur.chat.completions.create(
    model="openai/gpt-5-mini",  # per-call override of default_model
    messages=[{"role": "user", "content": "hi"}],
    call_type="support-reply-draft",
    router="auto",
    compression={"mode": "auto", "no_compress_fields": ["messages.1.content"]},
)
print(res.choices[0].message.content, res.ur.cost_usd)

Async

import asyncio
from ultrarouter import AsyncUltraRouter

async def main():
    async with AsyncUltraRouter(api_key="ur_sk_test_...") as ur:
        res = await ur.chat.completions.create(
            model="openai/gpt-5-mini", messages=[{"role": "user", "content": "hi"}],
        )
        print(res.ur.cost_usd)

asyncio.run(main())

Extensions and drop-in

emb = ur.embeddings.create(model="openai/text-embedding-3-small", input=["a", "b"])
models = ur.models.list(capability="vision")
cts = ur.call_types.list()
ur.requests.feedback(res.ur.request_id, rating=1, tags=["great"])
stats = ur.generation.get(res.ur.request_id)

client = ur.as_openai()  # a configured openai.OpenAI (requires the [openai] extra)

Retries 429 / 5xx / transport errors with jittered backoff honoring Retry-After (max_retries, default 2). Non-streaming POSTs carry a stable auto Idempotency-Key. Errors are UltraRouterError (.code, .status, .request_id, .retryable, .provider_code).

The SDK's source is the public repository lucastonon/ultrarouter-sdk-python. Until the package is published to PyPI, install the wheel built from that repository with uv build, as shown at the top of this page.