Create a chat completion (OpenAI-compatible)

Use one OpenAI-compatible Chat Completions endpoint to call models such as Claude and Gemini.

POST /v1/chat/completions

Auth: {'type': 'bearer', 'prefix': 'sk-', 'description': 'Pass your API key in the `Authorization: Bearer sk-xxx` header.'}

Unified chat completion interface, request/response structure identical to OpenAI. Projects using the OpenAI SDK can simply replace `baseURL` to switch. - Supports `stream: true` stream-based push (SSE) - `messages[].content` supports string or multi-modal arrays (text + image URL) - Tool calling (tools/function calling) follows OpenAI specifications

Request body

modelstringrequiredThe ID of the model to be called. ⚠️ First call GET /v1/models to retrieve the available list; do not rely on memory — the gateway may not expose the same IDs as upstream providers. IDs must be lowercase, hyphen-separated, and space-free (kimi-k3 instead of Kimi K3)
messagesarrayrequiredList of conversation messages, each containing role and content. The role can be system / user / assistant / tool.
    rolestringrequired
    contentstringrequiredMessage content (string, or a multimodal array `[{"type":"text","text":"..."},{"type":"image_url","image_url":{"url":"..."}}]`)
    namestring(Optional) Identifier of the message author
    tool_call_idstring(Only when role=tool) The corresponding tool_call id
streambooleanWhether to stream the response. When set to true, the response is pushed in chunks via SSE, suitable for scenarios requiring real-time display during generation.
temperaturenumberSampling temperature; higher values produce more diverse outputs, lower values produce more stable ones. ⚠️ Inference models (gpt-5 / o series) only accept the default value; passing other values will not result in errors but will be ignored; other models work normally.
max_tokensintegerMaximum number of tokens to generate in this response. Omitted means the model decides autonomously and will not be truncated.
top_pnumberNucleus sampling, selecting candidates from the top top_p cumulative probability. Only one of temperature or nucleus sampling should be used. ⚠️ Inference models (gpt-5 / o series) do not support this parameter; passing it will not result in errors but will be ignored; other models work normally.
toolsarrayList of available tools that the model can call. When needed, the model will return tool_calls, which you then execute and feed back as a tool call with role=tool.
tool_choicestringControl whether and how to use tools: auto (model decides), none (disable), or specify a specific tool. Must be used together with tools.
response_formatobjectSpecify the output format, e.g., return in JSON format.
stoparrayStop generation upon encountering any of the specified strings; the strings will not appear in the result. ⚠️ Inference models (gpt-5 / o series) do not support this parameter; passing it will not result in errors but will be ignored; other models work normally.
nintegerNumber of candidate responses to return per request. Billing is based on the total token count across all candidates.
seedintegerFixed random seed; ensures consistent output for the same input.
frequency_penaltynumberReduce the probability of a token reappearing based on its frequency of occurrence; used to suppress repetition. ⚠️ Inference models (gpt-5 / o series) do not support this parameter; passing it will not result in errors but will be ignored; other models work normally.
presence_penaltynumberReduce the probability of a token reappearing based on whether it has already appeared; used to encourage topic switching. ⚠️ Inference models (gpt-5 / o series) do not support this parameter; passing it will not result in errors but will be ignored; other models work normally.
logit_biasobjectAdjust the selection probability of a token by its token ID; can be used to strongly promote or suppress specific words. ⚠️ Inference models (gpt-5 / o series) do not support this parameter; passing it will not result in errors but will be ignored; other models work normally.
parallel_tool_callsbooleanWhether to allow the model to return multiple tool calls in one response. Must be used together with tools.
logprobsbooleanWhether to return the log probability of the selected token. ⚠️ Inference models (gpt-5 / o series) do not support this parameter; passing it will not result in errors but will be ignored; other models work normally.
top_logprobsintegerHow many additional candidate token probabilities to return per position. Must be enabled together with logprobs. ⚠️ Inference models (gpt-5 / o series) do not support this parameter; passing it will not result in errors but will be ignored; other models work normally.
max_completion_tokensintegerOutput token limit (including inference process tokens + visible output tokens). ⚠️ If set too low for inference models, thinking may consume all quota, resulting in empty main text —— in this case finish_reason=length and completion_tokens equals completion_tokens_details.reasoning_tokens. For short responses, reduce reasoning_effort accordingly. Some newer models use this field instead of max_tokens.
reasoning_effortstringInference strength. ⚠️ Values vary by model; this gateway does not provide a unified list: gpt-5.6 is empirically supported as none / low / medium / high / xhigh (minimal is not supported), other inference models may differ. Passing unsupported values will return 400 from upstream, with error details listing supported values for the model — check and retry accordingly. For short responses without being consumed by thinking, use the lowest supported level (e.g., none fully disables thinking). Only effective for inference models.
verbositystringLevel of detail in the response.
modalitiesarrayExpected output modality, such as text only or text plus audio. Only effective for multimodal models. ⚠️ Inference models (gpt-5 / o series) do not support this parameter; passing it will not cause errors but will have no effect; other models work normally.
audioobjectAudio output settings, such as voice tone and audio format. Must include audio in modalities. ⚠️ Inference models (gpt-5 / o series) do not support this parameter; passing it will not cause errors but will have no effect; other models work normally.
predictionobjectOutput prediction. When most of the response is known, providing this can accelerate generation. ⚠️ Inference models (gpt-5 / o series) do not support this parameter; passing it will not cause errors but will have no effect; other models work normally.
stream_optionsobjectStreaming-related settings, such as whether to include usage statistics at the last frame. Requires stream=true.
storebooleanWhether the conversation is retained on the model service side.
metadataobjectCustom key-value pairs, which will be sent along with the request for your own classification and retrieval.
userstringIdentifier for the end-user, to help differentiate your user sources.
prompt_cache_keystringPrompt caching key. Requests with the same prefix using the same key are more likely to hit cache, resulting in faster and more efficient retrieval.
prompt_cache_retentionstringDuration for which prompt cache is retained.

Responses

Example

curl https://api.router.ai/v1/chat/completions \
  -H "Authorization: Bearer sk-xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "messages": [
      {"role": "system", "content": "你是一位资深的技术写作助手"},
      {"role": "user", "content": "用三句话介绍 Redis"}
    ],
    "temperature": 0.7,
    "max_tokens": 512
  }'

API reference