Thinking summary and encryption
Qwen4-Max returns a displayable thinking summary and the encrypted full thinking content to restore reasoning history in multi-turn conversations.
Supported model: qwen4-max.
How it works
Full thinking is returned by default. When enabled, raw thinking is no longer returned in plaintext: the model returns a summary for display and the encrypted full thinking for restoring reasoning history.
Summaries and ciphertext are enabled together. Ciphertext may be absent if no reasoning is generated or encryption fails. Summaries may be missing or incomplete; raw reasoning remains unavailable.
Enable this feature in every request and replay historical ciphertext unchanged to restore the corresponding reasoning.
Text and multimodal input use the same parameters. Encryption stores only thinking, so retain historical images, videos, and other inputs. Store each encrypted thinking segment with its assistant message, including tool-call turns.
Enable enable_thinking=true for Chat Completions and DashScope, and use preserve_thinking=true to continue with encrypted history. Responses and Anthropic Messages use their own thinking parameters.
Enable the feature
These examples use Beijing. Replace WorkspaceId with your workspace ID and set DASHSCOPE_API_KEY.
| API | Enabling parameter | Summary field | Encrypted field |
|---|---|---|---|
| Chat Completions | thinking_display="summarized" | choices[i].message.reasoning_content | choices[i].message.encrypted_content |
| Responses | reasoning.summary="auto" | summary[].text | encrypted_content |
| Anthropic Messages | thinking.display="summarized" | thinking | signature |
| DashScope | parameters.thinking_display="summarized" | output.choices[i].message.reasoning_content | output.choices[i].message.encrypted_content |
Chat Completions
curl -X POST "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen4-max",
"messages": [
{
"role": "user",
"content": "Calculate 17×23."
}
],
"enable_thinking": true,
"thinking_display": "summarized",
"preserve_thinking": true
}'
Responses
curl -X POST "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/responses" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen4-max",
"input": "Calculate 17×23.",
"reasoning": {
"summary": "auto"
}
}'
Anthropic Messages
curl -X POST "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/apps/anthropic/v1/messages" \
-H "x-api-key: $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen4-max",
"max_tokens": 2048,
"thinking": {
"type": "enabled",
"budget_tokens": 1024,
"display": "summarized"
},
"messages": [
{
"role": "user",
"content": "Calculate 17×23."
}
]
}'
DashScope
curl -X POST "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen4-max",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"text": "Calculate 17×23."
}
]
}
]
},
"parameters": {
"result_format": "message",
"incremental_output": false,
"enable_thinking": true,
"thinking_display": "summarized",
"preserve_thinking": true
}
}'
Responses and streaming
Chat Completions streams summary deltas in choices[i].delta.reasoning_content, then a separate complete encrypted_content frame, then text or tool calls, and then completion. Non-streaming fields are in choices[i].message. Do not discard an encrypted frame because its text is empty or create a separate assistant message for it.
A Responses reasoning item contains summary (with summary_text elements) and encrypted_content. Summary text arrives incrementally; encrypted content arrives in the reasoning item completion event and final response. Use the completed snapshot to recover encrypted content without appending the summary twice.
An Anthropic Messages thinking block contains a thinking summary and an encrypted signature. Streaming emits thinking_delta first, then a complete signature_delta; text or tool calls follow after the thinking block closes. The signature may be empty if encryption fails or no thinking is generated.
DashScope fields are in output.choices[i].message and follow the Chat Completions streaming order. Put ciphertext in encrypted_content, not content[].text. Intermediate finish_reason is the string "null", and the final value is "stop". Streaming usage is cumulative; do not add it repeatedly.
Multi-turn conversations
Retain complete ciphertext when replaying history. Summaries can be omitted; the Responses summary array can be empty.
Chat Completions
Pass the non-standard OpenAI Python SDK parameters enable_thinking, thinking_display, and preserve_thinking through extra_body.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["DASHSCOPE_API_KEY"],
base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
questions = [
"Calculate 17×23.",
"Now add 9."
]
history = []
for turn, question in enumerate(questions, start=1):
history.append({"role": "user", "content": question})
response = client.chat.completions.create(
model="qwen4-max",
messages=history,
max_tokens=8192,
stream=False,
extra_body={
"enable_thinking": True,
"thinking_display": "summarized",
"preserve_thinking": True,
},
)
assistant_message = response.choices[0].message.model_dump(exclude_none=True)
history.append(assistant_message)
print(f"Turn {turn}")
print("Summary:", assistant_message.get("reasoning_content", ""))
print("Answer:", assistant_message["content"])
const questions = [
"Calculate 17×23.",
"Now add 9."
];
const history = [];
const endpoint = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions";
for (const [index, question] of questions.entries()) {
history.push({ role: "user", content: question });
const httpResponse = await fetch(endpoint, {
method: "POST",
headers: { "Authorization": `Bearer ${process.env.DASHSCOPE_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ model: "qwen4-max", messages: history, max_tokens: 8192, stream: false, enable_thinking: true, thinking_display: "summarized", preserve_thinking: true }),
});
if (!httpResponse.ok) throw new Error(await httpResponse.text());
const response = await httpResponse.json();
const assistantMessage = response.choices[0].message;
history.push(assistantMessage);
console.log(`Turn ${index + 1}`);
console.log("Summary:", assistantMessage.reasoning_content ?? "");
console.log("Answer:", assistantMessage.content);
}
set -euo pipefail
history='[]'
questions=(
'Calculate 17×23.'
'Now add 9.'
)
for question in "${questions[@]}"; do
history=$(jq --arg question "$question" '. + [{role: "user", content: $question}]' <<< "$history")
request=$(jq -n --argjson history "$history" '{model: "qwen4-max", messages: $history, max_tokens: 8192, stream: false, enable_thinking: true, thinking_display: "summarized", preserve_thinking: true}')
response=$(curl --fail-with-body -sS "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
--data "$request")
history=$(jq -n --argjson history "$history" --argjson response "$response" \
'$history + [$response.choices[0].message]')
printf '%s\n' "$response" | jq '.choices[0].message | {summary: .reasoning_content, answer: .content}'
done
Responses
Set reasoning.summary="auto" to enable summaries and encryption. The example uses store=false and saves history on the client.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["DASHSCOPE_API_KEY"],
base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
questions = [
"Calculate 17×23.",
"Now add 9."
]
history = []
for turn, question in enumerate(questions, start=1):
history.append({"role": "user", "content": question})
response = client.responses.create(
model="qwen4-max",
input=history,
reasoning={"effort": "medium", "summary": "auto"},
max_output_tokens=8192,
store=False,
stream=False,
)
output_items = [item.model_dump(exclude_none=True) for item in response.output]
history.extend(output_items)
print(f"Turn {turn}")
for item in output_items:
if item["type"] == "reasoning":
print("Summary:", "".join(part["text"] for part in (item.get("summary") or [])))
print("Answer:", response.output_text)
const questions = [
"Calculate 17×23.",
"Now add 9."
];
const history = [];
const endpoint = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/responses";
for (const [index, question] of questions.entries()) {
history.push({ role: "user", content: question });
const httpResponse = await fetch(endpoint, {
method: "POST",
headers: { "Authorization": `Bearer ${process.env.DASHSCOPE_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ model: "qwen4-max", input: history, reasoning: { effort: "medium", summary: "auto" }, max_output_tokens: 8192, store: false, stream: false }),
});
if (!httpResponse.ok) throw new Error(await httpResponse.text());
const response = await httpResponse.json();
history.push(...response.output);
console.log(`Turn ${index + 1}`);
for (const item of response.output) {
if (item.type === "reasoning") console.log("Summary:", (item.summary ?? []).map(part => part.text).join(""));
if (item.type === "message") console.log("Answer:", item.content.filter(part => part.type === "output_text").map(part => part.text).join(""));
}
}
set -euo pipefail
history='[]'
questions=(
'Calculate 17×23.'
'Now add 9.'
)
for question in "${questions[@]}"; do
history=$(jq --arg question "$question" '. + [{role: "user", content: $question}]' <<< "$history")
request=$(jq -n --argjson history "$history" '{model: "qwen4-max", input: $history, reasoning: {effort: "medium", summary: "auto"}, max_output_tokens: 8192, store: false, stream: false}')
response=$(curl --fail-with-body -sS "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/responses" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
--data "$request")
history=$(jq -n --argjson history "$history" --argjson response "$response" \
'$history + $response.output')
printf '%s\n' "$response" | jq '{summary: [.output[] | select(.type == "reasoning") | .summary[].text], answer: [.output[] | select(.type == "message") | .content[] | select(.type == "output_text") | .text]}'
done
Anthropic Messages
import os
import anthropic
client = anthropic.Anthropic(
api_key=os.environ["DASHSCOPE_API_KEY"],
base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/apps/anthropic",
)
questions = [
"Calculate 17×23.",
"Now add 9."
]
history = []
for turn, question in enumerate(questions, start=1):
history.append({"role": "user", "content": question})
response = client.messages.create(
model="qwen4-max",
messages=history,
max_tokens=8192,
thinking={"type": "enabled", "budget_tokens": 4096, "display": "summarized"},
stream=False,
)
content_blocks = [block.model_dump(exclude_none=True) for block in response.content]
history.append({"role": "assistant", "content": content_blocks})
print(f"Turn {turn}")
for block in content_blocks:
if block["type"] == "thinking":
print("Summary:", block["thinking"])
elif block["type"] == "text":
print("Answer:", block["text"])
const questions = [
"Calculate 17×23.",
"Now add 9."
];
const history = [];
const endpoint = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/apps/anthropic/v1/messages";
for (const [index, question] of questions.entries()) {
history.push({ role: "user", content: question });
const httpResponse = await fetch(endpoint, {
method: "POST",
headers: { "x-api-key": process.env.DASHSCOPE_API_KEY, "anthropic-version": "2023-06-01", "Content-Type": "application/json" },
body: JSON.stringify({ model: "qwen4-max", messages: history, max_tokens: 8192, thinking: { type: "enabled", budget_tokens: 4096, display: "summarized" }, stream: false }),
});
if (!httpResponse.ok) throw new Error(await httpResponse.text());
const response = await httpResponse.json();
history.push({ role: "assistant", content: response.content });
console.log(`Turn ${index + 1}`);
for (const block of response.content) {
if (block.type === "thinking") console.log("Summary:", block.thinking);
if (block.type === "text") console.log("Answer:", block.text);
}
}
set -euo pipefail
history='[]'
questions=(
'Calculate 17×23.'
'Now add 9.'
)
for question in "${questions[@]}"; do
history=$(jq --arg question "$question" '. + [{role: "user", content: $question}]' <<< "$history")
request=$(jq -n --argjson history "$history" '{model: "qwen4-max", messages: $history, max_tokens: 8192, thinking: {type: "enabled", budget_tokens: 4096, display: "summarized"}, stream: false}')
response=$(curl --fail-with-body -sS "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/apps/anthropic/v1/messages" \
-H "x-api-key: $DASHSCOPE_API_KEY" -H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
--data "$request")
history=$(jq -n --argjson history "$history" --argjson response "$response" \
'$history + [{role: "assistant", content: $response.content}]')
printf '%s\n' "$response" | jq '{summary: [.content[] | select(.type == "thinking") | .thinking], answer: [.content[] | select(.type == "text") | .text]}'
done
DashScope
import json
import os
from urllib.request import Request, urlopen
questions = [
"Calculate 17×23.",
"Now add 9."
]
history = []
for turn, question in enumerate(questions, start=1):
history.append({"role": "user", "content": [{"text": question}]})
body = {
"model": "qwen4-max",
"input": {"messages": history},
"parameters": {
"result_format": "message",
"incremental_output": False,
"enable_thinking": True,
"thinking_display": "summarized",
"preserve_thinking": True,
"max_tokens": 8192,
},
}
request = Request(
"https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation",
data=json.dumps(body).encode("utf-8"),
headers={
"Authorization": "Bearer " + os.environ["DASHSCOPE_API_KEY"],
"Content-Type": "application/json",
},
method="POST",
)
with urlopen(request, timeout=120) as http_response:
response = json.load(http_response)
assistant_message = response["output"]["choices"][0]["message"]
history.append(assistant_message)
print(f"Turn {turn}")
print("Summary:", assistant_message.get("reasoning_content", ""))
print("Answer:", "".join(part.get("text", "") for part in assistant_message["content"]))
const questions = [
"Calculate 17×23.",
"Now add 9."
];
const history = [];
const endpoint = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation";
for (const [index, question] of questions.entries()) {
history.push({ role: "user", content: [{ text: question }] });
const httpResponse = await fetch(endpoint, {
method: "POST",
headers: { "Authorization": `Bearer ${process.env.DASHSCOPE_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ model: "qwen4-max", input: { messages: history }, parameters: { result_format: "message", incremental_output: false, enable_thinking: true, thinking_display: "summarized", preserve_thinking: true, max_tokens: 8192 } }),
});
if (!httpResponse.ok) throw new Error(await httpResponse.text());
const response = await httpResponse.json();
const assistantMessage = response.output.choices[0].message;
history.push(assistantMessage);
console.log(`Turn ${index + 1}`);
console.log("Summary:", assistantMessage.reasoning_content ?? "");
console.log("Answer:", assistantMessage.content.map(part => part.text ?? "").join(""));
}
set -euo pipefail
history='[]'
questions=(
'Calculate 17×23.'
'Now add 9.'
)
for question in "${questions[@]}"; do
history=$(jq --arg question "$question" '. + [{role: "user", content: [{text: $question}]}]' <<< "$history")
request=$(jq -n --argjson history "$history" '{model: "qwen4-max", input: {messages: $history}, parameters: {result_format: "message", incremental_output: false, enable_thinking: true, thinking_display: "summarized", preserve_thinking: true, max_tokens: 8192}}')
response=$(curl --fail-with-body -sS "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
--data "$request")
history=$(jq -n --argjson history "$history" --argjson response "$response" \
'$history + [$response.output.choices[0].message]')
printf '%s\n' "$response" | jq '.output.choices[0].message | {summary: .reasoning_content, answer: [.content[].text]}'
done
Billing
This feature has no additional charge. The model’s existing input and output token billing rules apply.