Browse docs ▾
Getting started

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.

LanguageRegistryInstall
JavaScript / TypeScriptnpmnpm install boldrouter. Node.js 22+. Built on the official openai package. npm
PythonPyPIpip install boldrouter. Python 3.10+, sync and async. Built on the official openai package. PyPI
PHPPackagistcomposer 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.

.env
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.

app.ts - JavaScript / TypeScript
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);
app.py - Python
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)
app.php - PHP
<?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

JavaScript / TypeScript
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 ?? "");
Python
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)
PHP
$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.

JavaScript / TypeScript
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);
Python
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"))
PHP
$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'];
FieldTypeDescription
routingstringbalanced (default), price, latency or uptime. Sent as the x-bold-routing header. Routing & failover
providerobjectorder, only, ignore, allow_fallbacks, sort. Routing & failover
modelsstring[]Models to fall back to, in order. The requested model is tried first.
reasoningobjectenabled, effort. Chat completions
anonymizeboolean | objectRemove personal data before the prompt reaches the provider. Prompt anonymization
cachebooleanOn 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.
Python
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) and APIError with status 402 for insufficient credit.
  • PHP throws AuthenticationException, InsufficientCreditException (402), NotFoundException, RateLimitException, ServerException and ConnectionException, all under BoldRouter\Exception.

See Errors & rate limits for what each status means.

Frameworks and tools

  • Vercel AI SDK: npm install @boldrouter/ai-sdk-provider, then import { boldrouter } from "@boldrouter/ai-sdk-provider" and generateText({ 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.
Using another language? Every OpenAI-compatible client works: set its base URL to https://boldrouter.com/v1 and use your boldrouter key.