Chat Completions

Create a model response for single- or multi-turn conversations. This is the most commonly used endpoint and is compatible with the OpenAI Chat Completions protocol.

Basics

MethodPOST Endpointhttps://koprouter.kopglobal.com/v1/chat/completions AuthenticationAuthorization: Bearer sk-...

Request Parameters

Parameter Type Required Description
model string Yes Model ID from the id returned by /v1/models
messages array Yes Conversation messages, each with role and content
temperature number No Sampling temperature, range 0-2, default 1
top_p number No Nucleus sampling probability, range 0-1
max_tokens number No Maximum tokens to generate
stream boolean No Stream the response, default false
stop string/array No Stop sequences
tools array No Tool definitions for tool calling
tool_choice string/object No Tool calling strategy, e.g. auto, none
response_format object No Output format constraint, e.g. JSON mode
n number No Number of candidates per request

Example Request

curl https://koprouter.kopglobal.com/v1/chat/completions \
  -H "Authorization: Bearer sk-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MODEL_ID",
    "messages": [
      { "role": "system", "content": "You are a helpful assistant." },
      { "role": "user", "content": "Hello, introduce yourself." }
    ],
    "temperature": 0.7
  }'

Example Response

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1720000000,
  "model": "MODEL_ID",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! I'm an AI assistant."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 18,
    "completion_tokens": 12,
    "total_tokens": 30
  }
}

Streaming

With stream: true, the response is returned as Server-Sent Events (SSE), with each chunk shaped like:

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}

data: [DONE]
With an official SDK, just pass `stream: true` and the SSE chunks are parsed for you — no need to handle `data:` lines manually. `prompt_tokens` and `completion_tokens` in `usage` drive billing: each count is multiplied by the corresponding unit price.