通义千问 API
  1. 深度思考(QwQ)
通义千问 API
  • 首次调用通义千问API
  • 文本生成
    • 深度思考(QwQ)
      • 深度思考(QwQ)概括
      • 快速开始
        POST
      • 多轮对话
        POST
    • 长上下文
      • 通过file-id传入文档信息
        • 简单示例
        • 传入多文档
        • 追加文档
      • 通过纯文本传入信息
        • 简单示例
        • 传入多文档
        • 追加文档
      • 通过JSON字符串传入文档信息
        • 简单示例
        • 传入多文档
        • 追加文档
    • 翻译能力
      • Qwen-MT模型
      • 支持的语言
      • 简单示例
      • 流式输出
      • 术语干预翻译
      • 使用翻译记忆
      • 领域提示
    • 数学能力
      • 模型概览
      • 示例代码
    • 代码能力
      • 模型概览
      • 简单示例
      • 代码补全
      • 根据前缀和后缀生成中间内容
    • 多轮对话
      • 开始使用
    • 流式输出(Stream)
      • 概述
      • 开始使用
    • 工具调用(Function Calling)
      • 概述
    • 结构化输出(Json Mode)
      • 支持的模型
      • 开始使用
    • 前缀续写(Partial Mode)
      • 支持的模型
      • 开始使用
    • 批量推理(Batch)
      • 概述
    • 上下文缓存(Context Cache)
      • 概述
  • 视觉理解
    • 全模态(Qwen-Omni )
      • 概述
      • 开始使用
      • 图片+文本输入
      • 音频+文本输入
      • 视频+文本输入
      • 多轮对话
  1. 深度思考(QwQ)

快速开始

POST
https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions
API 使用前提:已获取API Key并完成配置API Key到环境变量。如果通过SDK调用,需要安装 OpenAI 或 DashScope SDK(DashScope Java SDK 版本需要不低于2.18.2)。
重要
1.
QwQ 模型当前仅支持通过流式输出方式调用。
2.
如果您使用 DashScope 方式调用 QwQ 模型:
1.
incremental_output 参数默认为 true,且不支持设置为 false,仅支持增量流式返回;
2.
response_format参数默认为"message"。
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions' \
--header 'Authorization: Bearer {{DASHSCOPE_API_KEY}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "qwq-32b",
    "messages": [
        {
            "role": "user", 
            "content": "9.9和9.11谁大"
        }
    ],
    "stream": true,
    "stream_options": {
        "include_usage": true
    }
}'
响应示例响应示例
data: {"choices":[{"delta":{"content":null,"role":"assistant","reasoning_content":""},"index":0,"logprobs":null,"finish_reason":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}

data: {"choices":[{"finish_reason":null,"delta":{"content":null,"reasoning_content":"嗯"},"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}

data: {"choices":[{"delta":{"content":null,"reasoning_content":","},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}

data: {"choices":[{"delta":{"content":null,"reasoning_content":"用户"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}
......

data: {"choices":[{"delta":{"content":"需","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}

data: {"choices":[{"delta":{"content":"进一步","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}

data: {"choices":[{"delta":{"content":"确认","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}

data: {"choices":[{"delta":{"content":"规则","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}

data: {"choices":[{"delta":{"content":"。","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}

data: {"choices":[{"finish_reason":"stop","delta":{"content":"","reasoning_content":null},"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}

data: {"choices":[],"object":"chat.completion.chunk","usage":{"prompt_tokens":18,"completion_tokens":1015,"total_tokens":1033},"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}

data: [DONE]

请求参数

Authorization
在 Header 添加参数
Authorization
,其值为在 Bearer 之后拼接 Token
示例:
Authorization: Bearer ********************
Header 参数
Authorization
string 
必需
示例值:
Bearer {{DASHSCOPE_API_KEY}}
Content-Type
string 
必需
示例值:
application/json
Body 参数application/json
model
string 
必需
messages
array [object {2}] 
必需
role
string 
可选
content
string 
可选
stream
boolean 
必需
stream_options
object 
必需
include_usage
boolean 
必需
示例

返回响应

🟢200成功
application/json
Body
choices
array [object {4}] 
必需
delta
object 
可选
index
integer 
可选
logprobs
null 
可选
finish_reason
null 
可选
object
string 
必需
usage
null 
必需
created
integer 
必需
system_fingerprint
null 
必需
model
string 
必需
id
string 
必需
上一页
深度思考(QwQ)概括
下一页
多轮对话
Built with