How to Get a Qwen API Key: A Step-by-Step Guide
On this page
This guide shows you how to get a Qwen API key. You'll create an Alibaba Cloud Model Studio account, generate your key, and make your first API call, plus a free alternative for adding Qwen models to your web app.
Prerequisites
- An email account
- Basic familiarity with code (we'll show simple JavaScript examples)
Step 1: Create Your Alibaba Cloud Account
Go to modelstudio.console.alibabacloud.com. You'll see the Model Studio landing page.
Click the Login button at the top right and complete the sign-up or login with your email.
Step 2: Generate Your API Key
Once logged in, go to the Dashboard tab.
In the sidebar, click API Keys to open the API key management page.
Click + Create API Key. Enter an optional description for your key.
Once created, copy your API key.
Store it somewhere safe — a password manager, an .env file, or your platform's secrets manager. Never commit API keys to a public repository. You can come back to the API keys page later to retrieve your key again.
Step 3: Make Your First API Call
Qwen uses an OpenAI-compatible API, so you can use the OpenAI SDK directly. Install it first:
npm install openai
Then make your first call:
import OpenAI from "openai";
const openai = new OpenAI({
baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
apiKey: process.env.DASHSCOPE_API_KEY,
});
const completion = await openai.chat.completions.create({
model: "qwen3.6-27b",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Hello, world!" },
],
});
console.log(completion.choices[0].message.content);
If you get a response back, everything is working. For the full set of endpoints and parameters, see Qwen's official API docs.
Can You Use the Qwen API for Free?
Creating an API key is free, but using it requires paying per token. New Alibaba Cloud accounts get a free quota of 1 million tokens for each eligible model on the International (Singapore) endpoint, valid for 90 days after activating Model Studio. The free quota exists only in the Singapore region, and the old free OAuth API tier was discontinued on April 15, 2026, so older tutorials promising standing free access are out of date.
Puter.js offers a different model. With its User-Pays model, you can add Qwen models to your app for free: each user covers their own AI usage through their own Puter account, so your cost stays at $0 regardless of how many users you have, with no API key and no backend.
Add Qwen models with the browser script tag:
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.chat("Explain quantum computing in simple terms", {
model: "qwen/qwen3.6-flash"
}).then(response => {
document.body.innerHTML = response.message.content;
});
</script>
or the npm package:
import { puter } from '@heyputer/puter.js';
const response = await puter.ai.chat("Explain quantum computing in simple terms", {
model: "qwen/qwen3.6-flash"
});
console.log(response.message.content);
This fits front-end apps where your users sign into Puter: usage is tied to their accounts, and Puter.js runs in the browser, so it does not replace a server-side key for a backend you control. For a backend, see the pricing below.
How Much Does the Qwen API Cost?
Qwen bills per token, with separate input and output rates, so cost scales with usage instead of a flat fee. Alibaba's current flagship, Qwen3.7 Max, is $1.25 per 1M input tokens and $3.75 per 1M output. The cheapest current model, Qwen3.6 Flash, is $0.19 input and $1.13 output. The rates above are for the International (Singapore) endpoint; the Chinese Mainland (Beijing) endpoint is 60 to 70% cheaper.
For the full breakdown, including the region and tier rules and the per-model rates, see our Qwen API pricing guide.
Why Isn't My Key Working?
Most first-call failures trace back to a few errors:
- 401, InvalidApiKey: the key is wrong, was revoked, or picked up a stray space or newline when copied. It also appears when the key's region does not match the base URL, so confirm you are using the endpoint for the account that issued the key.
- 400, Arrearage: the account has an overdue payment or no balance. Add funds in the Alibaba Cloud console, wait for the balance to update, then retry.
- 429, Throttling.RateQuota: requests are going out faster than your rate limit (RPM or TPM) allows. Add retries with exponential backoff, or apply for a higher quota.
- 404, ModelNotFound: the model name is misspelled or the model is not activated in your workspace. Check the exact model ID and enable it for the account.
- 403, AccessDenied: the account is not eligible for the requested model, often because it has not been purchased or activated.
Most of these come back to billing, so check that first. For the full list of status and error codes, see Qwen's error codes reference.
Conclusion
To get a Qwen API key: sign up at Alibaba Cloud Model Studio, then go to the Dashboard, open API Keys, and click + Create API Key. From there you can make your first API call, or skip the key entirely and add Qwen models to a web app for free with Puter.js.
Related
- Qwen API Pricing
- Free, Unlimited Qwen API
- Free, Unlimited Claude API
- How to Get an OpenAI API Key
- How to Get an Anthropic (Claude) API Key
- How to Get a Gemini API Key
- How to Get a Grok (xAI) API Key
- How to Get a DeepSeek API Key
- How to Get an ElevenLabs API Key
- How to Get a Mistral API Key
- How to Get a MiniMax API Key
- How to Get a Moonshot AI (Kimi) API Key
- How to Get an OpenRouter API Key
- How to Get a FLUX (Black Forest Labs) API Key
- How to Get a Stability AI (Stable Diffusion) API Key
- How to Get a Kling API Key
- How to Get a Leonardo.Ai API Key
- How to Get a Together AI API Key
- How to Get a Cohere API Key
- How to Get a Z.AI (GLM) API Key
- How to Use OpenAI SDK with Puter
- Free, Unlimited OpenAI API
- Free, Unlimited Gemini API
- How to Use LangChain with Puter
- How to Use Vercel AI SDK with Puter