SDKs
Official libraries for JavaScript and TypeScript, Python and PHP. They come set up for boldrouter, take boldrouter's options as typed parameters, and tell you which provider answered each request. Any OpenAI SDK also works if you set the base URL, as in the Quickstart.
| Language | Registry | Install |
|---|---|---|
| JavaScript / TypeScript | npm | npm install boldrouter. Node.js 22+. Built on the official openai package. npm |
| Python | PyPI | pip install boldrouter. Python 3.10+, sync and async. Built on the official openai package. PyPI |
| PHP | Packagist | composer require boldrouter/boldrouter. PHP 8.1+ with the curl extension. Packagist |
All three read your key from the BOLDROUTER_API_KEY environment variable, or take it as a parameter. Create a key under API keys.
export BOLDROUTER_API_KEY="sk-bold-..."Your first request
The requests and responses are the ones of the OpenAI API, so existing code carries over.
import BoldRouter from "boldrouter";
const client = new BoldRouter(); // reads BOLDROUTER_API_KEY
const res = await client.chat.completions.create({
model: "bold/auto",
messages: [{ role: "user", content: "Explain failover in one line." }],
});
console.log(res.choices[0].message.content);from boldrouter import BoldRouter
client = BoldRouter() # reads BOLDROUTER_API_KEY
res = client.chat.completions.create(
model="bold/auto",
messages=[{"role": "user", "content": "Explain failover in one line."}],
)
print(res.choices[0].message.content)<?php
require 'vendor/autoload.php';
$client = new BoldRouter\BoldRouter(); // reads BOLDROUTER_API_KEY
$res = $client->chat->completions->create([
'model' => 'bold/auto',
'messages' => [['role' => 'user', 'content' => 'Explain failover in one line.']],
]);
echo $res['choices'][0]['message']['content'];Tools, structured outputs, images in messages and embeddings are the same calls too. In PHP, responses are the decoded JSON as arrays.
Streaming
const stream = await client.chat.completions.create({
model: "bold/fast",
messages: [{ role: "user", content: "Write a haiku about Geneva." }],
stream: true,
});
for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? "");stream = client.chat.completions.create(
model="bold/fast",
messages=[{"role": "user", "content": "Write a haiku about Geneva."}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="", flush=True)$stream = $client->chat->completions->createStreamed([
'model' => 'bold/fast',
'messages' => [['role' => 'user', 'content' => 'Write a haiku about Geneva.']],
]);
foreach ($stream->text() as $delta) {
echo $delta;
}Routing and other boldrouter options
bold.chat takes the usual chat parameters plus boldrouter's options, and returns the reply together with the provider and model that served it. model defaults to bold/auto.
const { text, bold } = await client.bold.chat({
model: "anthropic/claude-sonnet-4.6",
messages: [{ role: "user", content: "Summarize this..." }],
routing: "price", // cheapest healthy provider
models: ["openai/gpt-5.5", "google/gemini-3.5-flash"], // fall back to these models
anonymize: true,
});
console.log(text, bold.provider, bold.model);r = client.bold.chat(
model="anthropic/claude-sonnet-4.6",
messages=[{"role": "user", "content": "Summarize this..."}],
routing="price",
models=["openai/gpt-5.5", "google/gemini-3.5-flash"],
anonymize=True,
)
print(r.text, r.provider, r.bold.get("model"))$r = $client->bold->chat([
'model' => 'anthropic/claude-sonnet-4.6',
'messages' => [['role' => 'user', 'content' => 'Summarize this...']],
'routing' => 'price',
'models' => ['openai/gpt-5.5', 'google/gemini-3.5-flash'],
'anonymize' => true,
]);
echo $r->text, ' ', $r->provider(), ' ', $r->bold['model'];| Field | Type | Description |
|---|---|---|
| routing | string | balanced (default), price, latency or uptime. Sent as the x-bold-routing header. Routing & failover |
| provider | object | order, only, ignore, allow_fallbacks, sort. Routing & failover |
| models | string[] | Models to fall back to, in order. The requested model is tried first. |
| reasoning | object | enabled, effort. Chat completions |
| anonymize | boolean | object | Remove personal data before the prompt reaches the provider. Prompt anonymization |
| cache | boolean | On by default; false turns it off. Prompt caching |
To set options once for every bold call, pass defaults when creating the client, for example new BoldRouter({ defaults: { routing: "latency" } }). In PHP the options can also go straight into chat->completions->create().
Helpers
bold.models()lists the catalog with the auto-routers (bold/*) first. Filter by kind (chat,embedding, ...) or by part of the model id.bold.compare(models, params)sends the same request to several models and returns each answer with its provider, usage and latency. A model that fails is returned as a failure, not thrown.
results = client.bold.compare(
["openai/gpt-5.5", "anthropic/claude-sonnet-4.6"],
messages=[{"role": "user", "content": "One-line haiku about routers."}],
)
for r in results:
print(r.model, r.text if r.ok else r.error)Errors and retries
The SDKs retry rate limits (429) and server errors (5xx) with backoff, honouring retry-after, before they give up. Errors keep their HTTP status, so you can tell them apart:
- JavaScript and Python raise the OpenAI SDK's errors:
AuthenticationError(401),NotFoundError(404, unknown model),RateLimitError(429) andAPIErrorwith status 402 for insufficient credit. - PHP throws
AuthenticationException,InsufficientCreditException(402),NotFoundException,RateLimitException,ServerExceptionandConnectionException, all underBoldRouter\Exception.
See Errors & rate limits for what each status means.
Frameworks and tools
- Vercel AI SDK:
npm install @boldrouter/ai-sdk-provider, thenimport { boldrouter } from "@boldrouter/ai-sdk-provider"andgenerateText({ model: boldrouter("bold/auto"), ... }). - n8n: install the community node
n8n-nodes-boldrouter(BoldRouter Chat Model) under Settings → Community nodes. - Langflow:
pip install lfx-boldrouter. - MCP clients such as Claude Desktop and Cursor: see MCP server.
https://boldrouter.com/v1 and use your boldrouter key.