API reference
The SwitchRouter HTTP API. Chat completions, models and the wallet use an API key; account, key management and usage aggregation use a browser session.
Authentication
Send your API key as a bearer token. Requests without a valid key return 401.
Authorization: Bearer sk_sr_…POST /v1/chat/completions
Creates an OpenAI-compatible chat completion, streaming or non-streaming. Requires an API key. Requests are validated against model capabilities and routed to a configured upstream deployment; unknown parameters are rejected.
curl https://api.switchrouter.dev/v1/chat/completions \
-H "Authorization: Bearer $SWITCHROUTER_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Title: My App" \
-d '{
"model": "deepseek.v3.2",
"messages": [
{ "role": "system", "content": "You are concise." },
{ "role": "user", "content": "Hello" }
],
"temperature": 0.7,
"max_tokens": 256
}'{
"id": "req_...",
"object": "chat.completion",
"created": 1790961677,
"model": "deepseek.v3.2",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "Hello!" },
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 3,
"total_tokens": 15
}
}POST /v1/messages
Native Anthropic Messages wire protocol endpoint for Anthropic SDKs and coding harnesses such as Claude Code. Accepts either x-api-key: sk_sr_… or Authorization: Bearer sk_sr_…, supports streaming SSE events, tool use, and Connect virtual aliases such as switchrouter/auto. See SwitchRouter Connect & CLI for setup examples.
POST /v1/responses
OpenAI Responses wire protocol endpoint used by Codex CLI and newer OpenAI client integrations. Supports bearer authentication, streaming responses, tool calling, and both explicit model IDs and Connect virtual aliases.
Chat parameters
| Field | Type | Notes |
|---|---|---|
| model | string | Required. A model ID from GET /v1/models. |
| messages | array | Required. Roles system, user, assistant, tool. Content may be text or image parts. |
| stream | boolean | Server-Sent Events. Requires a model with the streaming capability. |
| stream_options.include_usage | boolean | Adds a final chunk with token usage. |
| temperature | number | 0–2. |
| top_p | number | 0–1. |
| max_tokens / max_completion_tokens | integer | Positive integer. |
| stop | string | string[] | Up to 4 sequences. |
| response_format | object | text, json_object or json_schema. Requires structured output support. |
| tools / tool_choice | array / enum | Function tools. Requires tool-calling support. tool_choice is auto, none, required or a function. |
| n | integer | Only n = 1 is supported. |
Any other field is rejected with 400 unsupported_parameter.
Streaming format
Streaming responses are text/event-stream. Each event is a chat.completion.chunk; the stream ends with data: [DONE].
data: {"id":"req_...","object":"chat.completion.chunk","model":"deepseek.v3.2","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"req_...","object":"chat.completion.chunk","model":"deepseek.v3.2","choices":[{"index":0,"delta":{"content":"Hel"},"finish_reason":null}]}
data: {"id":"req_...","object":"chat.completion.chunk","model":"deepseek.v3.2","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]GET /v1/models
Public model catalogue with capabilities, modalities, context window and NGN pricing. No authentication required.
curl https://api.switchrouter.dev/v1/models
curl https://api.switchrouter.dev/v1/models/deepseek.v3.2GET /v1/models/:id
One model, or 404 model_not_found. See Models for the response fields.
Wallet
Wallet reads and funding use an API key and are scoped to the key’s workspace. Amounts are NGN integer minor units (kobo).
curl https://api.switchrouter.dev/v1/wallet \
-H "Authorization: Bearer $SWITCHROUTER_API_KEY"GET /v1/auth/context
Verifies an API key and returns its resolved workspace context — useful as a connectivity check.
curl https://api.switchrouter.dev/v1/auth/context \
-H "Authorization: Bearer $SWITCHROUTER_API_KEY"Console (session) endpoints
These are used by the Console with a browser session (HttpOnly cookie), not an API key:
- /v1/api-keys — create, list and revoke keys.
- /v1/workspaces — workspaces, wallet and payment status.
- /v1/usage, /v1/usage/summary, /v1/usage/series, /v1/usage/by-model, /v1/usage/by-api-key — usage aggregation.
Errors and request IDs
Errors use the OpenAI envelope with a stable code and the request ID.
{
"error": {
"message": "The parameter \"presence_penalty\" is not supported.",
"type": "invalid_request_error",
"code": "unsupported_parameter",
"request_id": "req_..."
}
}| Status | Typical code | Meaning |
|---|---|---|
| 400 | invalid_request / unsupported_parameter / unsupported_capability | The request or the model’s capabilities don’t match. |
| 401 | invalid_api_key | Missing, revoked or expired credential. |
| 402 | insufficient_balance | Fund the workspace wallet. |
| 404 | model_not_found | Unknown model ID. |
| 429 | rate_limited | Respect the retry-after-* header. |
| 502 / 503 | provider_error / provider_unavailable | Upstream provider problem; retry with backoff. |