Calls the POST /api/v1/models/limits endpoint to update the rate limit quotas (QPM/TPM) of models in a specified workspace. Both merge overlay and delete rate limit operations are supported.
Prerequisites
An API key has been created and configured as the environment variable DASHSCOPE_API_KEY. For more information, see Configure an API key in environment variables.
Request
-
HTTP method: POST
-
Request URL
Replace
{WorkspaceId}with your workspace ID.Region Endpoint China (Beijing) https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/models/limits -
Authentication
Set
Authorization: Bearer {API_KEY}in the request header.
Request parameters
All parameters are passed through the request body.
Parameter | Type | Required | Description |
|---|---|---|---|
| Array[Object] | Yes | List of per-model rate limit items. The number of items must be 1 to 200. Example: |
| String | Yes | The model ID. Cannot be empty. Examples: |
| String | No | Operation type. Valid values:
Default value: |
| Number | No | Request count limit (QPM), non-negative. Maximum number of requests per minute, in requests/minute. Must be empty when |
| Number | No | Time period for the request rate limit, a positive integer in seconds. For example, |
| Number | No | Usage limit (TPM), non-negative. Maximum token usage per minute. Must be empty when |
| Number | No | Time period for the usage limit, a positive integer in seconds. For example, |
Response parameters
Parameter | Type | Description |
|---|---|---|
| String | The request ID. Example: |
| String | Error code. |
| String | Error message. |
| Boolean | Whether the call succeeded. Example: |
| Object | Business data. |
TPM exemption scenario
To limit only RPM and exempt TPM, first call this endpoint with {"model":"X","operation_type":"DELETE"} to delete all rate limits for the target model. Then pass {"model":"X","operation_type":"OVERLAY","request_limit":60,"request_limit_period":60} to set only the QPM. The two steps are not atomic, so there is a brief window without any limit in between.
Sample requests
Example 1: Set QPM=60 and TPM=100000curl -X POST "https://dashscope.aliyuncs.com/api/v1/models/limits" \
--header "Authorization: Bearer ${DASHSCOPE_API_KEY}" \
--header 'Content-Type: application/json' \
--data '{
"models": [
{
"model": "qwen-plus",
"operation_type": "OVERLAY",
"request_limit": 60,
"request_limit_period": 60,
"usage_limit": 100000,
"usage_limit_period": 60
}
]
}'
Example 2: Delete rate limits
curl -X POST "https://dashscope.aliyuncs.com/api/v1/models/limits" \
--header "Authorization: Bearer ${DASHSCOPE_API_KEY}" \
--header 'Content-Type: application/json' \
--data '{
"models": [
{"model": "qwen-plus", "operation_type": "DELETE"}
]
}'
Sample response
Success example{
"code": null,
"message": null,
"success": true,
"output": null,
"request_id": "d5f5201f-ee7a-9e3d-8569-bc0eedec21f9"
}
Failure example
{
"code": "InvalidParameter",
"message": "Cannot set TPM without QPM for model qwen-plus: no existing QPM limit, please set QPM first",
"success": false,
"output": null,
"request_id": "d5f5201f-ee7a-9e3d-8569-bc0eedec21f9"
}
Error codes
If the call fails, an error message is returned. For more information about error codes and solutions, see Error messages.