To call model services from untrusted environments such as browsers and mobile apps, use a secure backend service to generate temporary API keys. This prevents your permanent API key from being exposed.
Prerequisites
Get a permanent API key on the API Key (Beijing), API Key (Singapore), or API Key (Virginia), or API Key (China (Hong Kong)) page. Then set the key as the DASHSCOPE_API_KEY environment variable. For more information, see Configure an API key as an environment variable.
Request example
By default, a temporary API key is valid for 60 seconds. Set a custom time-to-live (TTL) between 1 and 1,800 seconds using the expire_in_seconds parameter.
API keys differ by region.
Response example
- Successful response example
- Error response example
Response parameters
Parameter | Type | Description | Example |
|---|---|---|---|
token | String | Generated temporary API key. | st-**** |
expires_at | Number | Expiration time as a UNIX timestamp, in seconds. | 1744080369 |