CloseRouter

Chat Completions

Send a request to POST /chat/completions and read the response in this API’s format.

Request

curl
export CLOSEROUTER_API_KEY="closerouter_your_key"

curl https://api.closerouter.dev/v1/chat/completions \
  -H "Authorization: Bearer $CLOSEROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-5.4-mini",
    "messages": [
      { "role": "user", "content": "Reply with exactly: ok" }
    ],
    "max_tokens": 16
  }'

Response

Abbreviated response example.

JSON
{
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "ok"
      }
    }
  ]
}

Main parameters

FieldPurpose
modelModel ID from the catalog. Parameter support depends on the provider and API.
messagesMessages in this API’s format.
max_tokensOutput token limit. Required for Messages.
streamtrue enables streaming when supported by the endpoint.
userOptional identifier for your end user.

Streaming

Events arrive as data: {...} lines; the stream ends with data: [DONE].

curl
curl -N https://api.closerouter.dev/v1/chat/completions \
  -H "Authorization: Bearer $CLOSEROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-haiku-4.5",
    "messages": [
      { "role": "user", "content": "Reply with exactly: ok" }
    ],
    "max_tokens": 16,
    "stream": true
  }'

Fallback models

The models field accepts fallback candidates. Access restrictions apply to the entire list.

Related settings