Router9
Documentation
API Reference

Chat Completions

OpenAI-compatible chat completions API

Create Chat Completion

Generate a model response for the given conversation.

POST /v1/chat/completions

Request Headers

HeaderRequiredDescription
AuthorizationYesBearer sk-r9k-your-key
Content-TypeYesapplication/json

Request Body

ParameterTypeRequiredDescription
modelstringYesModel ID (e.g. gpt-4o, claude-3-sonnet, auto)
messagesarrayYesConversation messages
streambooleanNoEnable streaming (default: false)
temperaturenumberNoSampling temperature (0-2)
max_tokensnumberNoMaximum 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!" }]
}

On this page