Qwen family
Alibaba Cloud’s Qwen text models, including the Qwen3.8, Qwen3.7 and Qwen3.6 series, Qwen Flash and Qwen Plus. They are called through the OpenAI-compatible API, and the Qwen3.x series also supports the Anthropic-native API. For image generation models, see Qwen-Image.
Common tasks
Models
For the full model list and live prices, see the model page , or query the Models API. You can omit the qwen/ prefix from model IDs.
qwen/qwen3.8-maxSupports image inputqwen/qwen3.8-flashSupports image inputqwen/qwen3.7-plusSupports image inputqwen/qwen-flashNo thinking by default; text onlyQwen models are served by Alibaba Cloud Model Studio through two providers, the China site (aliyun) and the international site (alicloud), selected automatically by default. For how to select one, see Provider routing.
Examples
Python
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.ofox.io/v1", api_key=os.environ["OFOX_API_KEY"])
resp = client.chat.completions.create(
model="qwen/qwen3.8-flash",
messages=[{"role": "user", "content": "Explain idempotency in one sentence."}],
extra_body={"enable_thinking": False},
)
print(resp.choices[0].message.content)Thinking mode
In our tests on the same math problem, Qwen3.8 Flash thought for about 5,800 tokens by default and took about 1.5 minutes, while Qwen3.6 Flash thought for over 30,000 tokens and took more than 4 minutes; with thinking off, both returned within a few seconds.
Capping thinking length
When you need thinking but want to control latency and cost, pass thinking_budget (a cap on thinking tokens):
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.ofox.io/v1", api_key=os.environ["OFOX_API_KEY"])
resp = client.chat.completions.create(
model="qwen/qwen3.8-flash",
messages=[{"role": "user", "content": "Find all positive integers n less than 50 for which n² + n + 41 is not prime."}],
extra_body={"enable_thinking": True, "thinking_budget": 1000},
)
msg = resp.choices[0].message
details = getattr(msg, "reasoning_details", None) or []
print("[Thinking]", "".join(d.get("text", "") for d in details)[:200], "…")
print("[Answer]", msg.content)
print("Thinking tokens:", resp.usage.completion_tokens_details.reasoning_tokens)- In our tests
thinking_budgetis enforced strictly: set to 200, thinking used exactly 200 tokens. enable_thinkingandthinking_budgetare not standard OpenAI SDK parameters, so put them inextra_body; when sending raw HTTP requests, put them at the top level of the request body.- Thinking tokens are billed at the output rate; the count is in
usage.completion_tokens_details.reasoning_tokens.
Reading the thinking content
- In streaming responses, thinking content is in
delta.reasoning_content, the same as the official Alibaba Cloud Model Studio API. - In non-streaming responses, thinking content is in
message.reasoning_details; concatenate thetextof each item in order (see the example above).
Image input
Models that support image input use the standard image_url content block:
import base64
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.ofox.io/v1", api_key=os.environ["OFOX_API_KEY"])
img_b64 = base64.b64encode(open("photo.png", "rb").read()).decode()
resp = client.chat.completions.create(
model="qwen/qwen3.8-flash",
messages=[{"role": "user", "content": [
{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{img_b64}"}},
{"type": "text", "text": "Describe this image."},
]}],
extra_body={"enable_thinking": False},
)
print(resp.choices[0].message.content)Qwen3.7 Max, Qwen Plus and Qwen Flash are text-only; use one of the image-capable models in the table above instead.
Use in Claude Code
The Qwen3.x series and Qwen Flash support the Anthropic-native API at https://api.ofox.io/anthropic:
https://api.ofox.io/anthropicqwen/qwen3.8-max- On the Anthropic API, thinking content is returned as
thinkingblocks. - The Qwen3.8 series thinks a lot, so set a large enough
max_tokens. In our tests, withmax_tokensat 4000 the response could contain only athinkingblock and no answer. - Qwen Plus does not support the Anthropic API; calls return
protocol_not_supported.
For full Claude Code setup steps, see Claude Code setup.
JSON output and tool calling
response_format supports {"type": "json_object"} and {"type": "json_schema", ...}; tool calling uses the standard tools parameter. When using json_object, state “return JSON” and the required fields in the prompt. For the syntax, see Structured output and Function calling.
Prompt caching
Qwen automatically caches repeated request prefixes, with no changes to your request. The cached amount is in usage.prompt_tokens_details.cached_tokens, and the cached portion is billed at the cache read rate. Caching is best-effort; requests with the same prefix may still miss.
Common errors
For other general errors, see Error Handling.
Official docs
- Alibaba Cloud Model Studio · Models
- Alibaba Cloud Model Studio · Deep thinking
- Alibaba Cloud Model Studio · OpenAI compatibility
The official docs describe behavior when calling Alibaba Cloud Model Studio directly. When calling through OfoxAI, model IDs and endpoints on this page take precedence.
FAQ
How do I write a Qwen model ID?
The standard format is qwen/qwen3.8-flash; you can also omit the qwen/ prefix.
How do I turn off Qwen thinking?
Pass "enable_thinking": false; with the OpenAI SDK, put it in extra_body. The Qwen3.8, 3.7 and 3.6 series think by default; Qwen Flash and Qwen Plus do not.
Why does Qwen take several minutes to respond?
The Qwen3.x series thinks by default, and complex questions can use tens of thousands of thinking tokens. Turn thinking off, or cap its length with thinking_budget, e.g. "thinking_budget": 1000.
How do I use Qwen thinking_budget?
Pass it together with "enable_thinking": true; the value is the cap on thinking tokens, e.g. 1000. In our tests it is enforced strictly.
Which Qwen models can understand images?
Qwen3.8 Max, 3.8 Flash, 3.8 27B, 3.7 Plus and 3.6 Flash support image input. Qwen3.7 Max, Qwen Plus and Qwen Flash are text-only.
Can I use Qwen in Claude Code?
Yes. Set ANTHROPIC_BASE_URL to https://api.ofox.io/anthropic and use a Qwen3.x series model such as qwen/qwen3.8-max. Qwen Plus does not support the Anthropic API.
Where is Qwen reasoning_content?
In streaming responses it is in delta.reasoning_content; in non-streaming responses it is in message.reasoning_details, where you concatenate the text of each item.