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
llmgw_thinkingboolean网关扩展字段,显式开启 thinking/reasoning

多模态输入

图片输入使用 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文本输出
choices[].message.reasoning_content上游返回的思考内容,存在时透传
usagetoken 用量

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

text
data: [DONE]

边界

边界说明
模型能力文本模型不能传图片
thinking默认不强制注入 /no_think;需要思考时传 llmgw_thinking: true 或 prompt 显式包含 /think
reasoning只有上游返回 reasoning 字段时才会出现
流式超时客户端应设置较长 read timeout

示例

bash
curl -N https://llm.lytokens.com/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.