API Reference
Chat Completions
OpenAI-compatible chat completions API
Create Chat Completion
Generate a model response for the given conversation.
POST /v1/chat/completionsRequest Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer sk-r9k-your-key |
Content-Type | Yes | application/json |
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID (e.g. gpt-4o, claude-3-sonnet, auto) |
messages | array | Yes | Conversation messages |
stream | boolean | No | Enable streaming (default: false) |
temperature | number | No | Sampling temperature (0-2) |
max_tokens | number | No | Maximum tokens to generate |
Messages Format
{
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Hello!" }
]
}Example Request
curl https://api.router9.com/v1/chat/completions \
-H "Authorization: Bearer sk-r9k-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{ "role": "user", "content": "Explain quantum computing in one sentence." }
]
}'Response
{
"id": "chatcmpl-abc123",
"object": "text_completion",
"created": 1714000000,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Quantum computing uses quantum mechanical phenomena like superposition and entanglement to process information in ways classical computers cannot."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 15,
"completion_tokens": 28,
"total_tokens": 43
}
}Streaming
Set stream: true to receive responses as Server-Sent Events (SSE).
curl https://api.router9.com/v1/chat/completions \
-H "Authorization: Bearer sk-r9k-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [{ "role": "user", "content": "Hello!" }],
"stream": true
}'The response is a stream of data: lines:
data: {"id":"chatcmpl-abc","choices":[{"delta":{"role":"assistant"},"index":0}]}
data: {"id":"chatcmpl-abc","choices":[{"delta":{"content":"Hello"},"index":0}]}
data: {"id":"chatcmpl-abc","choices":[{"delta":{"content":"!"},"index":0}]}
data: [DONE]Token usage is included in the final chunk before [DONE].
Auto Model
Set model to "auto" and Router9 will automatically select the best available model.
{
"model": "auto",
"messages": [{ "role": "user", "content": "Hello!" }]
}