Chat
Create Chat Completion
创建一个聊天补全请求。兼容 OpenAI Chat Completions API 格式,支持流式和非流式响应。 设置 `model` 为 `auto` 时,Router One 将根据路由策略自动选择最佳模型。
AuthorizationBearer <token>
使用 API Key 进行认证。在 Router One 控制台获取你的 API Key,格式为 sk-xxx。
In: header
modelstring
模型 ID。设置为 auto 时由 Router One 智能路由选择最佳模型,也可指定具体模型如 gpt-4o、claude-sonnet-4-20250514 等。
messagesarray<ChatMessage>
聊天消息列表,按时间顺序排列。
Items
1 <= itemsstream?boolean
是否启用流式响应。启用后返回 SSE 事件流。
Default
falsetemperature?number
采样温度,范围 0-2。较高的值(如 0.8)使输出更随机,较低的值(如 0.2)使输出更确定。
Default
1Range
0 <= value <= 2max_tokens?integer
生成的最大 token 数量。
Range
1 <= valuetop_p?number
核采样参数。模型考虑概率质量前 top_p 的 token 结果。
Default
1Range
0 <= value <= 1stream_options?object
流式响应选项。仅在 stream: true 时有效。
Response Body
curl -X POST "https://gateway.routerone.ai/v1/chat/completions" \ -H "Content-Type: application/json" \ -d '{ "model": "auto", "messages": [ { "role": "user", "content": "你好" } ] }'{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1700000000,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!有什么我可以帮你的吗?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
}{
"error": {
"message": "Invalid API key",
"type": "authentication_error",
"code": "invalid_api_key"
}
}{
"error": {
"message": "Insufficient balance",
"type": "billing_error",
"code": "insufficient_balance"
}
}{
"error": {
"message": "Rate limit exceeded",
"type": "rate_limit_error",
"code": "rate_limit_exceeded"
}
}{
"error": {
"message": "string",
"type": "string",
"code": "string"
}
}