Quick answer: The official Qwen 4 API runs on QwenCloud (Alibaba Cloud Model Studio) through an OpenAI-compatible endpoint. The international example base URL is https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1. Use qwen4-max for the flagship ($1.50 / $4.50 per million input / output tokens) or qwen4-35b-a3b for the open-weight model ($0.06 / $0.36). Both have a 1M context, up to 128K output (256K in thinking mode) and image and video input. Authenticate with your Model Studio key, set as DASHSCOPE_API_KEY. Turn thinking on or off with enable_thinking.
The most common Qwen 4 API questions online are practical. "How much does it cost?" "Where do I get a key?" "Is there a free option?" "Which model ID do I use?" They are hard to answer because Qwen's docs are split across a model card, a cloud console and regional pricing pages. This page puts everything on one screen, with copy-paste code.
Sources: model IDs, endpoint, prices and limits come from QwenCloud's model pages. Thinking controls come from the Hugging Face model card. Checked December 5, 2026. Prices can differ by region, so confirm in your console before production use.
Qwen 4 API at a glance
qwen4-max | qwen4-35b-a3b | |
|---|---|---|
| Model | Qwen4-Max (flagship, closed weights) | Qwen4-35B-A3B (open weights, Apache-2.0) |
| Input price / 1M | $1.50 | $0.06 |
| Output price / 1M | $4.50 | $0.36 |
| Cached input (implicit) / 1M | $0.075 | $0.003 |
| Explicit cache creation, 5 min / 1 h | $1.875 / $3.00 | $0.075 / $0.12 |
| Explicit cache read / 1M | $0.075 | $0.003 |
| Context | 1M | 1M |
| Max input / output | 991K / 128K | 991K / 128K |
| Thinking mode max input / output | 983K / 256K | 983K / 256K |
| Rate limit | 5M tokens/min | 5M tokens/min |
| Input types | Text, image, video | Text, image, video |
| Compatible APIs | OpenAI, DashScope, Anthropic | OpenAI, DashScope, Anthropic |
Both models support function calling, structured JSON output, prefix completion, context caching and built-in web search.
Get a Qwen 4 API key
- Sign in to QwenCloud (Alibaba Cloud Model Studio, international).
- Create an API key in the console.
- Export it in your shell:
export DASHSCOPE_API_KEY="sk-...".
Your key belongs to a region. The base URL must match the region where you created it.
Python example (OpenAI SDK)
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1",
)
stream = client.chat.completions.create(
model="qwen4-35b-a3b", # or "qwen4-max"
messages=[{"role": "user", "content": "Summarize the CAP theorem in three bullets."}],
extra_body={"enable_thinking": True},
stream=True,
)
for chunk in stream:
if not chunk.choices:
continue
delta = chunk.choices[0].delta
reasoning = getattr(delta, "reasoning_content", None)
if reasoning:
print(reasoning, end="", flush=True)
if delta.content:
print(delta.content, end="", flush=True)
Reasoning streams back in reasoning_content, separate from the answer in content. Keep the two apart in your UI and your logs.
Control thinking and effort
Qwen 4 is a hybrid thinking model. On QwenCloud, enable_thinking switches thinking on or off. When you self-host the open model with vLLM or SGLang, the chat template also accepts reasoning_effort:
| Effort | Use for |
|---|---|
xhigh | Hardest problems, where quality matters most |
high | Default for the 35B |
low | Fast replies with minimal thinking |
off | No thinking (same as enable_thinking=False) |
Qwen's sampling recommendations:
- Thinking:
temperature=1.0,top_p=0.95,top_k=20,presence_penalty=0.0 - Non-thinking:
temperature=0.7,top_p=0.80,top_k=20,presence_penalty=1.5
Reasoning tokens are billed as output. At $4.50 per million output tokens on Max, long thinking dominates cost. Artificial Analysis found both Qwen 4 models "very verbose," using 1.8× the median number of tokens.
Estimate your Qwen 4 API cost
A coding turn with 30,000 input tokens and 5,000 output tokens:
| Model | Input | Output | Total |
|---|---|---|---|
qwen4-35b-a3b | $0.0018 | $0.0018 | ~$0.004 |
qwen4-max | $0.045 | $0.0225 | ~$0.068 |
With most of the input served from cache, the input cost drops by 95%. Cache-heavy agent loops (the same repo context every turn) benefit most.
Common Qwen 4 API errors
| Problem | Fix |
|---|---|
| 401 / invalid key | Check that the key region matches the base URL region |
| Model not found | Use the exact IDs qwen4-max or qwen4-35b-a3b, all lowercase |
Empty content but long wait | The model is still thinking; read reasoning_content or disable thinking |
| Answer cut off | Raise max_tokens; check finish_reason == "length" |
| Slow first token on Max | Expected at default high effort; Artificial Analysis measured ~61 s to the first answer token |
Is there a free Qwen 4 API?
There is no permanently free official tier for Qwen 4. Alibaba Cloud often gives new Model Studio accounts a one-time trial token allowance, so check your console. Two lower-cost routes:
- Run the open model yourself. Qwen4-35B-A3B weights are free under Apache-2.0. See Qwen 4 Ollama and VRAM requirements.
- Use glm5.app chat. Qwen 4 35B and Qwen 4 Max are both in the glm5.app model picker, so you can test prompts before you write integration code. No QwenCloud account is needed.
FAQ
What is the Qwen 4 API model ID? qwen4-max for the flagship and qwen4-35b-a3b for the open-weight model.
What is the Qwen 4 API base URL? The international OpenAI-compatible example is https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1. Use the base URL for the region where you created your key.
How much does the Qwen 4 API cost? $1.50 / $4.50 per million input / output tokens for Qwen4-Max, and $0.06 / $0.36 for Qwen4-35B-A3B.
Does the Qwen 4 API support images and video? Yes. Both models accept text, image and video input.
Is the Qwen 4 API compatible with the Anthropic SDK? QwenCloud lists OpenAI-, DashScope- and Anthropic-compatible APIs for both models.
Ship it
Pick qwen4-35b-a3b for cheap, high-volume calls and qwen4-max when you need the bigger model. Point the OpenAI SDK at QwenCloud and budget for reasoning tokens. Want to check output quality before you write any code? Try Qwen 4 35B in glm5.app chat with the exact prompts you plan to send.
Sources
Checked December 5, 2026. Regional prices and limits vary.
- QwenCloud, Qwen4-35B-A3B model page: https://www.qwencloud.com/models/qwen4-35b-a3b
- QwenCloud, Qwen4-Max model page: https://www.qwencloud.com/models/qwen4-max
- Hugging Face model card, Qwen4-35B-A3B: https://huggingface.co/Qwen/Qwen4-35B-A3B
- Artificial Analysis, Qwen4 Max: https://artificialanalysis.ai/models/qwen4-max




