SwitchRouterDocumentation
Dashboard

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.

header
Authorization: Bearer sk_sr_…
API keys are workspace-scoped. A key never grants access to another workspace.

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.

request
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
  }'
response · 200
{
  "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

FieldTypeNotes
modelstringRequired. A model ID from GET /v1/models.
messagesarrayRequired. Roles system, user, assistant, tool. Content may be text or image parts.
streambooleanServer-Sent Events. Requires a model with the streaming capability.
stream_options.include_usagebooleanAdds a final chunk with token usage.
temperaturenumber0–2.
top_pnumber0–1.
max_tokens / max_completion_tokensintegerPositive integer.
stopstring | string[]Up to 4 sequences.
response_formatobjecttext, json_object or json_schema. Requires structured output support.
tools / tool_choicearray / enumFunction tools. Requires tool-calling support. tool_choice is auto, none, required or a function.
nintegerOnly 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].

sse
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
curl https://api.switchrouter.dev/v1/models
curl https://api.switchrouter.dev/v1/models/deepseek.v3.2

GET /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
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
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 · 400
{
  "error": {
    "message": "The parameter \"presence_penalty\" is not supported.",
    "type": "invalid_request_error",
    "code": "unsupported_parameter",
    "request_id": "req_..."
  }
}
StatusTypical codeMeaning
400invalid_request / unsupported_parameter / unsupported_capabilityThe request or the model’s capabilities don’t match.
401invalid_api_keyMissing, revoked or expired credential.
402insufficient_balanceFund the workspace wallet.
404model_not_foundUnknown model ID.
429rate_limitedRespect the retry-after-* header.
502 / 503provider_error / provider_unavailableUpstream provider problem; retry with backoff.

Start building with SwitchRouter.

Connect your app or coding agent in seconds. Route across frontier models through one endpoint — then launch your app and start building what's next.

Start building