CHrouter API

An OpenAI-compatible chat endpoint. Any OpenAI client library works by changing its base URL and API key.

Connecting

Base URLhttps://api.chrouter.ch/v1
AuthenticationAuthorization: Bearer chr_… - the key you were given.
EndpointsPOST /v1/chat/completions (streaming and not)
GET /v1/models

Models

Pass a routing name as model; it picks a model and falls back to the next one if a provider fails:

A specific model id also works. GET /v1/models lists every name your key can use. Text chat only.

Limits

Errors

In OpenAI's shape: {"error": {"message", "type", "code"}}.

StatuscodeMeaning
400The request is malformed (for example, messages missing).
401invalid_api_keyNo key, a wrong key, or a revoked key. Repeated failures block your address for a while.
402budget_exhaustedYour key's monthly cap, or the API's, is reached.
404model_not_foundThe model or path does not exist.
413request_too_largeThe request body is over 1 MB.
422model_not_servedThe model exists but is not offered on this API.
429rate_limit_exceededToo many requests this minute; wait the seconds in Retry-After.
502Every provider for the model failed; retry later.
503service_unavailableThe API is paused.

Examples

curl:

curl https://api.chrouter.ch/v1/chat/completions \
  -H "Authorization: Bearer $CHROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "general_text", "messages": [{"role": "user", "content": "Hello"}]}'

Python (pip install openai):

import os
from openai import OpenAI

client = OpenAI(base_url="https://api.chrouter.ch/v1", api_key=os.environ["CHROUTER_API_KEY"])
reply = client.chat.completions.create(
    model="general_text",
    messages=[{"role": "user", "content": "Hello"}],
)
print(reply.choices[0].message.content)

JavaScript (npm install openai):

import OpenAI from 'openai';

const client = new OpenAI({ baseURL: 'https://api.chrouter.ch/v1', apiKey: process.env.CHROUTER_API_KEY });
const stream = await client.chat.completions.create({
  model: 'general_text',
  messages: [{ role: 'user', content: 'Hello' }],
  stream: true,
});
for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content || '');