Skip to content

Build Notes

Qwen4-Max API: How to Set an Output Budget

By Miles Park·

A Qwen4-Max response can stop before its final JSON object closes if the output budget is too small. Begin by checking which model and API you call. Alibaba announced Qwen4-Max on November 16, 2026. Model Studio lists qwen4-max as the production model and documents qwen4-max-preview separately.

Separate production settings from preview defaults

Alibaba documents that, for the preview model on its OpenAI-compatible Chat Completions route, max_tokens and max_completion_tokens are equivalent and include both thinking and the answer. Preview access uses Token Plan, and its announced window ends at midnight at the close of November 25 (UTC+8). Use the production model’s own endpoint and parameter documentation when moving your integration. Review pricing for the chosen region and access plan before running comparisons.

Check whether the response is usable

  1. Send a small synthetic order table and ask for a JSON object with an orders array, item IDs and integer quantities.
  2. Keep the prompt, model, region, thinking setting and output format the same for two calls. Vary only the supported completion limit. Start with a modest cap that fits your test budget.
  3. Record the resolved model, finish reason and any available usage fields. Parse the returned answer and check that every input order appears exactly once. If the selected route exposes the length stop reason, record it separately from a malformed response that ended normally.

For example, the input rows A12,2 and B08,5 should produce two records with those IDs and quantities. A syntactically valid answer containing one record still fails the completeness check. Keep the test fixture simple enough that the expected response can be checked locally.

From model response to a usable result
1. Capture

Keep the exact model ID, configured limit, usage and stop reason.

2. Parse

Check that the result is valid JSON and has the requested orders array.

3. Reconcile

Check each ID and quantity. Reject missing or duplicate records.

Use the documented fields for your endpoint. Availability and naming can vary by API.

Validate the content before retrying

The following local validator distinguishes an incomplete response from a complete one. It rejects invalid syntax, duplicate IDs and valid JSON that omits input rows. The assertions use synthetic strings and do not make an API call.

Python · locally tested JSON validation
import json

def check_orders(text, expected):
    try:
        rows = json.loads(text)["orders"]
        if not isinstance(rows, list):
            return False
        seen = {}
        for row in rows:
            item, qty = row["id"], row["quantity"]
            if not isinstance(item, str) or type(qty) is not int:
                return False
            if item in seen:
                return False
            seen[item] = qty
        return seen == expected
    except (ValueError, KeyError, TypeError):
        return False

expected = {"A12": 2, "B08": 5}
assert not check_orders('{"orders":[', expected)
assert not check_orders('{"orders":[{"id":"A12","quantity":2}]}', expected)
assert check_orders(
    '{"orders":[{"id":"A12","quantity":2},{"id":"B08","quantity":5}]}',
    expected,
)

Record the endpoint with the budget

For a useful comparison log, write down the production or preview model ID, deployment region, protocol, completion limit and thinking configuration. If you migrate protocols, check the budget field and usage fields again. Reserve enough budget for the answer and any reasoning counted against that limit. Check the documented production limits for your mode before applying one limit across applications.

If your SDK receives a structured response, validate the response against your application’s expected records even when the provider validates a JSON schema. Schema compliance and complete data reconciliation are separate checks.

Handle a short response deliberately

When a response reaches its limit and fails validation, preserve its stop reason for diagnosis. For a bounded retry, either raise the limit within the workflow’s budget or request fewer records and recombine validated batches. If the model stops normally yet leaves rows out, inspect the instructions and input. Raising the cap alone may have little effect. This is a configuration and validation walkthrough based on vendor documentation. We have not run the example on either endpoint.

Sources: Alibaba’s launch announcement · Production model guide · Preview guide · JoCoding IT News.

Join the discussion

Your email address will not be published. Required fields are marked *