An OpenAI-compatible chat endpoint. Any OpenAI client library works by changing its base URL and API key.
| Base URL | https://api.chrouter.ch/v1 |
|---|---|
| Authentication | Authorization: Bearer chr_… - the key you were given. |
| Endpoints | POST /v1/chat/completions (streaming and not)GET /v1/models |
Pass a routing name as model; it picks a model and falls back to the next one if a provider fails:
general_textgeneral_text_smartA specific model id also works. GET /v1/models lists every name your key can use. Text chat only.
x-ratelimit-limit-requests and x-ratelimit-remaining-requests show where you stand.max_tokens is capped at 4096 per request and applied when you send none.In OpenAI's shape: {"error": {"message", "type", "code"}}.
| Status | code | Meaning |
|---|---|---|
| 400 | The request is malformed (for example, messages missing). | |
| 401 | invalid_api_key | No key, a wrong key, or a revoked key. Repeated failures block your address for a while. |
| 402 | budget_exhausted | Your key's monthly cap, or the API's, is reached. |
| 404 | model_not_found | The model or path does not exist. |
| 413 | request_too_large | The request body is over 1 MB. |
| 422 | model_not_served | The model exists but is not offered on this API. |
| 429 | rate_limit_exceeded | Too many requests this minute; wait the seconds in Retry-After. |
| 502 | Every provider for the model failed; retry later. | |
| 503 | service_unavailable | The API is paused. |
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 || '');