An API key is needed for authentication when you call large language models (LLMs) or applications through API or SDK. This topic describes how to obtain an API key.
Activate Model Studio
Log on to the Model Studio console. If the following message appears at the top of the page, you need to activate Model Studio and claim the free quota. It is free to activate the service, but after you run out of the quota, you are charged for model calling.
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. If you select a non-default workspace, the Alibaba Cloud account administrator needs to authorize the sub-workspace when you use this API key to call models.
Description: Write meaningful content to identify the purpose of the API key.
In the Actions column of the created API key, click View (position ③) 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
After obtaining an API key, we recommend that you set it as an environment variable. This avoids explicitly specifying it when you use Alibaba Cloud Model Studio SDK and reduce the risk of an API leak. For more information, see Set API key as an environment variable.
Scope of API key
The API key of the Alibaba Cloud account can access all Model Studio services in all workspaces. But you must specify the workspace ID when you access a sub-workspace. For more information, see Call a model in a sub-workspace.
The API key of a RAM user can access authorized Model Studio services in the associated workspace. For more information about how to authorize a workspace, see Authorize a sub-workspace to use models.
If a RAM user needs to access Model Studio services in the default workspace, use one of the following methods:
Use the API key of the Alibaba Cloud account.
Use the Alibaba Cloud account to grant the RAM user access permission to the default workspace. Then, the RAM user can create an API key in the default workspace.
Validity period of API key
By default, the API Keys created in API Key Management are permanently valid. But you can manually delete them and they will become invalid.
If you need to provide temporary access for third-party applications or users, or if you want to strictly control high-risk operations like access to sensitive data and deletion, obtain a temporary authentication token that is valid for 60 seconds. This approach helps avoid directly exposing long-term API Keys, thereby reducing the risk of leaks.