Short-lived access tokens
Use a secure backend to provide temporary API keys when your application calls model services from untrusted environments like browsers or mobile apps. This prevents exposing your permanent API key.
Create a permanent API key in Key Management and set the
Temporary API keys expire after 60 seconds by default. You can set
No. Temporary API keys expire automatically and cannot be deleted manually.
A temporary API key inherits the permissions of the API key that created it, such as model access restrictions.
Prerequisites
Create a permanent API key in Key Management and set the DASHSCOPE_API_KEY environment variable. See Configure your API key.
Request example
Temporary API keys expire after 60 seconds by default. You can set expire_in_seconds from 1 to 1,800.
Sample response
Success response
Response parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
| token | String | The temporary API key. | st-**** |
| expires_at | Number | Expiration time as a UNIX timestamp in seconds. | 1744080369 |
Error response
Response parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
| code | String | Error code. See Error messages for details. | InvalidApiKey |
| message | String | Error message. | Invalid API-key provided. |
| request_id | String | The request ID. | 902fee3b-f7f0-9a8c-96a1-6b4ea25af114 |