Qwen4-Max migration: output limits, thinking, and agent setup

AIHubMix4 min read
Qwen4-Max migration: output limits, thinking, and agent setup

Moving from Qwen3.8-Max to Qwen4-Max changes more than the model ID. Both have a million-token context, but an output limit previously sized for the answer now also pays for thinking. The default effort changes, and agents must preserve reasoning history correctly across tool calls.

Start with one Chat Completions request, then one small repository task. Check the answer, stopping reason, history, and resulting diff before moving an existing workflow.

Recalculate the output limit

The Chat Completions reference defines Qwen4-Max's max_tokens as equivalent to max_completion_tokens: both cap thinking plus the final answer. Qwen3.8-Max's max_tokens covers the answer alone.

A cap of 300 therefore does not reserve 300 tokens for a visible answer. Reasoning can consume the budget first, potentially leaving an empty or incomplete answer. A response ending with finish_reason: "length" needs attention even when the HTTP request succeeds. Renaming the parameter without increasing the value changes nothing.

Use max_completion_tokens for new integrations and allow room for both parts. Qwen4-Max supports up to 262,144 combined output tokens in thinking mode, or 131,072 in non-thinking mode. Its 1,000,000-token context is not an input allowance to which you can add the maximum output; input and output must fit the context together.

Choose effort or a thinking budget

Qwen4-Max uses low, high, and xhigh, with high as the default. Omitting both controls selects high and a 131,072-token thinking budget. That is a ceiling, not a prediction of tokens used.

Two inherited settings change meaning: high now means high, rather than mapping to xhigh as on Qwen3.8-Max; medium maps to high. Other mappings are minimal to low, max to xhigh, and none to thinking disabled.

Send either reasoning_effort or thinking_budget. The official reference forbids combining them, and a budget must be a positive integer: zero does not disable thinking. With a budget alone, 1–4,096 selects low, 4,097–131,072 selects high, and 131,073–262,144 selects xhigh, retaining the supplied budget.

Start with the listed endpoint

The AIHubMix model guide lists qwen4-max on POST /v1/chat/completions. This is a starting request, not a measured result:

curl -sS https://aihubmix.com/v1/chat/completions \
  -H "Authorization: Bearer $AIHUBMIX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen4-max",
    "max_completion_tokens": 16384,
    "messages": [{"role": "user", "content": "Write a Python function that returns unique items in their original order, with two tests."}]
  }'

The output limit follows Alibaba's documented contract. You can optionally add reasoning_effort: "low" without a thinking budget; parameter forwarding has not been measured here. AIHubMix's capability flags remain unverified. Check the actual response and usage before relying on a setting.

Preserve the history your agent needs

With full thinking, keep historical assistant messages' reasoning_content separate from content, including turns that call tools. Qwen4-Max enables preserve_thinking by default; returned history counts as input and is billed. A serializer that keeps only visible text loses part of that history.

Alibaba also offers thinking summaries and encryption. When enabled with thinking_display: "summarized" on every request, reasoning_content becomes a display summary and encrypted_content carries the reasoning history. Replay the ciphertext unchanged; the summary cannot replace it. Streaming clients must retain the separate encrypted frame even when it has no visible text.

This summary mode is documented at Alibaba. Its passage through AIHubMix is unverified, so establish ordinary conversation continuity first.

Check caching before projecting savings

Alibaba's Qwen4 explicit cache supports manual breakpoints and automatic breakpoints, with 5-minute or 1-hour TTLs. A cached prefix needs at least 1,024 tokens. Cache writes cost approximately 125% or 200% of ordinary input, respectively; repeated writes are not free savings.

Keep stable system instructions, tool definitions, and repository material first, then changing questions. If no cache parameters are set, ordinary implicit caching does not guarantee hits. Verify cache read/write usage and the bill before assuming your agent benefits. These vendor cache controls have not been measured through AIHubMix.

Coding tools: verify one complete task

Follow the AIHubMix Qwen Code guide for installation and authentication. Set OPENAI_BASE_URL=https://aihubmix.com/v1, OPENAI_MODEL=qwen4-max, and supply the key through OPENAI_API_KEY. Use /status to confirm the selected model; also inspect the client's context and output settings.

Claude Code needs Anthropic Messages, while Codex needs Responses. Alibaba documents those protocols, but AIHubMix's Qwen4-Max guide lists only Chat Completions. Their availability through this gateway is not established here.

Work through this migration checklist in a scratch repository:

  1. Confirm the model and endpoint; inspect answer text, finish_reason, and usage on the basic request.
  2. Remove inherited answer-only caps and conflicting thinking controls. Retry truncation with more room; check the complete answer.
  3. Fix one failing test across two files. Success means a real tool call completes, the tests pass, and the diff contains only the intended change.
  4. Ask a follow-up that depends on the first turn. Inspect saved assistant/tool history and any compaction; confirm the required context survives.
  5. Repeat with your chosen effort. Compare accepted patches, total tokens, and retries. Verify cache usage separately before estimating recurring cost.

FAQ

What model ID should I use on AIHubMix?
Use qwen4-max with the listed Chat Completions endpoint.

Why can a successful request contain an incomplete answer?
Thinking and the answer share the output cap. Check finish_reason for length and increase the combined allowance when needed.

Does switching to max_completion_tokens fix truncation?
Not by itself. It has the same meaning as max_tokens on Qwen4-Max; the value must leave enough room.

Can I set effort and a thinking budget together?
No. Choose one. A thinking budget must be positive; use reasoning_effort none to disable thinking.

Should I replay a thinking summary as reasoning history?
No. In summary mode, retain and replay encrypted_content unchanged. The display summary cannot substitute for it.

Can I assume Claude Code or Codex works through AIHubMix?
Their required protocols are not verified for this model here. Establish the relevant endpoint and a complete tool workflow first.

Keep reading: the Qwen4-Max series

Sources

  1. Alibaba Cloud: Qwen4-Max model specifications and Qwen3.8-Max.
  2. Alibaba Cloud: Chat Completions parameters.
  3. Alibaba Cloud: Thinking summary and encryption.
  4. Alibaba Cloud: Explicit cache for Qwen4.
  5. AIHubMix: Qwen4-Max model guide and Qwen Code setup.

Sources checked November 17, 2026. No paid inference tests were run for this article.

One gateway to multiple AI providers. Built for production.

Visit AIHubMix