Get your Qwen API key in five minutes
Create an account, activate Model Studio, generate a key, and claim your free tier - then make your first call. Here's the exact sequence, with nothing left out.
What a Qwen API key is - and when you need one
A quick orientation so you don't set up something you don't actually need.
A Qwen API key is a secret credential - a string beginning with sk- - that authenticates your code when it calls Qwen's models programmatically. It is issued through Alibaba Cloud Model Studio, the developer platform for everything Qwen, whose underlying API surface is called DashScope (you'll see both names in the docs; they mean the same service). Every request your application sends includes this key so the platform knows who you are and what to bill.
The important thing to know first: you only need a key if you're a developer building Qwen into your own software. If you just want to chat with Qwen - ask questions, write, analyse documents and images - you don't need a key at all. Open the free Qwen Chat in your browser and start typing. The key is exclusively for the API: calling the models from a script, an app, or a production backend. If that's you, the rest of this page is the complete path from zero to your first working request.
chat.qwen.ai. No key, no account, no payment. The API key is only for programmatic access.Get your API key, step by step
Six steps, about five minutes. Have your email and phone handy for verification.
Create an Alibaba Cloud account
Go to alibabacloud.com and click Sign Up. You'll need a valid email and a phone number for verification. Use the international site unless you're explicitly targeting mainland China deployment - the regions are separate, with separate keys and a separate free tier.
Activate Model Studio
Open the Model Studio product page and click Activate, then accept the Terms of Service. This single step also enables your free quota - 1 million input tokens plus 1 million output tokens, valid for 90 days on the Singapore (International) region.
Open the API Keys page
From the Model Studio console, find the sidebar item labelled API Keys - sometimes shown as Key Management. This is where every key for your account lives.
Click "Create API Key"
You can optionally add a description to track which key belongs to which application - useful later when you have separate keys for production and staging. Each account can hold multiple keys.
Copy the key immediately
Your key starts with sk-. Copy it and store it somewhere safe - a password manager, a .env file, or your platform's secrets manager. Never commit it to a public Git repository. If you lose it, you can return to the API Keys page to view it again, or revoke it and create a new one.
Set it as an environment variable
So you never hardcode the key in your source, export it to your environment. Your code then reads it from there.
# macOS / Linux - current session only export DASHSCOPE_API_KEY="sk-your-key-here" # Make it permanent - add to ~/.bashrc or ~/.zshrc echo 'export DASHSCOPE_API_KEY="sk-your-key-here"' >> ~/.bashrc # Windows PowerShell $env:DASHSCOPE_API_KEY = "sk-your-key-here"
Is the Qwen API key free?
Yes - and the free allowance is generous enough to genuinely prototype with, not just kick the tyres.
New Alibaba Cloud Model Studio accounts in the International (Singapore) region receive 1 million input tokens and 1 million output tokens free, valid for 90 days after you activate Model Studio. That's enough to thoroughly prototype an application, benchmark several models against each other, and prove out an architecture before paying anything. A few details worth knowing so it doesn't surprise you later:
- It applies only to the International (Singapore) endpoint - the US (Virginia) and mainland China regions have no free quota.
- The 1M + 1M is a combined cap across most Qwen models, not per-model - spend it however you like across Max, Plus, Turbo, Coder, VL, and the rest.
- It expires after 90 days whether or not you use it, so don't sit on it.
- Beyond the free quota, billing kicks in automatically using the payment method you added at signup - no surprise overage, since you set up billing during onboarding.
- Reasoning models emit far more output tokens than you might expect, which burns the output half faster - keep an eye on usage in the console.
Your first call with the key
The API is OpenAI-compatible, so your key drops straight into the standard SDK - change three things and you're live.
Install the official openai package, point its base URL at the Qwen endpoint, and pass your key. The three things you change versus a normal OpenAI setup are the base URL, the API key, and the model name - everything else (streaming, function calling, JSON mode) works identically.
Install the SDK
pip install openai
Make a request
import os from openai import OpenAI client = OpenAI( api_key=os.getenv("DASHSCOPE_API_KEY"), # your sk- key base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1", ) completion = client.chat.completions.create( model="qwen-plus", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Say hello and confirm my key works."} ] ) print(completion.choices[0].message.content)
If that prints a reply, your key is live and authenticated. From here every standard feature is available through the same client - streaming responses, tool/function calling, JSON mode, multi-turn conversations, and image inputs on the vision models.
curl https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions \ -H "Authorization: Bearer $DASHSCOPE_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"qwen-plus","messages":[{"role":"user","content":"Hi"}]}'
Your key is tied to a region
Model Studio runs in four regions, each with its own endpoint and its own keys - and they are not interchangeable.
This is the single most common source of confusion, so it's worth getting right up front. A key created on the Singapore endpoint will fail authentication on the Beijing or US endpoints, and vice versa. Pick the region closest to your users - or whichever your compliance team approves - and use that base URL everywhere. If you ever get a 401 error, a mismatched base URL is more likely the cause than a bad key.
| Region | Base URL | Notes |
|---|---|---|
| Singapore (International) | dashscope-intl.aliyuncs.com/compatible-mode/v1 | Default for non-China teams · has the free tier |
| US (Virginia) | dashscope-us.aliyuncs.com/compatible-mode/v1 | Lowest latency for US teams |
| China (Beijing) | dashscope.aliyuncs.com/compatible-mode/v1 | Mainland China deployments |
| Hong Kong | cn-hongkong.dashscope.aliyuncs.com/compatible-mode/v1 | Hong Kong region |
Protecting your API key
A leaked key is a leaked credit card - anyone who has it can spend on your account. A few habits keep that from happening.
Your key is a secret that authorizes billable usage, so treat it with the same care as a password. The good news is that safe handling is mostly a matter of a few simple, durable habits - set them once and you rarely have to think about it again.
- Never hardcode it in source files - read it from an environment variable or secrets manager instead.
- Never commit it to Git, especially a public repo. Add
.envto your.gitignorebefore your first commit. - Never expose it in client-side code - browser or mobile apps should call your own backend, which holds the key, never ship it to the device.
- Use separate keys for production, staging, and each application, so you can revoke one without breaking the others.
- Rotate and revoke from the API Keys page if a key is ever exposed - revoke the old one and issue a new one immediately.
- Monitor usage in the Model Studio console so an unexpected spike (a sign of a leak) gets caught early.
Frequently asked questions
How long does it take to get a Qwen API key?
Is the Qwen API key really free?
Do I need an API key to use Qwen Chat?
What does a Qwen API key look like?
sk-, issued from the API Keys page in the Model Studio console. You pass it as a Bearer token (or via the SDK's api_key parameter) on every request. Store it in a password manager, a .env file, or a secrets manager - never in source code.