AddGatewayQuotaRule

Updated at:

Creates a gateway quota throttling rule.

Operation description

Creates a consumer-based quota rule for an AI gateway. Takes effect only on AI gateways of version 2.1.19 or later.

Note

Recommended call logic:

  • Step 1: Perform a dry run to check for rule conflicts.

    • Set dryRun to true.

    • The response contains a conflictHash value in the conflict preview.

  • Step 2: Submit the request after confirmation.

    • No conflicts: Set dryRun to false and overwrite to false.

    • Conflicts exist and you confirm the overwrite: Set dryRun to false and overwrite to true, and set conflictHash to the value returned in the previous step.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

apig:AddGatewayQuotaRule

none

*Gateway

acs:apig:{#regionId}:{#accountId}:gateway/{#GatewayId}

None None

Request syntax

POST /v1/gateways/{gatewayId}/quota-rules HTTP/1.1

Path Parameters

Parameter

Type

Required

Description

Example

gatewayId

string

No

The unique identifier of the gateway.

gw-d8ki1xxxxxxxxxxxxxxx

Request parameters

Parameter

Type

Required

Description

Example

body

object

No

The request body.

{'key': 'value'}

ruleName

string

Yes

The name of the rule.

团队规则

quotaDimension

string

Yes

The quota dimension. Only token is currently supported.

token

quotaLimit

integer

Yes

The total available quota per period.

1000

windowAlignment

string

No

The reset period alignment type. Only calendar is currently supported.

calendar

periodType

string

Yes

The period type. Valid values: day (calendar day), week (calendar week), and month (calendar month).

week

periodMultiplier

integer

No

The number of periods after which the quota resets.

10

timezone

string

No

The time zone for the calendar period, in UTC+x format.

UTC+8

consumerGroupIds deprecated

array

No

The list of consumer group IDs. This parameter is not supported.

group1,group2

string

No

The consumer group ID.

consumer-group-001

consumerIds

array

No

The list of consumer IDs to bind to the rule.

1001,1002,1003

string

No

The consumer ID.

cs-xxxxxx

dryRun

boolean

No

Whether to perform a dry run without persisting or applying the configuration. A dry run checks whether bound consumers have conflicting rules. A consumer cannot have two calendar-period quota rules with the same period type. For example, a consumer with a daily quota rule cannot have another daily quota rule.

false

overwrite

boolean

No

Whether to overwrite conflicting rules. If enabled, conflicting consumers are unbound from the old rule and bound to the new rule.

false

conflictHash

string

No

The conflict snapshot hash that prevents concurrent dirty overwrites. Retrieved from the response of a previous dry run (dryRun=true).

Not required when no conflicts exist, during a dry run (dryRun=true), or when overwrite is false.

If dryRun is false and overwrite is true but this parameter is missing or expired, the backend returns accepted=false with a new conflict preview. Perform a new dry run to confirm the updated conflicts.

f8f44dc6cf369a017d56b7197eb4fb5ac4bbb6b09a92b9b41999541fxxxxxxxx

Response elements

Element

Type

Description

Example

object

The response schema.

requestId

string

The request ID.

1234567890

code

string

The status code or error code.

200, 404, 500

message

string

The message content.

你好,世界!

data

object

The response data.

{'key': 'value'}

ruleId

string

The rule ID.

qr-xxxxx

dryRun

boolean

Whether the request is a dry run.

false

accepted

boolean

Whether the write request was accepted. A value of false typically indicates a retryable scenario, such as an unconfirmed conflict overwrite.

true

conflictPreview

object

The conflict preview.

totalConflictCount

integer

2

conflictHash

string

f8f44dc6cf369a017d56b7197eb4fb5ac4bbb6b09a92b9b41999541fxxxxxxxx

items

array<object>

object

consumerId

string

cs-xxxxxx

consumerName

string

consumer-a

conflictType

string

calendar

conflictPeriodType

string

week

Examples

Success response

JSON format

{
  "requestId": "1234567890",
  "code": "200, 404, 500",
  "message": "你好,世界!",
  "data": {
    "ruleId": "qr-xxxxx",
    "dryRun": false,
    "accepted": true,
    "conflictPreview": {
      "totalConflictCount": 2,
      "conflictHash": "f8f44dc6cf369a017d56b7197eb4fb5ac4bbb6b09a92b9b41999541fxxxxxxxx",
      "items": [
        {
          "consumerId": "cs-xxxxxx",
          "consumerName": "consumer-a",
          "conflictType": "calendar",
          "conflictPeriodType": "week"
        }
      ]
    }
  }
}

Error codes

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.