千问系列
qwen3.7-max / qwen3.7-plus 的 bytestream 接入指南
本页覆盖 qwen3.7-max / qwen3.7-plus 在 bytestream 网关(https://aiapi.bytestream.com.cn/)下的完整接入
方式:全部请求参数、千问专属的思考模式(enable_thinking / thinking_budget)与联网搜索、响应结构差异,
附 5 组端到端请求组合示例。通用的鉴权、端点与错误码约定见 通用说明。
| 调用端点 | 可用模型 | 请求组合示例 |
|---|---|---|
| 1 | 2 | 5 |
概览
bytestream 通过 dashscope 渠道对接阿里云百炼通义千问系列模型,使用其 OpenAI 兼容模式,将请求转换为上游
POST /compatible-mode/v1/chat/completions 调用。可用模型:
- qwen3.7-max · 旗舰档位
- qwen3.7-plus · 均衡档位
qwen3.7-max: 该系列能力上限最高的档位,长上下文、复杂推理与工具调用表现最好;支持思考模式与联网 搜索。适合 Agent 编排、长文档分析等重任务。
qwen3.7-plus: 均衡档位,单价与延迟显著低于 max,能力覆盖多数日常场景(问答、改写、结构化抽取),
是批量线上流量的默认选择;参数集与 max 一致,可直接切换 model 做成本降级。
鉴权
请求头携带 Authorization: Bearer sk-xxxxxxxx(sk- 前缀可省略)。令牌需在「控制台 → 令牌管理」中绑定
可访问 qwen3.7-max / qwen3.7-plus 的分组。
调用端点
| 端点 | 请求体 | 响应 | 适用场景 |
|---|---|---|---|
POST /v1/chat/completions | JSON | chat.completion / SSE chunk | 全部 OpenAI 兼容调用方 |
01 · 请求参数详解
顶层参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 必填 | qwen3.7-max 或 qwen3.7-plus。 |
messages | array<object> | 必填 | 对话消息数组,role 取值 system / user / assistant / tool;content 支持字符串或多模态内容数组。 |
stream | boolean | 可选 | 是否流式返回,默认 false。 |
stream_options | object | 可选 | { "include_usage": true } 可在最后一个 chunk 中带回 usage。 |
temperature | number | 可选 | 采样温度,范围 [0, 2),默认约 0.7。 |
top_p | number | 可选 | 核采样阈值,(0, 1.0) 开区间,默认约 0.8。 |
top_k | integer | 可选 | 候选词数量,千问专属参数;取值 0 或大于 100 时该策略失效。 |
max_tokens | integer | 可选 | 最大输出 token 数。 |
stop | string | array<string> | 可选 | 停止序列,映射为上游 stop;千问同时支持传入 token id 数组。 |
presence_penalty | number | 可选 | 重复惩罚,范围 [-2, 2],默认 0。 |
enable_thinking | boolean | 可选 | 是否开启思考模式。流式与非流式的默认值不同(见下方警示),涉及推理任务时建议显式传值。 |
thinking_budget | integer | 可选 | 思考过程的最大 token 数,超出后模型直接进入正式回答;仅在 enable_thinking: true 时生效。 |
enable_search | boolean | 可选 | 是否开启联网搜索,默认 false。 |
search_options | object | 可选 | 联网检索细则,如 { "forced_search": true, "enable_source": true };需配合 enable_search: true。 |
response_format | object | 可选 | { "type": "json_object" } 强制 JSON 输出;使用时需在 prompt 中同时说明"以 JSON 格式输出"。 |
tools | array<object> | 可选 | OpenAI 格式的函数定义列表。 |
tool_choice | string | object | 可选 | auto(默认)/ none,或指定具体函数。 |
parallel_tool_calls | boolean | 可选 | 是否允许一轮返回多个工具调用,默认 false(与 OpenAI 默认相反)。 |
seed | integer | 可选 | 采样种子,尽力保证输出可复现。 |
思考模式的默认值陷阱
千问上游对 enable_thinking 的默认值取决于调用方式:流式调用默认开启,非流式调用默认关闭(部分档位
甚至不允许在非流式下开启思考)。因此同一份请求体加上 stream: true 后行为会变化——请始终显式传
enable_thinking,不要依赖默认值。开启后 thinking_budget 建议同时设置,否则思考 token 可能大幅超出预期。
与 OpenAI 标准的其他差异点
top_p为开区间,不接受1.0。parallel_tool_calls默认为false,需要并行工具调用必须显式开启。n(多候选)与frequency_penalty在上游不支持,传入会被忽略。enable_thinking/thinking_budget/enable_search/search_options/top_k为千问专属字段, 由网关透传。
search_options 子字段
仅在 enable_search: true 时生效:
| 字段 | 类型 | 说明 |
|---|---|---|
forced_search | boolean | 是否强制每轮都联网检索,默认 false(由模型自行判断是否需要)。 |
enable_source | boolean | 是否在响应中返回检索来源列表,默认 false。 |
enable_citation | boolean | 是否在正文中插入角标引用,默认 false;需与 enable_source 配合使用。 |
search_strategy | string | 检索条数策略:standard(默认,约 5 条)/ pro(约 10 条,耗时与 token 更高)。 |
02 · 请求组合示例
01 · 基础对话(非流式,显式关闭思考)
curl https://aiapi.bytestream.com.cn/v1/chat/completions \
-H "Authorization: Bearer sk-your-token" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.7-plus",
"messages": [
{ "role": "system", "content": "你是一名电商客服助手。" },
{ "role": "user", "content": "订单还没发货,怎么催?" }
],
"enable_thinking": false,
"temperature": 0.7,
"max_tokens": 1024
}'OpenAI 官方 SDK 不认识 enable_thinking 这类非标准字段,Python 下需通过 extra_body 传入,Node 下通过
请求体透传或 // @ts-expect-error 直接附加。
02 · 思考模式 + 思考预算(流式)
curl https://aiapi.bytestream.com.cn/v1/chat/completions \
-H "Authorization: Bearer sk-your-token" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.7-max",
"messages": [{ "role": "user", "content": "分析这套分库分表方案的扩容瓶颈" }],
"enable_thinking": true,
"thinking_budget": 4096,
"max_tokens": 8192,
"stream": true,
"stream_options": { "include_usage": true }
}'思考内容以 delta.reasoning_content 分片下发,正文以 delta.content 下发,两者可按到达顺序分别渲染。
03 · 联网搜索 + 引用来源
curl https://aiapi.bytestream.com.cn/v1/chat/completions \
-H "Authorization: Bearer sk-your-token" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.7-max",
"messages": [{ "role": "user", "content": "最近一周新能源车企的销量情况" }],
"enable_search": true,
"search_options": {
"forced_search": true,
"enable_source": true,
"enable_citation": true,
"search_strategy": "pro"
}
}'04 · 工具调用(并行)
curl https://aiapi.bytestream.com.cn/v1/chat/completions \
-H "Authorization: Bearer sk-your-token" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.7-max",
"messages": [{ "role": "user", "content": "同时查一下北京和上海的天气" }],
"parallel_tool_calls": true,
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "查询指定城市的实时天气",
"parameters": {
"type": "object",
"properties": { "city": { "type": "string" } },
"required": ["city"]
}
}
}
],
"tool_choice": "auto"
}'05 · JSON 输出
curl https://aiapi.bytestream.com.cn/v1/chat/completions \
-H "Authorization: Bearer sk-your-token" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.7-plus",
"messages": [
{ "role": "system", "content": "请以 JSON 格式输出结果。" },
{ "role": "user", "content": "抽取:李四,前端,3 年经验" }
],
"response_format": { "type": "json_object" }
}'千问的 json_object 模式要求 prompt 中显式出现"JSON"字样,否则上游可能返回 400;该系列不支持
json_schema 严格结构化输出,需要 schema 约束时改用工具调用。
03 · 响应结构
{
"id": "chatcmpl-608a1b2c3d4e5f60",
"object": "chat.completion",
"created": 1721900000,
"model": "qwen3.7-max",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "...",
"reasoning_content": "(开启 enable_thinking 时才有)"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 112,
"completion_tokens": 520,
"total_tokens": 632,
"completion_tokens_details": { "reasoning_tokens": 218 }
}
}finish_reason 取值:stop / length / tool_calls / null(流式中间 chunk)。思考 token 计入
completion_tokens,其中细分量在 completion_tokens_details.reasoning_tokens 中给出,可用于核算思考成本。
开启 search_options.enable_source 时,检索来源列表位于响应顶层的 search_info 字段(非 choices 内);
标准 OpenAI SDK 的强类型模型会忽略该字段,需要时请读取原始 JSON。
04 · 附录
错误码
| 状态码 | 说明 |
|---|---|
200 | 请求成功 |
400 | 参数错误 · invalid_request(常见于 top_p 传 1.0、非流式下开启思考、JSON 模式未在 prompt 中提及 JSON) |
401 | 令牌无效 · invalid_api_key |
402 | 额度不足 · insufficient_user_quota |
404 | 模型不存在或令牌分组无权访问 |
429 | 触发限流 · rate_limit_exceeded |
500 | 上游 / 网关内部错误 |
错误体统一为 {"error": {"message", "type", "param", "code"}}。
速查
{
"model": "qwen3.7-max",
"messages": [{ "role": "user", "content": "..." }],
"stream": true,
"stream_options": { "include_usage": true },
"temperature": 0.7,
"top_p": 0.8,
"top_k": 50,
"max_tokens": 8192,
"stop": ["\n\n"],
"presence_penalty": 0,
"seed": 42,
"enable_thinking": true,
"thinking_budget": 4096,
"enable_search": true,
"search_options": {
"forced_search": true,
"enable_source": true,
"enable_citation": true,
"search_strategy": "pro"
},
"response_format": { "type": "json_object" },
"tools": [{ "type": "function", "function": { "name": "...", "parameters": {} } }],
"tool_choice": "auto",
"parallel_tool_calls": true
}bytestream · dashscope 渠道 · 通义千问系列接入文档 —— 本文档为接入示例(非官方最终版),供接口联调参考。