跳到主要内容
注册
跳到主要内容
Router One
对话生成

创建消息(Messages)

创建 Claude / Anthropic Messages 兼容请求(Claude Code 使用的形态),供当前目录中的 Claude 系列模型与 DeepSeek ID 使用,支持流式与非流式。其他对话模型请走 /v1/chat/completions。模型被发送到不支持的端点时,会在调用任何模型之前被拒绝:400 invalid_request_error,消息为 model '<id>' must be called via /v1/chat/completions。错误体采用 Anthropic 外层结构 {"type":"error","error":{type,message,code}},不是其他端点的 OpenAI {"error":{…}} 形状;网关自身返回的错误(例如 401、429)另带顶层 request_id,每个响应都带 X-Request-ID 响应头。

function 工具按原样转发(tools 带 input_schema、tool_choice;tool_use / tool_result 块可往返);只有 Claude Opus 5.5(claude-opus-5-5 或 anthropic/claude-opus-5.5)例外:对这个模型,tool_choice 的 any 或 tool 会按 auto 发送,模型可能直接用文字回答而不调用工具。模型是否接受强制 tool_choice 由厂商决定(见 Anthropic 的工具调用文档,2026-10-09 核对)。Anthropic 服务端工具:web_search 与 code_execution(含 bash_* / text_editor_* 子工具与跨轮次容器复用)被接受并按该模型公示的 token 单价计量(容器时长不按次透传计费);web_fetch、mcp_toolset、mcp_servers 会在调用任何模型之前被拒绝,返回 400 invalid_request_error。

耗时较长的 stream: false 调用会保持连接(截至 2026-10-09):约 25 秒后网关先提交 HTTP 200,并在 Message 就绪前写入 JSON 前导空白,此后的失败以 HTTP 200 加上述错误外层结构返回——先判断 type,再读 content;需要几分钟的生成请用 stream: true。

全部端点的完整参考:Markdown 版 · OpenAPI 3.1 JSON

POST
/v1/messages
AuthorizationBearer <token>

使用 API Key 进行认证。在 Router One 控制台获取你的 API Key,格式为 sk-xxx。

In: header

modelstring

模型 ID。设为 auto 时由 Router One 自动选择,也可以指定具体模型。大多数不带厂商前缀的官方模型名(如 gpt-5.5、claude-sonnet-5)可作为目录 ID 的别名使用;稳妥起见请从 /models 复制目录 ID。

messages

Claude / Anthropic Messages 格式的对话消息。

Items1 <= items
system?string

可选系统提示词。

max_tokensinteger

最大输出 token 数。

Range1 <= value
stream?boolean

是否启用流式响应。

Defaultfalse
temperature?number

采样温度,范围 0-2。

Default1
Range0 <= value <= 2
tools?

Anthropic 工具声明,按原样转发。function 工具带 input_schema;服务端工具 web_search 与 code_execution 被接受,web_fetch 与 mcp_toolset 会被拒绝并返回 400 invalid_request_error。

tool_choice?object

模型如何使用已声明的工具(auto、any、tool、none),按原样转发——Claude Opus 5.5(claude-opus-5-5 或 anthropic/claude-opus-5.5)除外:对这个模型 any 与 tool 会按 auto 发送,所以要检查 stop_reason 和内容块类型;模型是否接受强制选择由厂商决定。

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"
}