Step-by-step guide · 2026

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.

sk-•••••••••••••••••••••••••••
~5 min
Start to finish
1M + 1M
Free tokens, 90 days
$0
To start
sk-
Key format
Before you start

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.

Just want to use the AI, not build with it? Skip everything below - head to the free chat at chat.qwen.ai. No key, no account, no payment. The API key is only for programmatic access.
The walkthrough

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"
That's the whole process. Account → activate Model Studio → create key → copy → store as an environment variable. From here you're ready to install an SDK and make your first call.
Free tier

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.
Casual experiments? Third-party aggregators like OpenRouter also expose Qwen with their own free tiers and unified billing. They cost slightly more per token than DashScope direct, but signup is faster and one key reaches multiple providers.
Put it to work

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, if you prefer. The same call works from the command line - useful for a quick smoke test that your key authenticates before you write any code.
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"}]}'
Pick the right region

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.

RegionBase URLNotes
Singapore
(International)
dashscope-intl.aliyuncs.com/compatible-mode/v1Default for non-China teams · has the free tier
US
(Virginia)
dashscope-us.aliyuncs.com/compatible-mode/v1Lowest latency for US teams
China
(Beijing)
dashscope.aliyuncs.com/compatible-mode/v1Mainland China deployments
Hong Kongcn-hongkong.dashscope.aliyuncs.com/compatible-mode/v1Hong Kong region
Regional keys are not interchangeable. The free tier exists only on Singapore (International), so for most new developers outside China that is the right choice. Match your key's region to the base URL in your code and you'll avoid the most frequent setup error.
Keep it safe

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 .env to your .gitignore before 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.
If a key leaks, act fast. Revoke it from the API Keys page right away - that immediately invalidates it everywhere - then create a replacement and update your environment. Because each app can have its own key, a single revocation needn't take down your whole system.
FAQ

Frequently asked questions

How long does it take to get a Qwen API key?
About five minutes. Create an Alibaba Cloud account, activate Model Studio (which also enables your free quota), open the API Keys page, create a key, and copy it. Then set it as an environment variable, install the openai package, and you can make your first request right away.
Is the Qwen API key really free?
There's a free tier: new accounts on the Singapore (International) region get 1 million input plus 1 million output tokens, valid for 90 days. That's enough for serious prototyping. After the quota, you pay per token using the billing method you set up at signup. The US and mainland China regions don't include the free quota.
Do I need an API key to use Qwen Chat?
No. The web chat and mobile apps need no key at all - just sign in or use guest mode. An API key is only for developers calling Qwen programmatically through Model Studio / DashScope. The two are completely separate.
What does a Qwen API key look like?
It's a secret string that begins with 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.
Why does my key return a 401 error?
Almost always one of three things: the base URL doesn't match your key's region (a Singapore key fails on Beijing or US endpoints), the environment variable isn't actually loaded in your shell, or the key is from a sub-workspace without model permissions. Check the URL first - it's the most common cause.
Can I have more than one key?
Yes. Each Model Studio account can hold multiple keys, which is the recommended way to separate production from staging or to give different applications their own credentials. If one is compromised, you revoke just that key without disrupting everything else.
What if I lose my key?
Return to the API Keys page in the Model Studio console - you can view the existing key again, or revoke it and create a new one. If there's any chance it was exposed, revoke and replace it rather than reusing it.
Can I use the key from outside Alibaba Cloud?
Yes. There's no requirement to use any other Alibaba Cloud service. You can call the API with your key from AWS, GCP, Azure, your laptop, or anywhere else - all that matters is which regional endpoint you target and whether your network can reach it.
Is the API OpenAI-compatible?
Yes. Your key works with the official openai Python and JS SDKs, LangChain, LiteLLM, and other OpenAI-protocol tools. To migrate existing code you change three things - the base URL, the API key, and the model name. Streaming, function calling, and JSON mode behave the same.