Using the DeepSeek API Suite

XAI Router passes DeepSeek requests through as they are: the request body is forwarded unchanged (only model is rewritten when a model mapping applies) and the response is returned unchanged. Every parameter and response field in the DeepSeek documentation works as documented, including safety_check, title, latest_reminder, deepseek_web_search and deepseek_read_url.

Every path works with or without the /v1 prefix. Authenticate with Authorization: Bearer $API_KEY or x-api-key: $API_KEY.

Endpoints

APIPathBilling model
Chat CompletionsPOST /v1/chat/completionsdeepseek-flash
ResponsesPOST /v1/responsessame
Messages (Anthropic format)POST /v1/messages, POST /v1/messages/count_tokenssame
Web searchPOST /v1/tools/searchdeepseek-search
Web fetchPOST /v1/tools/fetchdeepseek-fetch
OCRPOST /v1/tools/ocrdeepseek-ocr
Text to speechPOST /v1/tools/tts, or a WebSocket on the same pathdeepseek-tts
Speech recognitionPOST /v1/tools/asrdeepseek-asr
FilesPOST /v1/files, GET /v1/files, GET /v1/files/{id}, DELETE /v1/files/{id}deepseek-files for parsed documents
BalanceGET /user/balancefree

Chat and web tools

All three protocols support the server-side web tools. A Chat Completions example:

curl $BASE_URL/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-flash",
    "thinking": {"type": "enabled"},
    "tools": [{"type": "deepseek_web_search"}, {"type": "deepseek_read_url"}],
    "messages": [{"role": "user", "content": "What is new in DeepSeek V4.1?"}],
    "stream": true
  }'

Billing follows the final usage the upstream reports: input, cache-hit and output tokens, plus web tool calls. The call count is the sum of tool_search, tool_fetch and tool_image_search in usage.server_tool_use, charged at the model's Query price.

Billing units of the tool endpoints

Billing modelUnitDefault price
deepseek-searcheach search that returned results$0.005
deepseek-fetcheach successful fetch$0.005
deepseek-ocrrecognised pages$0.0015 per page
deepseek-ttscharacters; a Han character counts as 2$3 per 10,000 characters
deepseek-asraudio seconds, rounded up$0.78 per hour
deepseek-filesparsed pages, estimated from file size$0.0015 per page

A search without results and a failed request are not charged.

Files

Uploading, referencing, retrieving and deleting work as in the DeepSeek documentation, in both the OpenAI and the Anthropic format. The Anthropic format needs the header anthropic-beta: files-api-2025-04-14.

curl $BASE_URL/v1/files \
  -H "Authorization: Bearer $API_KEY" \
  -F purpose="text_recognition" \
  -F file="@report.pdf"

Things to know:

  • A file belongs to the user who uploaded it. Other users cannot list, retrieve, delete or reference it in a conversation; they get a 400.
  • Document parsing is charged by pages estimated from size. An upload with text_recognition or rich_layout_recognition counts one page per 10 KiB, at least 1 page and at most 1000. An upload with user_data is free.
  • A listing contains the files uploaded in the same format. Files uploaded in the OpenAI format appear in OpenAI-format listings, and likewise for the Anthropic format. Retrieving, deleting and referencing by id are not limited this way.
  • Listings do not support the before_id parameter.

Text-to-speech WebSocket

Connect to wss://<your XAI host>/v1/tools/tts; the messages are the same as in the DeepSeek documentation. There are two ways to authenticate:

  • the header Authorization: Bearer $API_KEY;
  • where a browser cannot set headers, the subprotocol Sec-WebSocket-Protocol: tts, bearer.$API_KEY.

A session is charged by the characters sent.

Balance

GET /user/balance returns your XAI balance in DeepSeek's format:

{
  "is_available": true,
  "balance_infos": [
    {"currency": "USD", "total_balance": "110.00", "granted_balance": "0.00", "topped_up_balance": "110.00"}
  ]
}

currency is the one the console shows: USD when the account's billing factor is 1, CNY otherwise.

Notes for administrators

  • After a key with the provider https://api.deepseek.com is added, deepseek* is mapped to its group automatically. Every billing model in the tables above matches that rule.
  • A file upload with user_data and a file listing carry no model, so they are routed by the model name files. If the groups hold several providers, map files to the group that has DeepSeek.
  • One user's files stay in one upstream account, and a conversation that references files is sent to that account.
  • The file registry is kept in Redis for 3 years after a user's last upload by default; set FILE_REGISTRY_TTL to change it. Deleting a user removes the registry and the files upstream.
  • The default prices can be changed in the pricing settings. Web tools inside a conversation are charged at the Query price of deepseek-flash, by default the same as deepseek-search.
  • The billing models of the tools and of document parsing are valid on their own endpoints only: they cannot be used on the chat endpoints or replaced through a model mapping; such a request gets a 400.