Skip to content

Chat Completions

接口:

text
POST /v1/chat/completions

SDK:

python
client.chat.completions.create(...)

请求字段

字段类型必填说明
modelstring使用 /v1/models 返回的模型 ID
messagesarrayOpenAI Chat messages
max_tokensnumber最大输出 token 数
temperaturenumber采样温度
top_pnumber核采样参数
streambooleantrue 时返回 SSE
stream_options.include_usageboolean流式输出结束时包含 usage
toolsarrayOpenAI function tools
tool_choicestring/object支持常见 OpenAI tool choice
enable_thinkingboolean兼容 Qwen 官方字段,显式控制 thinking/reasoning;OpenAI SDK 可放在 extra_body
llmgw_thinkingboolean网关扩展字段,显式开启或关闭 thinking/reasoning
response_formatobject{"type":"json_object"} / JSON schema,控制输出格式
stopstring/array停止序列
seedinteger采样种子(上游支持时生效)
reasoning_effortstring推理强度,如 low/medium/high(上游支持时生效)

多模态输入

图片输入使用 OpenAI 标准 content parts:

json
{
  "role": "user",
  "content": [
    {"type": "text", "text": "这张图里有什么?"},
    {"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
  ]
}

也支持 data:image/...;base64,...。请先用 /v1/model-catalog/{model} 判断模型是否包含 modalities.input: ["image"]

响应字段

非流式返回 OpenAI chat.completion 对象:

字段说明
id请求 ID
objectchat.completion
model实际响应模型
choices[].message.content文本输出;仅返回 tool_calls 时为 null
choices[].message.tool_calls工具调用数组({id,type:"function",function:{name,arguments}}),无工具调用时不返回
choices[].message.reasoning_content仅流式响应返回上游思考内容;非流式响应不返回该字段
choices[].finish_reason停止原因:stoplengthtool_calls
usagetoken 用量

流式返回 chat.completion.chunk SSE,最后一帧为:

text
data: [DONE]

边界

边界说明
模型能力文本模型不能传图片
thinking网关扩展 llmgw_thinking / OpenAI enable_thinking(bool)按模型转换:qwen3.*enable_thinkingdeepseek-v4-*/think/no_think 指令;glm-*thinking 对象;其他模型(kimi/minimax 等)该 bool 无效,需用模型原生 thinking 对象控制
reasoning只有上游返回 reasoning 字段时才会出现
流式超时客户端应设置较长 read timeout

示例

bash
curl -N https://llm.xiaoyue9527.xyz/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer sk-gtw-REPLACE_ME' \
  --data-raw '{
    "model": "qwen3.6-plus",
    "messages": [{"role": "user", "content": "解释什么是 RESTful API"}],
    "max_tokens": 2048,
    "stream": true,
    "stream_options": {"include_usage": true}
  }'

OpenAI-compatible API documentation.