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_url and 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 typeAccepted 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 WebSocketAlso accepts the subprotocol Sec-WebSocket-Protocol: tts, bearer.<key>
Account management /x-*Authorization header only
Public endpointsGET /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

LevelConditionTypical endpoints
Any accountValid key and enabled accountModel calls, /dashboard/*, POST /x-self
ManagerSub-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/json or multipart/form-data correctly.
  • Compressed request bodies: Content-Encoding: gzip, deflate, br, and zstd are 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 the currency field of GET /user/balance returns USD or CNY accordingly.
  • Field casing: requests and responses of /x-users and /x-dna use PascalCase (for example CreditGranted); /dashboard/*, /x-pricing, and /x-bill use snake_case. Follow each page exactly.
  • Pagination: account lists accept page and size (at most 8192 per page) and return the total in the X-Total-Count response header; the size of /dashboard/logs is 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 example Unauthorized); 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-sign returns JSON in a {"success", "message", "data"} structure.
  • Accounts that trigger the risk guard receive 403 with a JSON error body; see Errors.

Endpoint index

EndpointDescriptionDocumentation
POST /v1/chat/completions, /v1/responses, /v1/messages, /v1/embeddings, /v1/images/*, /v1/audio/*, /v1/videos/*, Gemini /v1beta/models/*, and moreModel callsRouter API
GET /v1/models, GET /user/balanceModel catalog and balanceRouter API
Responses WebSocket, Realtime, Live, DeepSeek speech synthesisLong-lived connections and realtime voiceWebSocket and Realtime APIs
Status codes and error textError handlingErrors
GET /x-pricingPricing catalogPricing Catalog API
GET /dashboard/status, /info, /live, /bill, /logs, /news, GET /x-billAccount status and usageAccount and Usage API
/x-users, /x-dna, /x-users/batch-credit, /x-self, /x-newsSub-accounts, credit, and noticesAccount Management API
/x-signSelf sign-upSign-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"}]
  }'