创建消息(Messages)
创建 Claude / Anthropic Messages 兼容请求(Claude Code 使用的形态),供当前目录中的 Claude 模型使用,支持流式与非流式。其他模型请走 /v1/chat/completions。模型被发送到不支持的端点时,会在调用任何模型之前被拒绝:400 invalid_request_error,消息为 model '<id>' must be called via /v1/chat/completions。错误体采用 Anthropic 外层结构 {"type":"error","error":{type,message,code},"request_id"},不是其他端点的 OpenAI {"error":{…}} 形状。 function 工具按原样转发(`tools` 带 `input_schema`、`tool_choice`;`tool_use` / `tool_result` 块可往返)。Anthropic 服务端工具:`web_search` 与 `code_execution`(含 `bash_*` / `text_editor_*` 子工具与跨轮次容器复用)被接受并按该模型标准 token 费率计量(容器时长不按次透传计费);`web_fetch`、`mcp_toolset`、`mcp_servers` 会在调用任何模型之前被拒绝,返回 400 invalid_request_error。
使用 API Key 进行认证。在 Router One 控制台获取你的 API Key,格式为 sk-xxx。
In: header
模型 ID。设为 auto 时由 Router One 自动选择,也可以指定具体模型。大多数不带厂商前缀的官方模型名(如 gpt-5.5、claude-sonnet-5)可作为目录 ID 的别名使用;稳妥起见请从 /models 复制目录 ID。
Claude / Anthropic Messages 格式的对话消息。
1 <= items可选系统提示词。
最大输出 token 数。
1 <= value是否启用流式响应。
false采样温度,范围 0-2。
10 <= value <= 2Anthropic 工具声明,按原样转发。function 工具带 input_schema;服务端工具 web_search 与 code_execution 被接受,web_fetch 与 mcp_toolset 会被拒绝并返回 400 invalid_request_error。
模型如何使用已声明的工具(auto、any、tool、none),按原样转发。
Response Body
application/json
application/json
application/json
application/json
application/json
application/json
curl -X POST "https://api.router.one/v1/messages" \ -H "Content-Type: application/json" \ -d '{ "model": "auto", "max_tokens": 1024, "messages": [ { "role": "user", "content": "你好" } ] }'{
"id": "msg_abc123",
"type": "message",
"role": "assistant",
"model": "anthropic/claude-sonnet-5",
"content": [
{
"type": "text",
"text": "你好!有什么我可以帮你的吗?"
}
],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 9,
"output_tokens": 12
}
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "model 'openai/gpt-5.5' must be called via /v1/chat/completions",
"code": "INVALID_REQUEST"
}
}{
"type": "error",
"error": {
"type": "authentication_error",
"message": "invalid api key",
"code": "AUTH_INVALID_API_KEY"
},
"request_id": "86bc1f64e4bcdfc3cc516e51cc419418"
}{
"type": "error",
"error": {
"type": "billing_error",
"message": "insufficient balance: top up at https://router.one/deposit"
}
}{
"type": "error",
"error": {
"type": "rate_limit_error",
"message": "rate limit exceeded",
"code": "RATE_LIMIT_EXCEEDED"
},
"request_id": "86bc1f64e4bcdfc3cc516e51cc419418"
}{
"type": "error",
"error": {
"type": "api_error",
"message": "internal error",
"code": "INTERNAL_ERROR"
},
"request_id": "86bc1f64e4bcdfc3cc516e51cc419418"
}