Skip to content

Chat Completions

Chat Completions is the most commonly used conversation API. It is suitable for chat, coding assistants, summarization, classification, tool calling, and multi-turn conversations.

POST /v1/chat/completions

Full URL:

https://www.routeapi.ai/v1/chat/completions
Terminal window
curl https://www.routeapi.ai/v1/chat/completions \
-H "Authorization: Bearer $ROUTEAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{ "role": "user", "content": "Introduce RouteAPI in one sentence" }
]
}'
FieldTypeRequiredDescription
modelstringYesModel ID, must be available to the current account
messagesarrayYesConversation message list
streambooleanNoWhether to use SSE streaming output
temperaturenumberNoSampling temperature
top_pnumberNonucleus sampling parameter
max_tokensnumberNoMaximum output token count
toolsarrayNoTool definitions
tool_choicestring/objectNoTool choice strategy
response_formatobjectNoJSON mode or JSON Schema
stream_optionsobjectNoExtra streaming output options
[
{ "role": "system", "content": "You are a rigorous technical assistant." },
{ "role": "user", "content": "Explain what an API gateway is." }
]

Common roles:

RoleDescription
systemSystem prompt
userUser input
assistantHistorical model response
toolTool call result
{
"id": "chatcmpl_xxx",
"object": "chat.completion",
"created": 1730000000,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "RouteAPI is an API gateway for unified access to multiple AI model services."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 18,
"total_tokens": 42
}
}
  • The same parameter may be supported differently by different model services.
  • If the request includes optional parameters such as tools, response_format, or stream_options, confirm that the selected model supports the corresponding capability first.
  • Optional parameters explicitly passed as 0 or false should be treated as user-provided values.