Skip to main content
Models

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

APIEnabling parameterSummary fieldEncrypted field
Chat Completionsthinking_display="summarized"choices[i].message.reasoning_contentchoices[i].message.encrypted_content
Responsesreasoning.summary="auto"summary[].textencrypted_content
Anthropic Messagesthinking.display="summarized"thinkingsignature
DashScopeparameters.thinking_display="summarized"output.choices[i].message.reasoning_contentoutput.choices[i].message.encrypted_content
  • Chat Completions
  • Responses
  • Anthropic Messages
  • DashScope
curl
# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
curl -X POST "https://ap-southeast-1.maas.qwencloudapi.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 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.

Store streamed summaries, ciphertext, and answers

This Chat Completions example handles one reply without tool calls. Process all three fields on every chunk and save one assistant message at the end. Retain standalone ciphertext frames even when no text is present; ciphertext is a complete value, not a text delta to concatenate.
Python
import os
from openai import OpenAI

client = OpenAI(
  api_key=os.environ["DASHSCOPE_API_KEY"],
  # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
  # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
  base_url="https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1",
)
history = [{"role": "user", "content": "Calculate 17 * 23."}]
stream = client.chat.completions.create(
  model="qwen4-max",
  messages=history,
  stream=True,
  max_tokens=8192,
  extra_body={
    "enable_thinking": True,
    "thinking_display": "summarized",
    "preserve_thinking": True,
  },
)
assistant = {"role": "assistant", "content": "", "reasoning_content": ""}
for chunk in stream:
  if not chunk.choices:
    continue
  delta = chunk.choices[0].delta.model_dump(exclude_none=True)
  assistant["reasoning_content"] += delta.get("reasoning_content") or ""
  assistant["content"] += delta.get("content") or ""
  ciphertext = delta.get("encrypted_content")
  if ciphertext:
    assistant["encrypted_content"] = ciphertext
history.append(assistant)
print("Summary:", assistant["reasoning_content"])
print("Answer:", assistant["content"])
if not assistant.get("encrypted_content"):
  print("No ciphertext was returned; the summary cannot restore full reasoning.")

Multi-turn conversations

If a turn returns no ciphertext, its summary cannot restore the full reasoning history. Retain the original input and answer, and check whether the turn generated reasoning and successfully enabled summaries. Do not fabricate ciphertext from a summary.
Retain complete ciphertext when replaying history. Summaries can be omitted; the Responses summary array can be empty.
  • Chat Completions
  • Responses
  • Anthropic Messages
  • DashScope
Pass the non-standard OpenAI Python SDK parameters enable_thinking, thinking_display, and preserve_thinking through extra_body.
Python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["DASHSCOPE_API_KEY"],
    # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
    # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
    base_url="https://ap-southeast-1.maas.qwencloudapi.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.get("content") or "")

Billing

This feature has no additional charge. The model’s existing input and output token billing rules apply.