Alibaba Cloud Model Studio API Key: 4 Steps to Your First Request

Blog / AI concepts

Alibaba Cloud Model Studio API Key: 4 Steps to Your First Request

You create an Alibaba Cloud Model Studio API key in the Model Studio console (known in China as 阿里云百炼, or Bailian). Sign in to your Alibaba Cloud account, activate the Model Studio service, create a new key on the API Key management page, then put it into an SDK or tool to call Qwen (通义千问). Model Studio offers an OpenAI-compatible mode, so most tools that ask for an "endpoint + key" only need those two values swapped.

The steps below are in order. Console menu names and page layouts change with redesigns, so treat the official Alibaba Cloud documentation and the current console UI as the source of truth for exact locations.

How many steps does it take to get a Model Studio API key?

Roughly four:

  1. Register and sign in to an Alibaba Cloud account, and complete identity verification if the page asks for it. The exact requirements are set by Alibaba Cloud.
  2. Open the Model Studio console and activate the model service. First-time entry usually shows an activation prompt and an agreement to confirm.
  3. Find the API Key management page in the console and create an API key. Copy and save it right away; afterward the page may show only part of the characters.
  4. Store the key in a local environment variable, then send one request to verify it.

In a lot of documentation this key is also called a DashScope API key. DashScope is the name of the model-service API behind Model Studio, so searching "dashscope api key" and "Model Studio api key" points to the same kind of credential.

Two things to confirm first:

  • Keys are usually tied to a region. The China site and the international site have separate consoles, keys, and endpoint addresses, and using the wrong region produces an authentication failure. Check the official documentation for the exact split.
  • If your account belongs to a company, business workspaces and sub-account permissions may be involved, and an administrator assigns them. This varies by company, so I won't go into it here.

What base URL do you use for compatible mode?

Model Studio provides an OpenAI-compatible endpoint. For the China site, the compatible-mode base_url in the official documentation looks like this:

https://dashscope.aliyuncs.com/compatible-mode/v1

The international site uses a different domain. Check the official documentation instead of reconstructing it from memory. In a tool, the fields map like this:

Field in the toolWhat to enter
Base URL / endpointThe compatible-mode address above
API KeyThe key you created in Model Studio
ModelThe model identifier from the console's model list

I'm not listing model identifiers here because model versions change quickly. Look at the model list in the Model Studio console or the official model documentation. If you want to understand what "compatible" actually covers, read What does "OpenAI-compatible API" mean, and why do so many tools only ask for an address and a key?

How do you write the first request?

First put the key in an environment variable instead of writing it into code:

export DASHSCOPE_API_KEY="your key"

Then call the compatible address with the OpenAI Python SDK:

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["DASHSCOPE_API_KEY"],
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)

resp = client.chat.completions.create(
    model="<model identifier from the console>",
    messages=[{"role": "user", "content": "Introduce yourself in one sentence"}],
)
print(resp.choices[0].message.content)

Replace model with a model identifier you actually see in the console and that your account is allowed to call. For SDK installation and basic usage, see Calling the OpenAI API from Python: from installing the SDK to printing a reply; switching to Model Studio changes only api_key and base_url. For the full "from getting a key to receiving a reply" flow, see How do you use an LLM API? From getting a key to your first reply.

What if the request fails?

Check in this order and you can usually pin it down:

SymptomCheck first
401 or authentication failureWhether the key was copied completely and has no extra spaces; whether you mixed up the China and international sites
404 or wrong pathWhether base_url includes /compatible-mode/v1, and whether you accidentally appended /chat/completions
Model not found or no permissionThe spelling of the model identifier; whether that model needs to be activated separately in the console
429You hit a rate or quota limit; read the console's rate-limit notes and retry later
TimeoutA local network problem or a service fluctuation

If you suspect a service problem, see cdnping's Alibaba Cloud Model Studio status page, which probes the official API entry point on a schedule from the Cloudflare edge. Note that this reflects whether the entry point is reachable, not whether requests from your account will definitely succeed. For background on latency, see How to read AI API latency from China.

Where do you see cost and usage?

Billing rules, free quotas, and per-model prices all get adjusted, so I'm not writing specific numbers here. I suggest doing three things:

  • Check the unit price of the model you plan to use on the model page in the Model Studio console or in the official pricing notes, and distinguish input tokens from output tokens.
  • Look at actual charges on Alibaba Cloud's billing pages, and confirm whether you have a free quota and when it expires.
  • Before you start making calls in bulk, estimate your monthly usage. See How do you calculate LLM API cost? An estimation formula you can reuse for a method.

How should you store the key?

  • Keep it only in environment variables or a secrets manager. Don't commit it to Git, and don't paste it into chats or screenshots.
  • Use a different key for each project, so a leak means revoking only one.
  • If you suspect a leak, delete or disable the key in the console, create a new one, and check your bill for anomalies. The process is similar across providers; see Your OpenAI API key leaked: revoke it now, check usage, and prevent a repeat.
  • Don't share your key with other people. The terms of use are those in Alibaba Cloud's official agreement.

What if you use several providers' models?

Model Studio is just one of many services that offer a compatible API. If you need several Chinese and international models at once, opening an account and storing a separate key for each provider raises your management overhead. For the different approaches in principle, see How can one API key call models from multiple providers? How API compatibility and gateways work.

One disclosure: AGI Plan is a commercial partner of cdnping. AGI Plan is a multi-provider LLM aggregation gateway. It is sold as a monthly subscription, is paid in RMB, and needs no overseas credit card. It is compatible with both the OpenAI and Anthropic API formats, so tools like Claude Code and Codex only need one endpoint address changed. It is organized into capability groups such as frontier reasoning, balanced general-purpose, Chinese flagship, and fast lightweight, and some models are available only outside China; see the AGI Plan models page for specifics. The site also states that it is not an officially authorized channel. If all you need is Qwen, using Model Studio directly is enough. If you need to switch between several capabilities, take a look at the AGI Plan getting-started page.

What should you do next?

  1. Follow the steps above to activate the service, create a key, and get the first request working.
  2. Confirm usage and billing in the console, and set up spending alerts if they're offered.
  3. Put the key into the tools you use most, such as a client that supports a custom endpoint address.
  4. To understand the concept of an API key first, read What is an API key? 5 things beginners should know before using an AI API.

You can also go to the cdnping home page to test connection time to each AI API from your current network, as a reference when choosing an entry point.

Related articles

Keep reading