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
| API | Path | Billing model |
|---|---|---|
| Chat Completions | POST /v1/chat/completions | deepseek-flash |
| Responses | POST /v1/responses | same |
| Messages (Anthropic format) | POST /v1/messages, POST /v1/messages/count_tokens | same |
| Web search | POST /v1/tools/search | deepseek-search |
| Web fetch | POST /v1/tools/fetch | deepseek-fetch |
| OCR | POST /v1/tools/ocr | deepseek-ocr |
| Text to speech | POST /v1/tools/tts, or a WebSocket on the same path | deepseek-tts |
| Speech recognition | POST /v1/tools/asr | deepseek-asr |
| Files | POST /v1/files, GET /v1/files, GET /v1/files/{id}, DELETE /v1/files/{id} | deepseek-files for parsed documents |
| Balance | GET /user/balance | free |
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 model | Unit | Default price |
|---|---|---|
deepseek-search | each search that returned results | $0.005 |
deepseek-fetch | each successful fetch | $0.005 |
deepseek-ocr | recognised pages | $0.0015 per page |
deepseek-tts | characters; a Han character counts as 2 | $3 per 10,000 characters |
deepseek-asr | audio seconds, rounded up | $0.78 per hour |
deepseek-files | parsed 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_recognitionorrich_layout_recognitioncounts one page per 10 KiB, at least 1 page and at most 1000. An upload withuser_datais 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_idparameter.
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.comis added,deepseek*is mapped to its group automatically. Every billing model in the tables above matches that rule. - A file upload with
user_dataand a file listing carry no model, so they are routed by the model namefiles. If the groups hold several providers, mapfilesto 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_TTLto 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
Queryprice ofdeepseek-flash, by default the same asdeepseek-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.