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.
Endpoint
Section titled “Endpoint”POST /v1/chat/completionsFull URL:
https://www.routeapi.ai/v1/chat/completionsRequest example
Section titled “Request example”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" } ] }'Request parameters
Section titled “Request parameters”| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID, must be available to the current account |
messages | array | Yes | Conversation message list |
stream | boolean | No | Whether to use SSE streaming output |
temperature | number | No | Sampling temperature |
top_p | number | No | nucleus sampling parameter |
max_tokens | number | No | Maximum output token count |
tools | array | No | Tool definitions |
tool_choice | string/object | No | Tool choice strategy |
response_format | object | No | JSON mode or JSON Schema |
stream_options | object | No | Extra streaming output options |
messages format
Section titled “messages format”[ { "role": "system", "content": "You are a rigorous technical assistant." }, { "role": "user", "content": "Explain what an API gateway is." }]Common roles:
| Role | Description |
|---|---|
system | System prompt |
user | User input |
assistant | Historical model response |
tool | Tool call result |
Response example
Section titled “Response example”{ "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 }}Compatibility notes
Section titled “Compatibility notes”- The same parameter may be supported differently by different model services.
- If the request includes optional parameters such as
tools,response_format, orstream_options, confirm that the selected model supports the corresponding capability first. - Optional parameters explicitly passed as
0orfalseshould be treated as user-provided values.