By the Cuelark Team. Every model detail below comes from Alibaba Cloud Model Studio's own docs, checked on 17 November 2026. The code ran on our machine against a local mock of the documented stream. We had no Qwen API key for this test, so read it as a wiring test, not a quality review.
Alibaba's Model Studio added qwen4-max to its release notes on November 16 for the International deployment scope. It's the new flagship of the Qwen family. If you already run a chat UI on the Vercel AI SDK, switching looks like a one-line model change, since the model speaks the OpenAI Chat Completions protocol. That mostly holds. But one feature, encrypted reasoning, doesn't survive the trip through the standard OpenAI-compatible provider. Here's what changed, what broke in our test, and the small fix.
What the docs say
From the qwen4-max model page:
- Input and output: text, image and video in, text out. Streaming, function calling, parallel tool calls, web search, structured output (JSON Object and JSON Schema) and explicit plus implicit caching are all supported.
- Protocols: OpenAI Chat Completions, OpenAI Responses, Anthropic Messages and DashScope.
- Not supported: batch inference, fine-tuning and model deployment.
- Context: 1,000,000 tokens. Output goes up to 131,072 tokens without thinking and 262,144 with thinking.
-
Defaults: thinking is on (
enable_thinking: true),preserve_thinking: true, andreasoning_effort: high. The supported effort values arelow,highandxhigh. Other values get mapped:minimalbecomeslow,mediumbecomeshigh, andmaxbecomesxhigh. - Price: $1.50 per million input tokens and $4.50 per million output tokens (thinking plus answer) in the International scope, and $1.413 / $4.24 in the Global scope. The same rate applies with or without thinking. Cache prices are on the linked caching page.
Base URLs have also changed format. The OpenAI-compatible docs now use a workspace host, such as https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1 for Singapore. They tell you to move away from dashscope-intl.aliyuncs.com.
The part that matters for chat UIs: thinking summaries and ciphertext
The thinking summary and encryption page describes an opt-in mode for qwen4-max. Send thinking_display: "summarized" and you no longer get the raw reasoning. You get a summary you can show the user, plus the full reasoning in encrypted form.
The streaming order on Chat Completions is:
- Summary deltas arrive in
choices[i].delta.reasoning_content. - One separate frame carries the complete
encrypted_content. - Text or tool calls arrive, then completion.
The docs say this explicitly: to restore the model's reasoning on later turns, send this ciphertext back unchanged with its assistant message, in every request. They also warn you not to drop the encrypted frame just because its text is empty.
What happened with the AI SDK
We used [email protected] and @ai-sdk/[email protected], and pointed them at a mock server that sends frames in the documented order. The mock is built from the docs. It isn't a captured Qwen response.
Streaming worked. The summary came through as reasoning-delta parts and the answer as text-delta. Then we looked at what the second request actually sent:
{
"role": "assistant",
"content": "17 × 23 = 391",
"reasoning_content": "Breaking the product into 17×20 + 17×3."
}
There's no encrypted_content. The provider keeps fields it knows about and drops the rest. Nothing errors, so it's easy to miss. Your chat keeps working, but the model never gets its earlier reasoning back, which is exactly what the docs say the ciphertext is for.
The fix: one extractor, one field on the way back
The OpenAI-compatible provider has two hooks that solve this:
- a
metadataExtractorreads raw stream chunks, and - anything under
providerOptions.openaiCompatibleon a message gets spread into that message in the request body.
// lib/qwen.js
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
const encryptedReasoning = {
extractMetadata: async ({ parsedBody }) => ({
qwen: { encrypted: parsedBody?.choices?.[0]?.message?.encrypted_content ?? null },
}),
createStreamExtractor: () => {
let encrypted = null;
return {
processChunk(chunk) {
const e = chunk?.choices?.[0]?.delta?.encrypted_content;
if (e) encrypted = e;
},
buildMetadata: () => ({ qwen: { encrypted } }),
};
},
};
export const qwen = createOpenAICompatible({
name: 'qwen',
baseURL: process.env.QWEN_BASE_URL, // https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1
apiKey: process.env.DASHSCOPE_API_KEY,
metadataExtractor: encryptedReasoning,
});
export const thinking = {
qwen: { enable_thinking: true, thinking_display: 'summarized', preserve_thinking: true },
};
In the route, attach the ciphertext to the assistant message's metadata so useChat stores it with that message. When the history comes back on the next request, put it back:
// app/api/chat/route.js
import { streamText, convertToModelMessages } from 'ai';
import { qwen, thinking } from '@/lib/qwen';
export async function POST(req) {
const { messages } = await req.json();
const modelMessages = [];
for (const m of messages) {
for (const mm of await convertToModelMessages([m])) {
const enc = m.role === 'assistant' ? m.metadata?.encrypted : null;
modelMessages.push(
enc ? { ...mm, providerOptions: { openaiCompatible: { encrypted_content: enc } } } : mm,
);
}
}
const result = streamText({
model: qwen.chatModel('qwen4-max'),
messages: modelMessages,
providerOptions: thinking,
});
return result.toUIMessageStreamResponse({
sendReasoning: true,
messageMetadata: ({ part }) =>
part.type === 'finish-step' ? { encrypted: part.providerMetadata?.qwen?.encrypted } : undefined,
});
}
On the client, your existing shadcn chat doesn't change. Show the reasoning parts in a collapsible "Thinking" block and the text parts as the answer. After this change, our two-turn test sent the assistant message back with "encrypted_content": "ENC-TURN-1" and passed.
Honest limits
- We didn't call the real API. The stream shape comes from the docs. Before you ship, run one real two-turn request and check the second request body.
- Tool loops need more work. The docs say to store each encrypted segment with its own assistant message, including tool-call turns. Our extractor keeps one value per step, which is fine for plain chat. A multi-step tool agent needs one value per step mapped onto the matching assistant message.
- Summaries can be incomplete. The docs say the summary may be missing or partial, and raw reasoning isn't available in this mode. Don't build UI that depends on it.
-
The ciphertext lives in the client.
useChatholds it in message metadata. If you store chats, store the metadata too, or the next session starts without it. - No batch or fine-tuning. If your pipeline relies on either, this model isn't a drop-in swap.
Sources
- qwen4-max model page, Alibaba Cloud Model Studio
- Thinking summary and encryption
- OpenAI compatible: Chat
- Model releases and updates
- vercel/ai release [email protected]
If you'd rather not hand-build the thinking block and message list, Cuelark UI has shadcn-style components for AI chat that work with this setup.
Top comments (1)
State management around streaming reasoning tokens in conversational UIs is surprisingly tricky to get clean. If you don't cleanly decouple intermediate thinking states from the committed message history, you end up with messy hydration mismatches or bloated persistence payloads. Great breakdown on handling this gracefully on the client!