Router API
Router API
Connect
export BASE_URL="https://api.xaicontrol.com"
export API_KEY="sk-Xvs..."Every request except GET /x-pricing requires:
Authorization: Bearer sk-Xvs...Model APIs
The Router preserves the request and response formats used by mainstream SDKs. In most cases, you only need to change base_url and api_key.
OpenAI-compatible
| Capability | Stable path |
|---|---|
| Chat Completions | POST /v1/chat/completions |
| Responses | POST /v1/responses |
| Response compaction | POST /v1/responses/compact |
| Embeddings | POST /v1/embeddings |
| Image generation and edits | POST /v1/images/generations, POST /v1/images/edits |
| Image variations | POST /v1/images/variations |
| Video generation | POST /v1/videos/generations |
| Audio transcription and translation | POST /v1/audio/transcriptions, POST /v1/audio/translations |
| Moderations | POST /v1/moderations |
| Files and Threads | /v1/files, /v1/threads |
| Realtime | GET /v1/realtime (WebSocket) |
| Realtime client secrets | POST /v1/realtime/client_secrets |
| Model list | GET /v1/models |
Response retrieval, cancellation, and subresources use /v1/responses/{id}. Compatibility aliases /chat/completions, /responses, /embeddings, and /models remain available; new integrations should use /v1/*.
Anthropic-compatible
| Capability | Stable path |
|---|---|
| Messages | POST /v1/messages |
| Token counting | POST /v1/messages/count_tokens |
Native Gemini format
Gemini SDK model paths are supported:
POST /v1beta/models/{model}:generateContent
POST /v1beta/models/{model}:streamGenerateContent?alt=sseChat Completions example
curl "$BASE_URL/v1/chat/completions" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5-nano",
"messages": [{"role": "user", "content": "Reply with OK only"}],
"stream": false
}'For streaming output, set "stream": true and consume the SSE data: events line by line.
OpenAI SDK
from openai import OpenAI
client = OpenAI(base_url="https://api.xaicontrol.com/v1", api_key="sk-Xvs...")
response = client.responses.create(model="gpt-5-nano", input="Reply with OK only")
print(response.output_text)Query APIs
| Method and path | Description | Authentication |
|---|---|---|
GET /v1/models | Models available to the current account | API Key |
GET /x-pricing | Public pricing catalog | Optional |
GET /dashboard/status | Account status, balance, and management capability | API Key |
GET /dashboard/info | Account configuration and limits | API Key |
When /x-pricing is called with an API Key, it includes the effective prices for that account. Without a key, it returns public prices.
See the Usage API for query parameters, response structures, and examples.
Common status codes
| Status | Meaning |
|---|---|
400 | Invalid request body, model, or parameter |
401 | Missing or invalid API Key |
403 | Account, model, IP, or endpoint access is restricted |
413 | Request body is too large |
429 | Request, token, or credit limit reached |
502 / 503 | Upstream temporarily unavailable; retry with backoff |
Retry guidance
- Retry only
429,502,503, and network failures, with a finite limit. - Use exponential backoff with jitter.
- Do not automatically replay non-idempotent image or video generation requests.
- Log the HTTP status and response body, never a complete API Key.