When you need to call large language models and applications through API or SDK, you must first obtain an API key as an authentication credential by following the instructions in this topic.
Activate model studio
Log on to the Alibaba Cloud Model Studio with your Alibaba Cloud account. If the following message appears at the top of the page, you need to activate Model Studio to obtain the free quota for new users. Activating Model Studio is free. You are only charged for model calling (after exceeding the free quota), model deployment, and model fine-tuning. If no such message appears, you have already activated the service.
Obtain an API key
Go to the API-Key page. Under the My tab (position ① in the screenshot below), click Create My API-KEY (position ②).
In the Create API Key dialog box, select a workspace to which the API key belongs, enter a description, and click OK.
Workspace: Usually, just use the default workspace (the Alibaba Cloud account workspace). If you select a non-default workspace, the Alibaba Cloud account administrator needs to authorize the sub-workspace for model calling, training, and deployment when you use this API key to call models.
Description: We recommend that you enter meaningful content to accurately identify the purpose of the API key.
In the Actions column of the created API key, click View (position ③ in the above screenshot) to obtain the API key.
NoteOnly the Alibaba Cloud account has the permission to view all API keys. The Alibaba Cloud account can view or delete API keys of all RAM users, while RAM users can only view or delete their own API keys.
Do not disclose your API key in any way to avoid security risks or financial losses due to unauthorized use.
Your API key is an important asset. Please keep it safe. If you click Delete in the Actions column to delete an existing API key, you will no longer be able to access Model Studio services through that key. If you have integrated this API key into certain applications or services before, these applications will not work properly because of authentication failure.
What to do next
Option 1: Call models in third-party tools
If you call models in tools or platforms such as Chatbox or Dify, you might need to enter three pieces of information:
The API key obtained from this topic
Base URL:
https://dashscope.aliyuncs.com/compatible-mode/v1
Model name, such as qwen-plus
Option 2: Call models through code
If you call models through code, we recommend that you set API key as an environment variable. This avoids explicitly configuring the API key in your code, thereby reducing the risk of API key leakage.
Scope of API key
The API key of the Alibaba Cloud account can access all services in all workspaces. But you must specify the workspace ID when you access a specific workspace.
The API key of a RAM user can only access authorized services in the workspace to which the API key is attached. For more information about how to authorize a workspace, see Authorize a sub-workspace for model calling, training, and deployment.
If a RAM user needs to access services in the "default workspace" (the Alibaba Cloud account workspace), there are two solutions:
Obtain the API key of the Alibaba Cloud account for calling.
The Alibaba Cloud account first grants the RAM user permission to access the "default workspace." Then, the RAM user creates their own API key in the "default workspace" to access services in the "default workspace."
Validity period of API key
By default, the API keys created on the API Key Management page are permanently valid. They will become invalid after manual deletion.
To provide temporary access for third-party applications or users, or if you want to strictly control high-risk operations such as accessing sensitive data or deletion, you can obtain a temporary authentication token (valid for 60 seconds). This approach helps avoid directly exposing long-term API keys, thereby reducing the risk of leaks.