API Reference
XAI Router exposes two families of APIs on a single HTTP endpoint:
- Router API: model access. It keeps the native request and response formats of OpenAI, Anthropic, Gemini, and other protocols; replace
base_urland the API Key and you are connected. - Account APIs: balance and usage queries, the pricing catalog, self sign-up, and account management for sub-account distribution. Paths start with
/x-or/dashboard/.
This reference lists only stable, customer-facing APIs. Paths and fields that are not listed are outside the compatibility scope.
Base URL
export BASE_URL="https://api.xairouter.com"
export API_KEY="sk-Xvs..."BASE_URL has no /v1. Model endpoints are normally written as $BASE_URL/v1/.... For the OpenAI SDK, base_url is usually $BASE_URL/v1; for the Anthropic SDK, it is $BASE_URL.
Authentication
Every API uses the API Key of an XAI account. Keys start with sk-Xvs and are 51 characters long; a key in the wrong format is rejected.
| API type | Accepted credential locations |
|---|---|
Model calls and /dashboard/* | Authorization: Bearer <key>, x-api-key: <key>, x-goog-api-key: <key> (the first non-empty value in this order wins) |
| DeepSeek speech synthesis WebSocket | Also accepts the subprotocol Sec-WebSocket-Protocol: tts, bearer.<key> |
Account management /x-* | Authorization header only |
| Public endpoints | GET /x-pricing and /x-sign/* need no authentication |
- Passing the key in a query parameter (for example Gemini-style
?key=) is not supported. - Before forwarding, the Router strips all of your credential headers and then writes the upstream credential; your API Key is never sent to model providers.
Permission levels
| Level | Condition | Typical endpoints |
|---|---|---|
| Any account | Valid key and enabled account | Model calls, /dashboard/*, POST /x-self |
| Manager | Sub-account capability (user_limit above 0 or existing sub-accounts), daily token limit above 800000000, and a balance above the management threshold | /x-users, /x-dna, /x-bill, /dashboard/logs |
The manage field of GET /dashboard/status tells you whether the current account is a manager, and user_api_balance gives the balance threshold.
Conventions
- Encoding: requests and responses are UTF-8. Set
Content-Type: application/jsonormultipart/form-datacorrectly. - Compressed request bodies:
Content-Encoding: gzip,deflate,br, andzstdare supported and decompressed before forwarding. - Request body limit: exceeding it generally returns
413; Realtime calls, Live, signup and similar endpoints document their own response. - Dates: query parameters use
YYYY-MM-DD, interpreted on the service business date; times in responses are RFC 3339. - Currency: balances, charges, and prices are in US dollars (USD). Accounts whose price factor (
factor) is not 1 settle in yuan, and thecurrencyfield ofGET /user/balancereturnsUSDorCNYaccordingly. - Field casing: requests and responses of
/x-usersand/x-dnause PascalCase (for exampleCreditGranted);/dashboard/*,/x-pricing, and/x-billuse snake_case. Follow each page exactly. - Pagination: account lists accept
pageandsize(at most 8192 per page) and return the total in theX-Total-Countresponse header; thesizeof/dashboard/logsis 1 to 100 and its total is returned in the JSON body. - Management call fee: some account queries and updates charge a small management call fee per call, recorded in the bill under the model name
XAPI. See each endpoint.
Error format
- Errors generated by the Router itself are single-line
text/plain(for exampleUnauthorized); the HTTP status code carries the error class. - Errors returned by model providers pass through unchanged, keeping their status code and JSON structure.
- The sign-up API
/x-signreturns JSON in a{"success", "message", "data"}structure. - Accounts that trigger the risk guard receive
403with a JSON error body; see Errors.
Endpoint index
| Endpoint | Description | Documentation |
|---|---|---|
POST /v1/chat/completions, /v1/responses, /v1/messages, /v1/embeddings, /v1/images/*, /v1/audio/*, /v1/videos/*, Gemini /v1beta/models/*, and more | Model calls | Router API |
GET /v1/models, GET /user/balance | Model catalog and balance | Router API |
| Responses WebSocket, Realtime, Live, DeepSeek speech synthesis | Long-lived connections and realtime voice | WebSocket and Realtime APIs |
| Status codes and error text | Error handling | Errors |
GET /x-pricing | Pricing catalog | Pricing Catalog API |
GET /dashboard/status, /info, /live, /bill, /logs, /news, GET /x-bill | Account status and usage | Account and Usage API |
/x-users, /x-dna, /x-users/batch-credit, /x-self, /x-news | Sub-accounts, credit, and notices | Account Management API |
/x-sign | Self sign-up | Sign-up API |
Minimal example
curl "$BASE_URL/v1/chat/completions" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6.2-sol",
"messages": [{"role": "user", "content": "Hello"}]
}'