Chat Completions 差异

与 OpenAI 官方 Chat Completions 对齐:SDK 里把 base_url 换成 https://api.model-r.com/v1 就能用,官方字段绝大多数按官方语义工作。需要留意的差异集中在四件事:托管工具不在此接口、少数官方字段默认不发给模型、流末 usage 块的开关、图片只支持 URL。

支持清单

✅ 按官方语义支持(行为不同处在说明里加注);⊘ 不支持(说明写明实际发生什么)。

特性状态说明
顶层字段
model ✅ 填模型名称,以 /v1/models 返回为准
messages ✅ 至少一条;system / developer 读作指令,assistant 可带 tool_calls,tool 消息读作函数结果,其余角色原样保留
max_completion_tokens / max_tokens ✅ 同一输出上限的两种写法,新写法优先
temperature / top_p / stop / seed ✅ 采样参数;stop 接受字符串或数组
reasoning_effort ✅ 七档 + none,见总览页「推理控制」
parallel_tool_calls ✅ 原样发给模型
stream_options.include_usage ✅ 控制流末是否补一个只含 usage 的块,见下文
response_format(JSON 模式) ⊘ 默认不发给模型,设置不生效,见下文
其余官方字段 ⊘ frequency_penalty、presence_penalty、logprobs、store、audio 等同样默认不发给模型
消息内容(content 数组里的部件)
text 部件 ✅ 文本
image_url 部件 ✅ 只支持 URL(链接)写法,见下文
其它 type 的部件 ⊘ 不认识的部分被跳过,请求不失败
工具类型
function ✅ 嵌套(function.name)与平铺(name)两种写法都收
托管工具(如 web_search) ⊘ 返回 400,报错指路 /v1/responses,见下文
响应形态
流式 SSE ✅ 以 data: [DONE] 结束(官方语义)
非流式 JSON ✅ 完整响应对象,带 usage

与官方的差异

托管工具要用 Responses 接口

web_search、file_search 这类由平台执行的托管工具在 Chat 接口不可用,发出即返回 400,报错信息会指路。

请求

{
  "model": "your-model",
  "messages": [{ "role": "user", "content": "搜索一下今天的新闻" }],
  "tools": [{ "type": "web_search" }]
}

返回

{
  "error": {
    "type": "invalid_request_error",
    "message": "Chat Completions only supports 'function' tools; hosted tools (e.g. web_search) require the /v1/responses endpoint"
  },
  "request_id": "req-…"
}

要用托管工具,改走 /v1/responses(见 Responses 页);在 Chat 接口里定义自己的 function 工具不受影响。

response_format 等字段默认不发给模型

JSON 模式(response_format)以及 frequency_penalty、presence_penalty、logprobs、store、audio 这些官方字段,平台默认不转发给模型:请求不会失败,但这些设置不生效。

请求

{
  "model": "your-model",
  "messages": [{ "role": "user", "content": "把下面的数据整理成 JSON" }],
  "response_format": { "type": "json_object" }
}

返回(JSON 模式未生效,模型按提示自行回答)

{
  "choices": [
    {
      "message": { "role": "assistant", "content": "{ \"ok\": true }" },
      "finish_reason": "stop"
    }
  ],
  "usage": { "prompt_tokens": 14, "completion_tokens": 6, "total_tokens": 20 }
}

需要保证 JSON 输出时在提示里明确要求;确有需要开启这些字段可联系平台。

流末 usage 块由 include_usage 控制

官方语义:流式请求带 stream_options.include_usage: true 时,流结束前补一个只含 usage 的块(choices 为空数组),随后是 data: [DONE]。

请求

{
  "model": "your-model",
  "messages": [{ "role": "user", "content": "你好" }],
  "stream": true,
  "stream_options": { "include_usage": true }
}

返回(流的最后两帧)

data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[],"usage":{"prompt_tokens":9,"completion_tokens":6,"total_tokens":15}}
 
data: [DONE]

图片只支持 URL 写法

content 数组里的 image_url 部件只支持直接给链接的写法;没有 base64 内嵌的变体。

请求

{
  "model": "your-model",
  "messages": [
    {
      "role": "user",
      "content": [
        { "type": "text", "text": "这张图里是什么" },
        { "type": "image_url", "image_url": { "url": "https://example.com/cat.png" } }
      ]
    }
  ]
}

要发本地图片,先上传到可访问的地址再给链接;需要 base64 直传时用 Messages 或 Responses 平台函数 接口(都支持)。