Metadata-Version: 2.5
Name: boldrouter
Version: 0.1.0
Summary: Official BoldRouter SDK for Python. The OpenAI SDK, preconfigured for BoldRouter, plus typed routing, failover, reasoning, anonymization and caching options and model comparison helpers.
Project-URL: Homepage, https://boldrouter.com
Project-URL: Documentation, https://boldrouter.com/docs
Project-URL: Repository, https://github.com/boldrouter/boldrouter
Project-URL: Issues, https://github.com/boldrouter/boldrouter/issues
Author-email: "GentleBulldozer (GentleDozer on X)" <support@boldrouter.com>
License-Expression: MIT
License-File: LICENSE
Keywords: ai,boldrouter,gateway,llm,openai-compatible,router,sdk
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: openai<4,>=1.60
Requires-Dist: typing-extensions>=4.7
Provides-Extra: test
Requires-Dist: httpx>=0.27; extra == 'test'
Requires-Dist: pytest-asyncio>=0.24; extra == 'test'
Requires-Dist: pytest>=8; extra == 'test'
Description-Content-Type: text/markdown

# boldrouter

Official [BoldRouter](https://boldrouter.com) SDK for Python. It is the OpenAI SDK, preconfigured for BoldRouter, plus typed BoldRouter options and a few helpers. One API key, 170+ models across 30+ providers, automatic routing and failover, prompt caching and PII anonymization.

## Install

```bash
pip install boldrouter
```

Python 3.10+.

## Usage

```python
from boldrouter import BoldRouter

client = BoldRouter(api_key="sk-bold-...")  # or omit and set BOLDROUTER_API_KEY

# Everything from the OpenAI SDK works unchanged:
res = client.chat.completions.create(
    model="bold/auto",
    messages=[{"role": "user", "content": "What is an API gateway?"}],
)
print(res.choices[0].message.content)
```

Streaming, tools, structured outputs and embeddings are the same calls you already know. Image generation goes through chat completions: pass `modalities=["image", "text"]` with an image-capable model such as `bold/image` and read `choices[0].message.images`. `AsyncBoldRouter` is the async variant.

## BoldRouter options

`client.bold.chat` takes the same parameters as `chat.completions.create` plus typed BoldRouter options, and returns the reply together with which provider served it:

```python
r = client.bold.chat(
    model="anthropic/claude-sonnet-4.6",
    messages=[{"role": "user", "content": "Summarize this..."}],
    routing="price",                                       # x-bold-routing header
    provider={"order": ["anthropic", "openai"], "allow_fallbacks": True},
    models=["openai/gpt-5.5", "google/gemini-2.5-pro"],    # cross-model fallback chain
    reasoning={"enabled": True, "effort": "high"},
    anonymize=True,
    cache=False,
)
print(r.text, r.provider, r.bold["model"], r.completion.usage)
```

Defaults for every `client.bold` call: `BoldRouter(defaults={"routing": "latency"})`.

To use the options with the plain OpenAI methods, or with streaming:

```python
from boldrouter import bold_options

stream = client.chat.completions.create(
    model="bold/auto", messages=msgs, stream=True,
    **bold_options(model="bold/auto", routing="latency", models=["openai/gpt-5.5"]),
)
```

| Option | Sent as | Docs |
|---|---|---|
| `routing` | `x-bold-routing` header: `balanced` (default), `price`, `latency`, `uptime` | [Routing](https://boldrouter.com/docs/routing) |
| `provider` | `provider` body field: `order`, `only`, `ignore`, `allow_fallbacks`, `sort` | [Routing](https://boldrouter.com/docs/routing) |
| `models` | `models` body field. The primary model is prepended automatically. | [Routing](https://boldrouter.com/docs/routing) |
| `reasoning` | `reasoning` body field: `enabled`, `effort` | [Chat completions](https://boldrouter.com/docs/chat-completions) |
| `anonymize` | `anonymize` body field, `True` or `{"enabled", "reverse", "entities"}` | [Anonymization](https://boldrouter.com/docs/anonymization) |
| `cache` | `cache` body field. On by default; `False` disables. | [Prompt caching](https://boldrouter.com/docs/prompt-caching) |

## Helpers

```python
client.bold.models(kind="chat")                     # bold/* first, then alphabetical
client.bold.compare(["openai/gpt-5.5", "anthropic/claude-sonnet-4.6"], messages=msgs)
# [CompareResult(model=..., ok=True, text=..., bold={"provider": ...}, usage=..., latency_ms=...), ...]
```

`read_bold_headers(raw.headers)` extracts the `x-bold-*` headers from any `with_raw_response` result.

## Configuration

| Option | Default | Description |
|---|---|---|
| `api_key` | `BOLDROUTER_API_KEY` | Keys start with `sk-bold-`. Create one at [boldrouter.com/dashboard/keys](https://boldrouter.com/dashboard/keys). |
| `base_url` | `https://boldrouter.com/v1` or `BOLDROUTER_BASE_URL` | Override for proxies or testing. |
| `defaults` | `{}` | BoldRouter options applied to every `client.bold` call. |
| anything else | | Passed to the OpenAI client: `timeout`, `max_retries`, `http_client`, `default_headers`, ... |

## Errors

BoldRouter returns OpenAI-shaped errors, so the OpenAI SDK's exceptions apply: `AuthenticationError` (401), `RateLimitError` (429), `NotFoundError` (404 unknown model), `APIStatusError` with status 402 for insufficient credit and 502 when all providers failed. The SDK retries 429 and 5xx with backoff by default.

## License

MIT. Project: [BoldRouter](https://boldrouter.com). Author: GentleBulldozer ([GentleDozer on X](https://x.com/GentleDozer)). Owner: Cybrient Technologies SA.
