All Products
Search
Document Center

Alibaba Cloud Model Studio:Obtain an API key

Last Updated:Nov 27, 2026

Before you use models or applications in Alibaba Cloud Model Studio, you must obtain an API key for authentication.

Plan type identification

Model Studio provides three types of API Keys. The API Key and Base URL must be used as a matching pair; otherwise, calling the Anthropic-compatible endpoint may return 401 or 403 errors.

API Key prefix

Plan type

Anthropic-compatible Base URL

sk-

Pay-as-you-go

https://dashscope-intl.aliyuncs.com/apps/anthropic

sk-sp-

Token Plan

https://token-plan.ap-southeast-1.maas.aliyuncs.com/apps/anthropic

sk-sp-

Coding Plan

https://coding-intl.dashscope.aliyuncs.com/apps/anthropic

View plan type

  1. Log on to the Model Studio console.
  2. Click Subscribe in the top navigation bar and select Token Plan from the expanded menu, or go to the My Subscriptions page.
  3. On the My Subscriptions page, view the subscription status on the Coding Plan and Token Plan tabs, together with the corresponding API Key and Base URL.

Obtain an API Key

  1. Go to the Alibaba Cloud Model Studio API Key page and select a region in the upper-right corner. Each region has its own endpoint domain, API Keys, and model list, which cannot be used across regions. For the API Key entry and endpoint domain of each region, see Access information for each region.

  2. To create an API Key, click Create API Key, configure the following options in the dialog box, and then click OK (if you cannot create one, contact the super admin or a workspace admin):

    • Owner Account: Alibaba Cloud account (primary account) is selected by default (the account name is usually a string of digits). To create API Keys with independent ownership and permissions for team members or applications and combine them with workspaces for fine-grained model access control, you can select RAM users (account format username@<AccountAlias>.onaliyun.com).
    • Workspace: Default workspace is selected by default. Keys in this workspace can call all standard models (for the quantity limit and primary account quota, see Validity and limits). For permission isolation, fine-grained model access control, or independent cost accounting, select a non-default workspace. For more information, see Workspaces.
    • Permission: All is recommended. For fine-grained control, you can select Custom and configure the accessible IP addresses and Access Model Scope (for the quantity limit, see Validity and limits).
  3. After the API Key is created, immediately copy (or download and save) the complete API Key in the dialog box that appears. A new API Key is displayed in full only once, at the moment of creation. After you close the dialog box, only masked values are shown in the list, and the complete plaintext cannot be viewed or copied again. If you did not save it, you can only reset the API Key or create a new one.

NoteSome legacy API Keys can still be copied in full directly from the list; check whether the list provides a copy entry.

Configure the API Key in environment variables

  • Method 1: Configure in a third-party tool

    If you call models in tools or platforms such as Chatbox, you may need to enter the following three pieces of information:

    • The API Key obtained in this document

    • Base URL:

      • Singapore: https://dashscope-intl.aliyuncs.com/compatible-mode/v1
      • Other regions: see Base URL overview
    • Model names, such as qwen-plus, qwen-max, and deepseek-v4-pro.

    The Model Studio API Key is used to call Model Studio API endpoints. For the API Key prefix and Base URL of each plan, refer to the "Plan type identification" section of this document. The Qwen mode of some third-party tools logs in with a Qwen web account (qwenauth), which is a different authentication method from the Model Studio API Key: when the tool requires an API Key, use the Model Studio API Key; when the tool requires account login, use the Qwen web account. The two cannot be used interchangeably; otherwise the call will fail and may return errors such as "no quota".

  • Method 2: Configure the API Key in environment variables to support subsequent cURL and code calls

    ImportantDo not configure or use long-term API Keys in client-side code (such as browsers and mobile apps) or in untrusted environments. You can use a temporary API Key (valid for up to 1800 seconds).

    In the following examples, replace <YOUR_API_KEY> with your actual API Key.

    Linux

    Add a permanent environment variable

    Append the environment variable settings to the ~/.bashrc file.

    echo "export DASHSCOPE_API_KEY='<YOUR_API_KEY>'" >> ~/.bashrc
    source ~/.bashrc
    echo "百炼 API Key 永久配置为:${DASHSCOPE_API_KEY:0:10}*********"
    

    Add a temporary environment variable

    export DASHSCOPE_API_KEY='<YOUR_API_KEY>'
    echo "当前会话百炼 API Key 配置为:${DASHSCOPE_API_KEY:0:10}*********"
    

    Service manager (systemd)

    The following operations apply to scenarios where you deploy your application as a backend service.

    1. Create an environment file
    sudo sh -c "echo 'DASHSCOPE_API_KEY=<YOUR_API_KEY>' > /etc/your-app/env"
    sudo chmod 600 /etc/your-app/env # 限制只有root用户有访问权限
    
    1. Edit the systemd service file (for example, /etc/systemd/system/your-app.service):
    [Service]
    # 加载密钥文件
    EnvironmentFile=/etc/your-app/env
    ExecStart=/usr/bin/python /opt/your-app/main.py
    
    1. Reload the service
    sudo systemctl daemon-reload
    sudo systemctl restart your-app
    

    macOS

    Add a permanent environment variable

    Append the environment variable settings to the ~/.bash_profile or ~/.zshrc file.

    VAR_VALUE="<YOUR_API_KEY>"; \
    echo "export DASHSCOPE_API_KEY='$VAR_VALUE'" >> ~/.zshrc 2>/dev/null
    echo "export DASHSCOPE_API_KEY='$VAR_VALUE'" >> ~/.bash_profile 2>/dev/null
    source ~/."${SHELL##*/}rc" 2>/dev/null
    echo "百炼 API Key 永久配置为:${DASHSCOPE_API_KEY:0:10}*********"
    

    Add a temporary environment variable

    export DASHSCOPE_API_KEY='<YOUR_API_KEY>'
    echo "当前会话百炼 API Key 配置为:${DASHSCOPE_API_KEY:0:10}*********"
    

    Windows

    On Windows, you can configure environment variables via system properties, CMD, or PowerShell.

    System properties

    Notes on the system properties method:

    • The environment variable takes effect permanently.
    • Modifying system environment variables requires administrator privileges.
    • The configuration does not immediately affect command windows, IDEs, or other applications that are already open; you must restart these programs or open a new command line for the environment variable to take effect.
    1. On the Windows desktop, press Win+Q and search for Edit the system environment variables, then click to open the System Properties interface.

    2. In the System Properties window, click Environment Variables, then click New under the System variables section, fill in DASHSCOPE_API_KEY as the Variable Name, and enter your DashScope API Key as the Variable Value.

    3. Click OK in the three windows in turn to close the system properties configuration page and complete the environment variable configuration.

    4. Open a CMD (command prompt) window or a Windows PowerShell window, and run the following command to check whether the environment variable takes effect.

      • CMD query command:
    echo 百炼 API Key 永久配置为:%DASHSCOPE_API_KEY:~0,10%*********
    
    • Windows PowerShell query command:
    Write-Host "百炼 API Key 永久配置为:$($env:DASHSCOPE_API_KEY.Substring(0, [Math]::Min(10, $env:DASHSCOPE_API_KEY.Length)))*********"
    

    CMD

    Add a permanent environment variable

    If you want the API Key environment variable to take effect in all new sessions of the current user, follow these steps.

    1. Run the following command in CMD.
    setx DASHSCOPE_API_KEY "<YOUR_API_KEY>"
    
    1. Open a new CMD window.
    2. Run the following command in the new CMD window to check whether the environment variable takes effect.
    echo 百炼 API Key 永久配置为:%DASHSCOPE_API_KEY:~0,10%*********
    

    Add a temporary environment variable

    If you only want to use the environment variable in the current session, run the following command in CMD.

    set "DASHSCOPE_API_KEY=<YOUR_API_KEY>"
    

    You can run the following command in the current session to check whether the environment variable takes effect.

    echo 当前会话百炼 API Key 配置为:%DASHSCOPE_API_KEY:~0,10%*********
    

    PowerShell

    Add a permanent environment variable

    If you want the API Key environment variable to take effect in all new sessions of the current user, follow these steps.

    1. Run the following command in PowerShell.
    [Environment]::SetEnvironmentVariable("DASHSCOPE_API_KEY", "<YOUR_API_KEY>", [EnvironmentVariableTarget]::User)
    
    1. Open a new PowerShell window.
    2. Run the following command in the new PowerShell window to check whether the environment variable takes effect.
    Write-Host "百炼 API Key 永久配置为:$($env:DASHSCOPE_API_KEY.Substring(0, [Math]::Min(10, $env:DASHSCOPE_API_KEY.Length)))*********"
    

    Add a temporary environment variable

    If you only want to use the environment variable in the current session, run the following command in PowerShell.

    $env:DASHSCOPE_API_KEY = "<YOUR_API_KEY>"
    Write-Host "当前会话百炼 API Key 配置为:$($env:DASHSCOPE_API_KEY.Substring(0, [Math]::Min(10, $env:DASHSCOPE_API_KEY.Length)))*********"
    

Validity and limits

API Keys have no expiration limit. If you need a time-limited API Key, you can generate a temporary API Key (valid for up to 1800 seconds).

The status of an API Key changes with account operations. Both the Alibaba Cloud account and RAM users with API Key permissions for the workspace can delete API Keys.

Note

  • API Keys created by RAM users before March 25, 2026 are bound to the RAM user. When the RAM user is deleted in the RAM console, Model Studio deletes these API Keys as well, and this cannot be undone. Before deleting a RAM user, check the usage of the API Keys under it; to retain the ability to call the API, create new API Keys with the Alibaba Cloud account or another account and update your business configurations.
  • API Keys created on or after March 25, 2026 are not cascaded with RAM users. After a RAM user is deleted, these API Keys remain in effect and can continue to be used.
Trigger operationAPI Keys of the Alibaba Cloud accountAPI Keys of RAM accounts
Manually delete API Key

Supported (Alibaba Cloud accounts have this permission by default; RAM users must have API Key management permissions for the workspace they belong to). Invalid immediately after deletion and cannot be recovered.

Supported (Alibaba Cloud accounts have this permission by default; RAM users must have API Key management permissions for the workspace they belong to). Invalid immediately after deletion and cannot be recovered.

Removing an account from a workspace

—

After the account is removed from the workspace, the API Key becomes invalid; it becomes valid again once the account rejoins the workspace

Delete an account/role in the RAM console

—

API Keys created before March 25, 2026: deleted as well and cannot be recovered.

API Keys created on or after March 25, 2026: unaffected and remain valid.

Asynchronous tasks after an API Key is deleted

After an API Key is deleted, it can no longer be used or recovered. If asynchronous tasks associated with the API Key have not started or have not finished, the system still executes them normally after the API Key is deleted.

If you confirm that you do not want the associated asynchronous tasks to continue running, manually terminate the relevant tasks to avoid incurring charges after the API Key is deleted.

Quantity and permission limits

Summary of API Key limits:

  • API Key quantity: Up to 50 per account and region, not limited per workspace; maximum number of workspaces per Alibaba Cloud account: up to 10 in the Singapore region and up to 20 in other regions (all including the default workspace).
  • Models selectable for custom permissions: Up to 30, limited to models authorized for the workspace.
  • IP whitelist: Up to 50 addresses or CIDR blocks; IPv4 (0.0.0.0/0) allows all traffic by default; IPv6 is supported only in the China (Beijing) region; separate multiple entries with commas when entering them in batch. After entering an IP address, press Enter to confirm before the system recognizes and saves it; clicking OK without pressing Enter does not save the address. The whitelist is validated against the connection IP of the request, not request-header IPs such as X-Forwarded-For; when accessing through a proxy or gateway, add the egress IP of the proxy node. Requests from IPs outside the whitelist are rejected with HTTP 403 and IP access denied by API-Key restrictions.
  • Temporary API Key: Up to 1,800 seconds.

API calls

Visit text generation and the API references of more models.

For models supported by the OpenAI SDK, see OpenAI compatibility.

FAQ

Unable to create an API Key?

Creating an API Key must be performed by a Super Admin or a workspace admin. If the system returns Apikey limit number exceeded for MainAccount, the current account has reached the API Key limit; delete unused API Keys and try again.

How do I manage API Key permissions?

The call permissions of an API Key are determined entirely by its Workspace. API Keys in the same workspace have identical permissions, so there is no need to create different API Keys for different models (such as text generation, text-to-image, and speech synthesis).

  • API Keys under the default workspace: can call all standard models and the applications within the default workspace.
  • API Keys under a sub-workspace: can call the standard models that the sub-workspace has been authorized to call, as well as the applications within that workspace.

Call models fine-tuned in Alibaba Cloud Model Studio: after these models are successfully deployed, they can be called only with the API Key of the workspace they belong to.

For finer-grained control beyond the workspace, switch Permission to Custom when creating or editing an API Key, and configure:

  • IP whitelist rules: All IPv4 addresses are allowed by default; for the complete rules, see Validity and limits.
  • Access Model Scope: Once the switch is enabled, the API Key can only call the selected models (limited to models authorized for the workspace; for the quantity limit, see Validity and limits).

The environment variable is set, but why does my code still report that the API Key cannot be found?

The specific causes are as follows:

  • Case 1: The persistent environment variable was not set. Temporary environment variables take effect only in the current terminal session and do not apply to an IDE or other applications that are already running. Follow the method in this document for setting a persistent environment variable.

  • Case 2: The IDE, command-line tool, or application was not restarted.

    • Usually, you need to restart the IDE (such as VS Code) or the command-line tool so that it loads the latest environment variables.
    • If you set the environment variable after deploying the application, you may need to restart the application service so that the application reloads the environment variables.
  • Case 3: The environment variable needs to be added to a configuration file. If your application is started by a service manager (such as systemd or supervisord), you may need to add the environment variable to the service manager's configuration file.

  • Case 4: The sudo command was used. Running a script with sudo python xx.py may omit the current user's environment variables, because sudo does not inherit all environment variables by default. You can use sudo -E python xx.py, where the -E parameter ensures that environment variables are passed. If you have permission to run the script, you can run python xx.py directly.

What are the differences between a Model Studio API Key and a RAM AccessKey?

They are credentials for different purposes. A Model Studio API Key is not a key pair; you only get a single string after creation, with no AccessKeyId or AccessKeySecret, so no "AccessKey secret" is shown on the API Key page. The specific differences are as follows:

  • Format: A Model Studio API Key is a single string starting with sk-; a RAM AccessKey is a key pair composed of AccessKeyId and AccessKeySecret.
  • Purpose: A Model Studio API Key is used to call the model and application services of Model Studio; a RAM AccessKey is used to call Alibaba Cloud OpenAPI.
  • How to obtain: A Model Studio API Key is created on the API Key page of Alibaba Cloud Model Studio. For specific steps, see "Obtain an API Key" in this topic; a RAM AccessKey is created in the RAM console.
  • Display rules: The full value of a new-version Model Studio API Key is displayed only once in the dialog box shown upon successful creation, so you can copy or download it for safekeeping. After you close the dialog box, only a masked form is displayed in the list and the full plaintext can no longer be viewed. For old API Keys created before the upgrade, the full plaintext can still be copied from the list. The AccessKeySecret of a RAM AccessKey is likewise displayed only once upon creation.

How many API Keys can be created under a single Alibaba Cloud account?

The maximum number of workspaces that can be created under a single Alibaba Cloud account is 10 in the Singapore region and 20 in other regions (including the default workspace); the number of API Keys is 50 per account per region, and is not limited by workspace.

Does Model Studio support batch exporting all API Key information?

No. The API Key Management page in the Model Studio console does not provide batch export or download features. To obtain information about multiple API Keys, view and copy them one by one on that page.