API reference
Use an OpenAI SDK or make HTTPS requests directly. Your API key is the credential for every request.
Authentication
Bearer authentication is recommended. The API also accepts x-api-key and x-goog-api-key for compatible clients.
Authorization: Bearer $HANROUTER_API_KEYx-api-key: $HANROUTER_API_KEYx-goog-api-key: $HANROUTER_API_KEYCore endpoints
GET
/v1/modelsList the model IDs currently available to this key.
POST
/v1/chat/completionsGenerate a model response from a message list.
Direct HTTP request
Use the same Base URL and API key without an SDK.
GET /v1/models
curl https://www.hanrouter.com/v1/models \
-H "Authorization: Bearer $HANROUTER_API_KEY"POST /v1/chat/completions
curl https://www.hanrouter.com/v1/chat/completions \
-H "Authorization: Bearer $HANROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "your-model-id",
"messages": [
{ "role": "user", "content": "Explain this API in one sentence." }
],
"temperature": 0.2
}'Streaming response
Set stream to true to receive Server-Sent Events. Read each delta as it arrives and wait for the final completion event.
cURL
curl -N https://www.hanrouter.com/v1/chat/completions \
-H "Authorization: Bearer $HANROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "your-model-id",
"messages": [{ "role": "user", "content": "Write a short greeting." }],
"stream": true
}'Errors and retries
Do not retry authentication failures. For rate-limit or transient upstream failures, use exponential backoff and preserve the request ID in your logs.
StatusGuidance
401Check that the key is active, complete, and sent in one supported header.429Reduce concurrency, wait briefly, then retry with exponential backoff.5xxRetry only idempotent or safely repeatable work after a short delay.