Chat completions · OpenAI compatible
Call text models using unified messages, with streaming, tools and multimodal input where supported.
/v1/chat/completionshttps://api.hanrouter.ai/v1Manage API keysURL and authentication
Use https://api.hanrouter.ai/v1 as the OpenAI-compatible Base URL and Authorization: Bearer $HANROUTER_API_KEY. Do not duplicate /v1. All manufacturers use your HanRouter key, not an upstream vendor key.
For the Anthropic SDK and Claude Code, use https://api.hanrouter.ai without /v1; the client appends /v1/messages. Use the OpenAI-compatible interface for Google models.
Verify available models
List models available to your key first, then copy data[].id exactly into requests. Names, case and aliases come from this response. The public plaza hides unpriced models; backend availability is unchanged.
curl "https://api.hanrouter.ai/v1/models" \
-H "Authorization: Bearer $HANROUTER_API_KEY"Streaming and response
Read choices[0].message.content for text or tool_calls for tools; return tool results using role: tool. Streaming reads choices[].delta until [DONE]. Parameters vary; reasoning models may reject sampling options.
Request parameters
model- Required string: exact model ID available to your key.
messages- Required array: messages containing role and content.
stream- Optional boolean: SSE streaming; default false.
temperature- Optional number: only for models supporting sampling temperature.
max_completion_tokens- Optional integer: output limit, possibly including reasoning tokens.
tools- Optional array: tool definitions; the app executes tools and returns results.
response_format- Optional object: JSON or other supported output formats.
Request example
Examples use configured model IDs. Key group permissions determine access; query GET /v1/models first.
curl -X POST "https://api.hanrouter.ai/v1/chat/completions" \
-H "Authorization: Bearer $HANROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "your-model-id",
"messages": [
{
"role": "user",
"content": "Hello"
}
],
"stream": false
}'Response example
{
"object": "chat.completion",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello!"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 8,
"completion_tokens": 3,
"total_tokens": 11
}
}