API
Chat Completions
The OpenAI-compatible /v1/chat/completions endpoint.
POST /v1/chat/completions is a drop-in implementation of the OpenAI Chat Completions API. Any OpenAI SDK or HTTP client works unchanged after a base URL swap.
Request
bash
curl https://api.tokenrouter.io/v1/chat/completions \
-H "Authorization: Bearer tr_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-5-mini",
"messages": [
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "What is an AI gateway?"}
],
"temperature": 0.7,
"max_tokens": 200
}'Response
json
{
"id": "chatcmpl-9f3a1b2c",
"object": "chat.completion",
"created": 1754400000,
"model": "openai/gpt-5-mini",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "An AI gateway is a single API layer that sits between your apps and model providers..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 27,
"completion_tokens": 42,
"total_tokens": 69
}
}Streaming
Set "stream": true to receive Server-Sent Events. Each event is a chat.completion.chunk; the stream terminates with a literal data: [DONE] line.
bash
curl -N https://api.tokenrouter.io/v1/chat/completions \
-H "Authorization: Bearer tr_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-sonnet-4-5",
"stream": true,
"stream_options": {"include_usage": true},
"messages": [{"role": "user", "content": "Write a haiku about budgets."}]
}'text
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hard"}}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" caps"}}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[],"usage":{"prompt_tokens":14,"completion_tokens":19,"total_tokens":33}}
data: [DONE]With stream_options.include_usage set, the final chunk before [DONE] carries the full usage object and an empty choices array — exactly like OpenAI.
Tool calling
json
{
"model": "openai/gpt-5-mini",
"messages": [{"role": "user", "content": "What is the weather in Berlin?"}],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string"}
},
"required": ["city"]
}
}
}
],
"tool_choice": "auto"
}Tool calls come back in choices[0].message.tool_calls; return results as role: "tool" messages. Tool calling is translated natively for every provider that supports it.
Reasoning models from the DeepSeek family return their chain-of-thought in
message.reasoning_content (and delta.reasoning_content while streaming), matching DeepSeek’s API shape.