Qwen API Guide: Python & Node.js Integration Outside China
Alibaba's Qwen-3 matches GPT-4 on MMLU benchmarks and supports up to 1 million token context. This guide shows how to access the Qwen API globally via ChinaModelAPI's OpenAI-compatible endpoint — with working Python and Node.js code examples.
What Is the Qwen API?
The Qwen API is Alibaba Cloud's developer interface for their Qwen (通义千问) large language model series. The API follows the OpenAI chat completions format, making it a drop-in replacement for developers already using GPT models.
Key Qwen API facts:
- • OpenAI-compatible — same request/response format as GPT
- • Qwen-Max context window — up to 1,000,000 tokens
- • Languages — multilingual (100+), excels at Chinese-English
- • MMLU score — Qwen-3 ~88%, competitive with GPT-4o (88.7%)
- • Supports — chat, function calling, streaming, vision (Qwen-VL)
Qwen Models: Which One to Use?
| Model ID | Best For | Context | Speed | Cost |
|---|---|---|---|---|
| qwen-3 | General tasks, latest performance | 128K | Fast | $$ |
| qwen-max | Long docs, complex reasoning | 1M | Moderate | $$$ |
| qwen-plus | Balanced: speed + quality | 128K | Fast | $$ |
| qwen-2.5 | Stable production workloads | 128K | Fast | $ |
| qwen-2.5-coder | Code generation & completion | 128K | Fast | $ |
How to Access Qwen API Outside China: 4 Steps
-
1
Create a ChinaModelAPI account
Sign up at chinamodelapi.com — no credit card required.
-
2
Purchase tokens with USDT
Starter plan ($9.9) is sufficient for testing. Tokens never expire.
-
3
Copy your API key
Your key from the dashboard works across all Qwen models.
-
4
Change base_url in your SDK
One line of code — see examples below.
Python Integration: Qwen API
Install the OpenAI Python SDK: pip install openai
from openai import OpenAI
client = OpenAI(
base_url="https://api.chinamodelapi.com/v1",
api_key="your-chinamodelapi-key"
)
response = client.chat.completions.create(
model="qwen-3", # or qwen-max, qwen-plus, qwen-2.5
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain transformer architecture in 3 sentences."}
],
max_tokens=1024
)
print(response.choices[0].message.content)
For streaming responses:
stream = client.chat.completions.create(
model="qwen-max",
messages=[{"role": "user", "content": "Write a Python function for binary search."}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
Node.js Integration: Qwen API
Install: npm install openai
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.chinamodelapi.com/v1",
apiKey: "your-chinamodelapi-key"
});
const response = await client.chat.completions.create({
model: "qwen-3", // or "qwen-max", "qwen-plus"
messages: [
{ role: "user", content: "Translate this to Chinese: Hello, world!" }
]
});
console.log(response.choices[0].message.content);
Frequently Asked Questions
Can I use the Qwen API for free?
ChinaModelAPI does not offer a free tier, but the Starter plan at $9.9 provides substantial tokens for testing and small projects. Tokens never expire, so there's no time pressure to use them up.
Does Qwen API support function calling?
Yes. Qwen-3 and Qwen-Max support OpenAI-compatible function calling (tool use). The request format is identical to OpenAI's — define your tools in the tools parameter and the model will return structured function calls.
What is Qwen-Max's context window?
Qwen-Max supports up to 1,000,000 tokens of context — equivalent to roughly 750,000 words or a full book. This is one of the largest context windows available, making it ideal for analyzing long documents, codebases, or research papers.
Is there a rate limit on the Qwen API?
Rate limits depend on your plan tier. Starter has basic limits suitable for development. Pro and above provide higher throughput. Enterprise plans include custom rate limits and SLA guarantees. Contact us for specific numbers.
Related Guides
Ready to use the Qwen API? Get access in under 5 minutes.
Get Early Access