对话补全 (Chat)
通义千问 Qwen 系列
Qwen 通用、Coder 与长上下文模型
适用模型
| 模型 | 上下文 | 最大输出 |
|---|---|---|
qwen3.7-max | 1,000,000 | 64,000 |
qwen3.6-35b-a3b | 262,144 | 64,000 |
qwen3.6-27b | 1,000,000 | 64,000 |
qwen3-coder-plus | 1,000,000 | 64,000 |
qwen3-max | 262,144 | 64,000 |
qwen-plus | 1,000,000 | 64,000 |
公开协议
通义千问官方同时提供 DashScope 原生接口和 OpenAI 兼容接口。LoopToken 对外采用官方 OpenAI 兼容形态:POST /v1/chat/completions。
from openai import OpenAI
client = OpenAI(base_url="https://api.vibelab.me/v1", api_key="sk-lt-...")
response = client.chat.completions.create(
model="qwen3-coder-plus",
messages=[{"role": "user", "content": "写一个带超时的 Go HTTP 客户端"}],
max_tokens=2048,
)
print(response.choices[0].message.content)支持通用页列出的流式输出、工具调用和 JSON 输出字段。不同级别模型的上下文和输出限制不同,但请求结构相同,因此合并在本页。
请求参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
model | string | 是 | - | 本页适用模型之一 |
messages | array | 是 | - | 对话消息列表,至少包含一条消息 |
messages[].role | string | 是 | - | system、user、assistant 或 tool |
messages[].content | string/array | 是 | - | 文本或多模态内容块 |
stream | boolean | 否 | false | 是否启用 SSE 流式输出 |
max_tokens | integer | 否 | 模型默认 | 最大输出 Token 数 |
temperature | number | 否 | 1 | 采样温度,建议范围 [0, 2) |
top_p | number | 否 | 1 | 核采样阈值,范围 (0, 1] |
stop | string/array | 否 | - | 停止序列 |
tools | array | 否 | - | 函数工具列表 |
tool_choice | string/object | 否 | auto | auto、none 或指定工具 |
parallel_tool_calls | boolean | 否 | true | 是否允许并行工具调用 |
response_format | object | 否 | {"type":"text"} | 可设置 json_object |
seed | integer | 否 | - | 随机种子 |
响应参数
| 参数 | 类型 | 说明 |
|---|---|---|
id | string | 请求 ID |
object | string | chat.completion 或 chat.completion.chunk |
created | integer | Unix 时间戳 |
model | string | 模型名称 |
choices[].index | integer | 候选结果序号 |
choices[].message | object | 非流式助手消息 |
choices[].delta | object | 流式增量消息 |
choices[].finish_reason | string | 停止原因 |
usage.prompt_tokens | integer | 输入 Token 数 |
usage.completion_tokens | integer | 输出 Token 数 |
usage.total_tokens | integer | 总 Token 数 |
{
"id": "chatcmpl_01H...",
"object": "chat.completion",
"created": 1783819200,
"model": "qwen3-coder-plus",
"choices": [{
"index": 0,
"message": {"role": "assistant", "content": "package main\n\n// ..."},
"finish_reason": "stop"
}],
"usage": {"prompt_tokens": 24, "completion_tokens": 96, "total_tokens": 120}
}错误响应格式及状态码见错误码。