Chat completions

The main text endpoint. OpenAI-compatible, and it reaches every text model in the catalogue.

POSThttps://your-instance.com/v1/chat/completions

Send a conversation as a list of messages and get the next one back. This is the endpoint to reach for unless you specifically need a provider's native format — every text model is available here, including Claude and Gemini models, translated to and from the OpenAI shape for you.

Request body

  • modelstringrequired

    Model to use. Call GET /v1/models for the names this instance serves.

  • messagesobject[]required

    The conversation so far. Each entry has a role of system, user, assistant or tool, and content.

  • streambooleandefault: false

    Stream the reply as server-sent events instead of waiting for the whole completion.

  • toolsobject[]

    Function definitions the model may call. See the tool calling section.

  • tool_choicestring | objectdefault: "auto"

    Force or forbid tool use: "none", "auto", "required", or a specific function.

  • response_formatobject

    Set to {"type": "json_object"} to constrain output to valid JSON.

  • temperaturenumberdefault: 1

    Sampling temperature between 0 and 2. Lower is more deterministic.

  • top_pnumberdefault: 1

    Nucleus sampling. Consider setting this or temperature, not both.

  • max_tokensinteger

    Upper bound on generated tokens. The request fails if the prompt plus this exceeds the model's context window.

  • stopstring | string[]

    Up to four sequences that end generation when produced.

Example

curl https://your-instance.com/v1/chat/completions \
  -H "Authorization: Bearer $CLAWROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-5",
    "messages": [
      {"role": "system", "content": "You are concise."},
      {"role": "user", "content": "Why is the sky blue?"}
    ]
  }'

Response

200 OK
{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "created": 1750000000,
  "model": "claude-sonnet-5",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "Rayleigh scattering..." },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 24,
    "completion_tokens": 61,
    "total_tokens": 85
  }
}

Images in a prompt

Multimodal models accept image parts inside a user message. Pass a URL the provider can fetch, or inline the bytes as a data URI.

JSON
{
  "model": "claude-sonnet-5",
  "messages": [
    {
      "role": "user",
      "content": [
        { "type": "text", "text": "What is in this image?" },
        {
          "type": "image_url",
          "image_url": { "url": "data:image/jpeg;base64,/9j/4AAQ..." }
        }
      ]
    }
  ]
}

Tool calling

Describe the functions the model may call. When it chooses one, the reply carries tool_calls instead of content, and you run the function and send the result back as a tool message.

Python
tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Current weather for a city",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]

response = client.chat.completions.create(
    model="claude-sonnet-5",
    messages=[{"role": "user", "content": "Weather in Taipei?"}],
    tools=tools,
)

call = response.choices[0].message.tool_calls[0]
print(call.function.name, call.function.arguments)