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

创建聊天补全

创建一个聊天补全请求:OpenAI Chat Completions 兼容端点,一个 base URL 接入 30+ 模型,支持流式和非流式响应,model: auto 走智能路由。

设置 model 为 auto 时,Router One 会按当前网关策略从服务端候选集中选择。

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

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

POST
/v1/chat/completions
AuthorizationBearer <token>

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

In: header

modelstring

模型 ID。设置为 auto 时按网关策略使用服务端候选集,也可指定具体模型如 openai/gpt-5.5、anthropic/claude-sonnet-5 等(模型 ID 以目录为准)。大多数不带厂商前缀的官方模型名(如 gpt-5.5、claude-sonnet-5)可作为目录 ID 的别名使用;稳妥起见请从 /models 复制目录 ID。

messages

聊天消息列表,按时间顺序排列。

Items1 <= items
stream?boolean

是否启用流式响应。启用后返回 SSE 事件流。

Defaultfalse
temperature?number

采样温度,范围 0-2。较高的值(如 0.8)使输出更随机,较低的值(如 0.2)使输出更确定。

Default1
Range0 <= value <= 2
max_tokens?integer

生成的最大 token 数量。推理模型的思考 token 也计入这个上限,请留足余量。

Range1 <= value
max_completion_tokens?integer

max_tokens 在 OpenAI 现行规范中的名称,含义相同,任选其一即可。两者同时传入时以 max_completion_tokens 为准。

Range1 <= value
top_p?number

核采样参数。模型考虑概率质量前 top_p 的 token 结果。

Default1
Range0 <= value <= 1
reasoning_effort?string

推理强度提示,如 low、medium、high。按原值转发给模型,Router One 不校验、不改写该值;唯一例外是 Claude Opus 5.5(claude-opus-5-5 或 anthropic/claude-opus-5.5),该值会映射到 Anthropic 的 output_config.effort:none 与 minimal 记为 low,low 到 max 原样写入,其他取值忽略。支持程度因模型而异:没有该控制项的模型会忽略它或返回 400 invalid_request,使用前先查该模型的目录页。

stream_options?

流式响应选项。仅在 stream: true 时有效。

web_search_options?object

托管联网搜索,仅 google/gemini-3-flash 接受:传 {}(或等价的 tools: [{"type": "google_search"}] 加 tool_choice: "auto"),由模型决定是否搜索;实际引用的来源以 url_citation annotations 返回(非流式在 choices[0].message.annotations,流式在 choices[0].delta.annotations),按该模型 token 单价计费。其他模型上该字段按原样转发,由模型自身校验。

tools?

可供模型调用的工具(函数)声明。支持程度因模型而异,使用前先查该模型的目录页。在 google/gemini-3-flash 上数组还可以包含 {"type": "google_search"}(托管搜索,见 web_search_options)。

tool_choice?string|

控制模型如何选择工具。auto 由模型自行决定,none 关闭工具调用,required 强制调用某个工具,传对象并指定函数名则强制调用该函数。模型是否接受强制选择由厂商决定;对 Claude Opus 5.5(claude-opus-5-5 或 anthropic/claude-opus-5.5),Router One 会把 required 或指定函数按 auto 发送,模型可能直接用文字回答;要从它拿 JSON,请在 /v1/messages 上用 output_config.format。

response_format?

转发给模型的输出格式提示。json_object 要求模型回复 JSON;json_schema 额外附带一份 JSON Schema。Router One 只校验请求形状——type 为 json_schema 而缺少 json_schema.name 或 json_schema.schema 时,在到达模型前即返回 400 invalid_request——不校验、不修复模型输出。Schema 是否被强制执行取决于模型,支持程度因模型而异,请用目标模型实测。对 Claude 系列 ID,这个字段不是拿到 JSON 的可靠方式——请改在 /v1/messages 上用 output_config.format。详见结构化输出指南。

Response Body

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://api.router.one/v1/chat/completions" \  -H "Content-Type: application/json" \  -d '{    "model": "auto",    "messages": [      {        "role": "user",        "content": "你好"      }    ]  }'
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1700000000,
  "model": "anthropic/claude-sonnet-4.6",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "你好!有什么我可以帮你的吗?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 9,
    "completion_tokens": 12,
    "total_tokens": 21
  }
}
{
  "error": {
    "message": "response_format.json_schema.name is required",
    "type": "invalid_request_error",
    "code": "INVALID_REQUEST",
    "request_id": "290dd478f91d8aec68f7535e871376eb"
  }
}
{
  "error": {
    "message": "invalid api key",
    "type": "authentication_error",
    "code": "AUTH_INVALID_API_KEY",
    "request_id": "290dd478f91d8aec68f7535e871376eb"
  }
}

{
  "error": {
    "message": "insufficient balance: top up at https://router.one/deposit",
    "type": "billing_error",
    "code": "INSUFFICIENT_BALANCE",
    "request_id": "290dd478f91d8aec68f7535e871376eb"
  }
}

{
  "error": {
    "message": "rate limit exceeded",
    "type": "rate_limit_error",
    "code": "RATE_LIMIT_EXCEEDED",
    "request_id": "290dd478f91d8aec68f7535e871376eb"
  }
}
{
  "error": {
    "message": "internal error",
    "type": "api_error",
    "code": "INTERNAL_ERROR",
    "request_id": "290dd478f91d8aec68f7535e871376eb"
  }
}