Skip to content

Chat Completions

Generates a model response from a chat history. Uses the industry-standard Chat Completions protocol format — mainstream SDKs work as drop-in.

POST https://wrouter.ai/v1/chat/completions

Headers

HeaderRequiredNotes
AuthorizationBearer sk-...
Content-Typeapplication/json

Body parameters

ParameterTypeRequiredDescription
modelstringe.g. gpt-4o, claude-sonnet-4-5, gemini-2.5-pro, deepseek-chat
messagesarrayConversation history (see below)
temperaturenumber0–2, default 1
top_pnumber0–1
nintegerDefault 1
streambooleanEnable SSE streaming
stream_optionsobjecte.g. {"include_usage": true}
stopstring | string[]Stop sequences
max_tokensinteger
max_completion_tokensintegerFor o-series reasoning models
presence_penaltynumber-2 to 2
frequency_penaltynumber-2 to 2
logit_biasobject
userstringEnd-user identifier
toolsarrayFunction-calling definitions
tool_choicestring | object"auto" | "none" | "required" | specific function
response_formatobjecte.g. {"type":"json_object"} or a JSON Schema
seedintegerDeterministic sampling
reasoning_effortstring"low" | "medium" | "high" for reasoning models
modalitiesarraye.g. ["text","audio"]
audioobjectAudio output options

messages structure

json
[
  {"role": "system", "content": "You are a helpful assistant."},
  {"role": "user", "content": "Hi"},
  {"role": "assistant", "content": "Hello!"},
  {"role": "user", "content": [
    {"type": "text", "text": "Describe this image"},
    {"type": "image_url", "image_url": {"url": "https://..."}}
  ]}
]

rolesystem | user | assistant | tool. content is a string or a multimodal array (text / image_url / input_audio).

Response (non-streaming)

json
{
  "id": "chatcmpl-xxx",
  "object": "chat.completion",
  "created": 1718000000,
  "model": "gpt-4o-2024-08-06",
  "choices": [
    {"index": 0, "message": {"role": "assistant", "content": "Hello!"}, "finish_reason": "stop"}
  ],
  "usage": {"prompt_tokens": 12, "completion_tokens": 6, "total_tokens": 18}
}

Response (streaming SSE)

With stream: true responses are text/event-stream:

data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"He"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","choices":[{"index":0,"delta":{"content":"llo"}}]}
data: [DONE]

Setting stream_options.include_usage = true adds a final usage chunk before [DONE].

Examples

curl

bash
curl https://wrouter.ai/v1/chat/completions \
  -H "Authorization: Bearer $WROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [{"role":"user","content":"Introduce WRouter in one sentence."}],
    "temperature": 0.7
  }'

Python (streaming + tools)

python
from openai import OpenAI
client = OpenAI(api_key="sk-...", base_url="https://wrouter.ai/v1")

tools = [{
  "type": "function",
  "function": {
    "name": "get_weather",
    "description": "Look up weather",
    "parameters": {"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}
  }
}]

stream = client.chat.completions.create(
    model="claude-sonnet-4-5",
    messages=[{"role":"user","content":"Weather in Shanghai?"}],
    tools=tools,
    stream=True,
)
for chunk in stream:
    delta = chunk.choices[0].delta
    if delta.content:
        print(delta.content, end="", flush=True)

Calling Claude / Gemini

Swap model:

FamilySample IDs
OpenAIgpt-4o, gpt-4o-mini, gpt-5, o3-mini
Anthropicclaude-sonnet-4-5, claude-opus-4-1, claude-haiku-4-5
Googlegemini-2.5-pro, gemini-2.5-flash
DeepSeekdeepseek-chat, deepseek-reasoner
Qwenqwen-max, qwen-plus, qwen3-coder
Doubaodoubao-1-5-pro-256k, doubao-seed-1-6

Full list at https://wrouter.ai/models.

Errors

See Errors.