Skip to content

Chat Completions

Chat Completions 是最常用的对话接口,适合普通聊天、编程助手、摘要、分类、工具调用和多轮对话。

POST /v1/chat/completions

完整地址:

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": "请用一句话介绍 RouteAPI" }
]
}'
字段类型必填说明
modelstring模型 ID,必须是当前账户可用模型
messagesarray对话消息列表
streamboolean是否使用 SSE 流式输出
temperaturenumber采样温度
top_pnumbernucleus sampling 参数
max_tokensnumber最大输出 token 数
toolsarray工具定义
tool_choicestring/object工具选择策略
response_formatobjectJSON mode 或 JSON Schema
stream_optionsobject流式输出附加选项
[
{ "role": "system", "content": "你是一个严谨的技术助手。" },
{ "role": "user", "content": "解释什么是 API 网关。" }
]

常见 role:

Role说明
system系统提示词
user用户输入
assistant模型历史回复
tool工具调用结果
{
"id": "chatcmpl_xxx",
"object": "chat.completion",
"created": 1730000000,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "RouteAPI 是一个统一管理多家 AI 模型供应商的 API 网关。"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 18,
"total_tokens": 42
}
}
  • 同一个参数在不同模型服务中的支持程度可能不同。
  • 如果请求包含 toolsresponse_formatstream_options 等可选参数,请先确认所选模型支持对应能力。
  • 明确传入 0false 的可选参数应被视为用户显式设置。