Key takeaways

  • Create a Qwen API key on the API Key page of Alibaba Cloud Model Studio; it starts with sk-, never expires and is shown in full only once.
  • Keys, base URLs and model lists are separate for each of the six regions, and a key used with another region's URL returns a 401 InvalidApiKey error.
  • Only the Singapore region gives new users a free quota, typically 1 million tokens per model for 90 days; after that qwen4-max costs $1.50 per million input tokens and $4.50 per million output tokens there, as of November 29, 2026.

To get a Qwen API key, sign in to Alibaba Cloud Model Studio, open the API Key page, pick a region in the upper-right corner and click Create API Key. The key starts with sk- and is shown in full only once. The region choice matters more than it looks. Alibaba's key guide says a key works only with the endpoint and models of the region where you made it.

This guide is for developers who want to call Qwen4-Max or the cheaper Qwen models from their own code. Every step comes from Alibaba Cloud's Model Studio docs, read on November 29, 2026. The commands below are the docs' own examples and were not run for this guide, which had no key to run them with.

Qwen models are sold through Alibaba Cloud Model Studio, and the API itself goes by DashScope in domain names, in the docs and in the DASHSCOPE_API_KEY variable. A "Qwen API key", a "Model Studio API key" and a "DashScope API key" are the same thing.

What you need first

An Alibaba Cloud account on the international site, with the account information filled in. The free quota page says that since September 15 you have to complete sign-up before you can activate Model Studio at all.

Then curl, or Python with the standard openai package, which the docs point at Alibaba's endpoint.

How to get a Qwen API key

  1. Open the Model Studio console for Singapore. The first time, it shows a service agreement. Agreeing activates Model Studio and grants the free quota.
  2. Go to the API Key page and check the region selector in the upper-right corner. Stay on Singapore unless you have a reason to store data elsewhere, because Singapore is the only region with a free quota.
  3. Click Create API Key. The dialog asks for three things. Leave Owner Account on your main Alibaba Cloud account, leave Workspace on the default workspace, and set Permission to All, which is what the docs recommend. Custom lets you limit the key to certain IP addresses and up to 30 models.
  4. Click OK and copy the key right away. The docs say a new key "is displayed in full only once, at the moment of creation". After you close the dialog the list shows a masked value, and the only way back is to reset the key or make a new one.
  5. Put the key in an environment variable. Alibaba's examples all read DASHSCOPE_API_KEY:
export DASHSCOPE_API_KEY='<YOUR_API_KEY>'

That lasts for the current terminal session. To keep it, the docs append the same line to ~/.bashrc on Linux or ~/.zshrc on macOS.

Keys don't expire. You can have up to 50 per account in each region. For browsers and mobile apps, where a long-lived key would leak, the docs point to a temporary key that lasts at most 1,800 seconds.

Which base URL goes with your key

Each region has its own keys, its own endpoint and its own model list, and the regions page says they "cannot be used across regions". These are the OpenAI-compatible base URLs for the six regions, as of November 29, 2026:

Region Region ID OpenAI-compatible base URL Free quota
Singapore ap-southeast-1 https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1 Yes
US (Virginia) us-east-1 https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/compatible-mode/v1 No
Germany (Frankfurt) eu-central-1 https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/compatible-mode/v1 No
Japan (Tokyo) ap-northeast-1 https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/compatible-mode/v1 No
China (Hong Kong) cn-hongkong https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1 No
China (Beijing) cn-beijing https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1 No

{WorkspaceId} is the ID of your workspace. To get the whole hostname, open Workspace Management in the console and copy the value in the API Host column. It looks like llm-xxx.ap-southeast-1.maas.aliyuncs.com.

Most older tutorials use a different address for Singapore: https://dashscope-intl.aliyuncs.com/compatible-mode/v1. It still works, needs no workspace ID and accepts a key from any workspace in the region, and Alibaba's own key guide gives it as the base URL to paste into tools such as Chatbox. Alibaba now calls it the legacy domain and recommends the workspace one for production, which has a 3,600-second request timeout where the old domain has 600.

For a first test, the old dashscope-intl address is the least work. For anything you plan to keep running, use the workspace URL.

Frankfurt, Tokyo, Hong Kong and Virginia need one more step: before the first call you create a workspace there and choose where inference runs, Global or the local option.

The base URL page also lists Anthropic-compatible addresses. Swap /compatible-mode/v1 for /apps/anthropic on the same host.

How to make your first call

The Model Studio quickstart uses qwen4-max on the Singapore workspace domain. Replace {WorkspaceId} with your own before you run it.

curl "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen4-max",
    "messages": [{"role": "user", "content": "Who are you?"}]
  }'

The same request in Python, after pip install openai:

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["DASHSCOPE_API_KEY"],
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)

response = client.chat.completions.create(
    model="qwen4-max",
    messages=[{"role": "user", "content": "Who are you?"}],
)

print(response.choices[0].message.content)

The model page says the old qwen4-max-preview ID is retired and now routes to qwen4-max at the standard price. Alibaba's recommended models for text are qwen4-max for hard reasoning and coding, qwen3.7-plus as the balanced choice and qwen3.8-flash for speed and low cost.

What the Qwen API costs and what is free

New accounts get a free quota, with conditions. As of November 29, 2026, the free quota page says:

  • Only the Singapore region has it. A key made in any other region is billed from the first token.
  • Each model has its own quota, "typically 1 million tokens". Quotas can't be pooled or moved between models, and a dated snapshot counts as a separate model.
  • It lasts 90 days from the day you activate Model Studio, or from the model's release if that is later. Whatever is left then is gone.
  • It covers real-time calls only. Batch calls and fine-tuning are billed.

When a quota runs out, billing switches to pay as you go without asking. To stop that, turn on Free Quota Only on the Free quota page in the console. It is off by default. With it on, an exhausted model returns HTTP 403 with the code AllocationQuota.FreeTierOnly and nothing is charged. Turn it on before the first call, not after: the docs say the switch can't be enabled for a model whose quota is already used up.

The free list is shrinking. Alibaba removed the quota for qwen3.7-max and qwen3.7-flash on November 19, 2026, and for qwen3.8-max-0902, deepseek-v4-pro and kimi-k3 on November 15.

After the quota, these are the list prices for the Singapore region on the pricing page, per million tokens, as of November 29, 2026:

Model Input Output Free quota listed
qwen4-max $1.50 $4.50 1 million tokens
qwen3.8-max $2.00 $6.00 1 million tokens
qwen3.7-plus, prompts up to 256K tokens $0.40 $1.60 1 million tokens
qwen3.7-plus, prompts over 256K tokens $1.20 $4.80
qwen3.8-flash $0.15 $0.47 1 million tokens

The newest flagship is cheaper than the model it replaced. Qwen4-Max costs $1.50 in and $4.50 out, against $2 and $6 for Qwen3.8-Max, so there is little reason to start on the older one.

The pricing page shows original prices only, and qwen3.7-plus is marked 20% off for a limited time. Prices also differ by region: qwen4-max is $1.413 and $4.24 in Beijing. And the Qwen Flash table lists 1 million free tokens for qwen3.8-flash under a note saying those models have no free quota in any region. The page contradicts itself there, so check the model list in the console, where models with a free quota carry a blue quota bar.

Common errors with a new Qwen API key

These come from Alibaba's error code page.

401, InvalidApiKey, "Incorrect API key provided". The most common cause with a fresh key is a region mismatch: a Beijing key sent to a Singapore base URL, or the reverse. Make the key on the console page for the region whose URL you call. The docs list a second cause that is easy to miss: writing os.getenv("sk-xxx") in Python, which looks for an environment variable named after your key. Use os.getenv("DASHSCOPE_API_KEY").

401 with an sk-sp- key. Keys that start with sk-sp- belong to the Coding Plan or Token Plan subscriptions and work only with their own base URLs. They fail on the pay-as-you-go endpoints above.

401, "NOT AUTHORIZED". The {WorkspaceId} in the URL is wrong, or your account isn't a member of that workspace.

403, AllocationQuota.FreeTierOnly. The free quota for that model is used up and Free Quota Only is on. Turn the switch off to pay as you go, or change the model field to one that still has quota. The API won't switch models for you.

404, ModelNotFound. The model name is misspelled, or the model isn't offered in your region.

400, Arrearage. The Alibaba Cloud account has an unpaid balance. Until it is settled, calls fail even for models with free quota left.

If the code can't find a key you did set, restart the terminal or IDE. The key guide also notes that sudo python script.py drops your environment variables, and sudo -E keeps them.

Other places to get a key for Qwen

A Model Studio key is not the same as a Qwen account login. The key guide warns that the Qwen mode in some third-party tools signs in with a Qwen web account, and that the two "cannot be used interchangeably". A tool that asks for an API key wants the Model Studio key.

OpenRouter also sells access to Qwen through its own key. Its authentication docs say you create one on the API keys page, and it starts with sk-or-v1-. OpenRouter's model list has qwen/qwen4-max at $1.425 per million input tokens and $4.275 per million output tokens as of November 29, 2026, a little under Alibaba's Singapore list price. That route skips the Alibaba Cloud account and the region question, and the free quota with them.

The open-weight Qwen models need no key at all. The guide to running Qwen 3.8 locally covers that. The Kimi API key guide does this for Moonshot's models.

Before you send real traffic, open the Free quota page and check what each model has left and when it expires. The figures change only when you refresh the page, and the docs list a stale page among the reasons people get charged.

Frequently asked questions

Is the Qwen API key free?

Creating the key costs nothing, and new users who activate Model Studio in the Singapore region get a free quota, typically 1 million tokens per model, valid for 90 days. Other regions have no free quota, and when it runs out billing switches to pay as you go unless Free Quota Only is turned on.

What is the Qwen API endpoint?

For Singapore, the OpenAI-compatible base URL is https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1, where {WorkspaceId} is your workspace ID. The older https://dashscope-intl.aliyuncs.com/compatible-mode/v1 still works. Each region has its own URL and its own keys.

How much does the Qwen API cost?

As of November 29, 2026, Alibaba's list price in the Singapore region is $1.50 per million input tokens and $4.50 per million output tokens for qwen4-max, and $0.15 and $0.47 for qwen3.8-flash. Prices differ by region.

Can I use a Qwen API key in Claude Code?

Model Studio has an Anthropic-compatible endpoint: the same host as the OpenAI-compatible one, with /apps/anthropic in place of /compatible-mode/v1. A pay-as-you-go sk- key works there. Coding Plan and Token Plan keys start with sk-sp- and need their own base URLs.

Sources

  1. Obtain an API keyAlibaba Cloud
  2. Model service overviewAlibaba Cloud
  3. Regions and service deployment scopesAlibaba Cloud
  4. Base URL overviewAlibaba Cloud
  5. Free quota for new usersAlibaba Cloud
  6. Model Invocation PricingAlibaba Cloud
  7. Recommended modelsAlibaba Cloud
  8. qwen4-max (latest model)Alibaba Cloud
  9. Error codesAlibaba Cloud
  10. Region and endpoints: SingaporeAlibaba Cloud
  11. AuthenticationOpenRouter
  12. Models APIOpenRouter

Add ClaudeGPT Si as a preferred source on Google