Skip to main content
Version: 1.13.0

Rate Limit Policies

Rate limit policies cap traffic independently from limits stored on caller API keys and models. A policy can select requests by caller identity, model, provider, or tags, then give each selected group its own quota. Recurring suspension windows can pause one policy without disabling other controls.

Use conditional policies for new configurations. They match requests with conditions and can split quota into independent buckets. Classic policies remain available for existing rules that target one API key, model, team, or member.

A policy does not replace limits on individual API keys or models. A request proceeds only when every matching policy and direct limit has capacity.

Prerequisites​

Before starting, prepare the following:

  • Familiarity with the limit fields, counter behavior, storage options, and resource-specific limits described in API Key and Model Rate Limits.
  • A working model alias and caller API key that can send proxy requests.
  • For the per-member examples, a caller API key bound to the selected team and a member.
  • One configuration path:
    • AISIX Enterprise or AISIX Cloud with an environment and an attached gateway. Dashboard workflows require permission to manage rate limit policies and view teams.
    • AISIX OSS with a declarative resources file that can be validated and reloaded.

Export the gateway request values used to verify the examples:

# AISIX_PROXY has no trailing slash or endpoint path.
# The local quickstarts use http://127.0.0.1:3000.
export AISIX_PROXY="YOUR_AISIX_GATEWAY_URL"
export AISIX_MODEL="gpt-4o-prod"
export AISIX_API_KEY="YOUR_CALLER_API_KEY"

Choose a Policy Form​

A policy uses one of two forms:

FormUse ForCharacteristics
Conditional policyNew configurationsMatches a condition tree and can split quota into independent buckets. The Dashboard's New policy flow creates this form.
Classic policyExisting single-subject rulesTargets one API key, model, team, or member through scope and scope_ref. Managed classic policies can be converted to conditional.

Configure a Conditional Policy​

The following workflow creates team-member-default, a conditional policy that matches one team, gives each member a separate bucket, and allows one request per minute.

The managed control plane projects saved policies to attached gateways. Resource Projection explains when a change becomes active. Multiple conditional policies can apply to the same traffic.

In AISIX Enterprise and Cloud, each rate-limit policy name must be unique within its environment. Names are case-sensitive and can contain up to 100 Unicode characters. Creating or renaming a policy with a duplicate name returns 409 ALREADY_EXISTS. The same name can be used in another environment.

  1. Open the environment and select Rate limits.

  2. Select New policy and enter team-member-default for Name.

  3. Under Match conditions, add a Team condition, keep the in operator, and select the target team.

    New rate limit policy form named team-member-default with the Platform team condition
  4. Under Quota buckets, select Split by dimension, then select Member.

    Quota buckets set to Split by dimension with Member selected
  5. Under Limits, set Requests / minute to 1, then select Create policy.

    Limits section with Requests per minute set to one and fixed window selected
  6. Reopen team-member-default and confirm that it shows the team condition, member bucket, and one-request-per-minute limit.

    Saved team-member-default policy with the Platform team condition, member bucket, and one RPM

Editing a policy can change its conditions, buckets, and limits. Changing the set of bucket dimensions changes the counter keys. Editing only the conditions or limits does not reset existing counters.

Verify the Policy​

Use a caller and model with no other matching direct limit or policy. Wait for the managed policy to reach the gateway, or reload the AISIX OSS resources file.

Memory counters are local to each gateway instance. Address one instance directly, or use shared Redis when testing through a load balancer. Start in a fresh UTC minute and send two matching requests:

for i in 1 2; do
curl -sS -o "/tmp/team-member-default-${i}.json" \
-w "request ${i}: %{http_code}\n" \
-X POST "${AISIX_PROXY}/v1/chat/completions" \
-H "Authorization: Bearer ${AISIX_API_KEY}" \
-H "Content-Type: application/json" \
--data-binary @- <<EOF
{
"model": "${AISIX_MODEL}",
"messages": [{"role": "user", "content": "Hello"}]
}
EOF
done

jq -e '.error.type == "rate_limit_exceeded" and .error.policy.name == "team-member-default"' \
/tmp/team-member-default-2.json

Expect the first request to reach the model with 200. The second should return 429, and the jq check should name team-member-default.

If the result differs, use the observed response to narrow the cause:

ResultWhat to Check
The first request returns 429.Another limit matched, or the bucket already recorded a request in the current UTC minute.
The second request returns 200.Confirm policy projection, identical bucket selection, one memory-backed gateway instance or shared Redis, and that the UTC minute did not change.

When a conditional policy rejects a request on an OpenAI-compatible endpoint, the 429 body identifies the policy:

{
"error": {
"message": "request limit exceeded (requests) (policy 'team-member-default')",
"type": "rate_limit_exceeded",
"policy": {
"id": "<policy-id>",
"name": "team-member-default"
}
}
}

Every matching policy and direct limit must have capacity. OpenAI-compatible errors name the policy that rejected the request. Anthropic-compatible errors keep the strict Anthropic envelope and omit the policy object.

Customize a Conditional Policy​

A conditional policy makes three decisions: which requests match, how their counters split, and how much traffic each bucket can use.

Match Requests with Conditions​

Conditions select the requests that use the policy. Build the condition tree from these rules:

  • Every top-level node must match.
  • A group combines its children with logic: and or logic: or.
  • An empty or omitted conditions list matches every request in the environment.

Each condition reads one request dimension:

DimensionValueNotes
teamTeam IDCaller API key's team_id
memberMember or user IDCaller API key's user_id
api_keyCaller API key IDAuthenticated key
modelModel IDAddressed entry, intermediate model group, and dispatched target
model_nameModel aliasDisplay names for the same model entries
providerProvider catalog IDDispatched target's provider
tag:<key>Request tag valueResolved request tag
model_tag:<key>Model tag valueAddressed, intermediate, and target model entries
provider_key_tag:<key>Provider key tag valueCredential used for the upstream attempt

For model and model_name, routing evaluates the entry the caller addressed, any intermediate model group, and the selected target. Negation excludes every matching identity. A wildcard model_tag condition uses the resolved model entry's tags.

Managed deployments require declared tag keys. Set model and provider-key values under Access tags. In AISIX OSS, set tags on the resource.

Condition operators follow lua-resty-expr, the same expression vocabulary used by APISIX route vars:

OperatorMeaningApplies To
== / ~=Equal / not equalAll dimensions
inValue in a list of 1–64 entriesAll dimensions
~~ / ~*Case-sensitive / case-insensitive regular expression, up to 256 charactersmodel_name, provider, and all three tag dimensions
negate: trueInvert a condition or groupAny node

Additional condition rules:

  • Identity dimensions (team, member, api_key, and model) use equality or list operators.
  • A missing dimension matches neither its condition nor its negation. Another branch of an or group can still match.
  • A policy can contain up to 16 conditions and 3 levels of nesting.

For a model tag, ==, in, and the regular expression operators can match any present value. The ~= operator requires every present value to differ from the configured value.

Deleted Resources​

Deleting a key, model, team, or member named by a managed conditional policy does not delete the policy. The deleted ID stops matching. A model_name condition compares names and remains unchanged.

Match Resource Tags​

Tag conditions let one policy follow cost-attribution metadata instead of fixed resource IDs.

Under Match conditions, select Add condition and choose Tag as its dimension. In Tag source, select Request tags, Model tags, or Provider key tags. In Tag key, search for and select the declared key, then set the operator and Tag value. Changing the tag key keeps the selected source. Conditions using tag:<key> display Request tags.

When you select Request tags, the inline help lists the sources. Open View resolution order to see how the gateway chooses the first valid value for each key. See How a Request Resolves Its Tags.

For the example below, select Provider key tags and department. Set the operator to equals and enter docs-research in Tag value.

Tag source menu in the rate limit rule with Provider key tags selected

For an independent quota per matching credential, under Quota buckets, select Split by dimension and choose Provider Key.

Quota buckets set to Split by dimension with Provider Key selected

For version and rolling upgrade guidance, see Use Model and Provider Key Tags.

Split Counters into Buckets​

Quota buckets determine which matching requests share usage. Leave group_by empty for one shared quota, or split the counters by team, member, api_key, model, provider, provider_key, or tag:<key>.

ConfigurationResult
Omitted or []All matching requests share one bucket.
One or more dimensionsEach value combination gets its own bucket with the same limits.
Request lacks a selected dimensionThe policy does not apply to that request.
model or provider_keyEach model or upstream credential gets its own bucket. Model and provider-key tags are condition-only dimensions.

Common bucket patterns include:

GoalConfiguration
Shared team quotaMatch the team and leave group_by empty.
Per-member quota within a teamMatch the team and use group_by: [member]. Add a separate shared policy when the team also needs a total cap.
Fair share of a modelMatch the model and use group_by: [team].
Per-department quotaUse group_by: ["tag:department"]. Requests without a department value are not limited by this policy. See Rate-Limit by Tag.
Per-credential quotaUse group_by: ["provider_key"]. Targets sharing a credential also share its bucket.

Set the Limits​

A conditional policy requires at least one limit:

  • Request limits: rps, rpm, rph, and rpd.
  • Token limits: tpm and tpd. Usage settles after the response or stream reports it.
  • Concurrent requests: concurrency.

AISIX rejects requests that exceed a policy with HTTP 429. The action field currently accepts only reject and defaults to that value when omitted.

Window Behavior​

The default window_type: fixed aligns windows to the UTC clock; daily limits reset at 00:00 UTC. Set window_type: sliding for rolling minute, hour, and day windows. See Rate Limit Fields and Windows.

Understand Request Counting​

Counting depends on when AISIX can determine the match and bucket:

  • Count once per client request when caller identity, the addressed entry, or a selected group provides everything needed.
  • Count each admitted upstream attempt, including retries, when the actual target or credential determines the match or bucket.
  • Skip a target refused by a per-attempt policy and try the next eligible target.
  • Evaluate target-dependent policies for every ensemble panel and judge call.

For example, a shared model-tag policy counts once when both the group and target carry department=rnd. See How Requests Are Counted for refund behavior after a refusal.

Complete Conditional Example​

The following policy combines a required team condition with a model-or-provider choice, assigns each member a separate bucket, and allows 20 requests per minute:

{
"name": "algo-team-premium-models",
"conditions": [
{ "dimension": "team", "operator": "in", "value": ["<team-id>"] },
{
"logic": "or",
"children": [
{ "dimension": "model_name", "operator": "~~", "value": "^gpt-4" },
{ "dimension": "provider", "operator": "==", "value": "anthropic" }
]
}
],
"group_by": ["member"],
"limits": { "rpm": 20 }
}

See the Resources File Reference for the complete policy schema and field validation rules.

Manage Classic Single-Scope Policies​

Compare Classic and Conditional Policies​

A classic policy targets one subject and uses fixed-window fields instead of conditional limits. Each classic scope has a conditional equivalent that matches the same traffic:

Classic ScopeMatching TrafficConditional Matching Equivalent
API keyRequests authenticated with the selected caller API keyconditions: api_key in {K}
ModelRequests resolved to the selected modelconditions: model in {M}
TeamRequests whose caller API key carries the selected team bindingconditions: team in {T}
MemberRequests whose caller API key carries the selected member bindingconditions: member in {U}
Each member in a teamRequests carrying both the selected team and a member bindingconditions: team in {T} with group_by: [member]

Classic policies use the following fields instead of conditions, group_by, and limits:

FieldBehavior
scope and scope_refSelect one subject.
windowUses a fixed second, minute, hour, or day window. A day resets at 00:00 UTC.
max_requestsCaps requests in the selected window.
max_tokensCaps tokens only for minute and day windows. A day cap is equivalent to conditional tpd.
window_typeNot supported; classic policies cannot use sliding windows.

Conversion can change model-group counting. A classic ensemble policy counts once per client request; its conditional equivalent counts every panel and judge call. See How Requests Are Counted.

Configure or Convert a Classic Policy​

The managed control plane rejects token caps on second or hour windows. Managed classic policies also follow these lifecycle rules:

ChangeResult
Create another policy for the same scope and targetRefused; only one can exist.
Change the scope or targetNot supported after creation.
Delete the targetDeletes its classic policies. Deleting a team also removes its each-member policy. The confirmation lists them by name.
Upgrade a policy orphaned by deletion before 1.11.0The policy remains. Delete it under Rate limits.

The dashboard marks classic policies with a Legacy badge and displays their conditional matching equivalents.

Existing classic policies appear under Rate limits. The Dashboard supports changes to their name, window, caps, and suspension schedules.

Select Convert to conditional policy to convert in place. AISIX keeps the policy ID, name, and schedules, translates the target and limits, and starts new conditional counters. Conversion is permanent.

Convert to conditional policy confirmation explaining counter and ensemble behavior

The New policy flow creates a conditional policy. Creating a classic policy requires the Admin API.

Suspend a Policy on a Schedule​

Add recurring suspension windows to pause either policy form at predictable times. AISIX skips the policy while any window matches and resumes enforcing it when the window closes.

The following workflow adds an all-day weekend window to team-member-default.

caution

Confirm that every gateway receiving the policy supports schedules before adding one. An unsupported gateway rejects a scheduled policy and stops enforcing it. Policies without schedules are unaffected.

  1. Open the policy's create or edit form.

  2. Under Suspension windows, select the timezone, choose weekly days or explicit dates, and set the time range or All day.

    Suspension window configured for all day Saturday and Sunday in Asia Shanghai time
  3. Save the policy. The list summarizes the windows and shows a Suspended now badge while one is active.

    Saved team-member-default policy showing its all-day weekend suspension

Clearing every window and saving resumes enforcement on the existing counters. Suspension itself does not reset them.

Verify Suspension​

  1. Temporarily replace the weekend window with a short window that includes the current time. Wait for the update, then repeat Verify the Policy. No response should identify team-member-default while its window is active.
  2. Remove every window and wait for the update. In a fresh UTC minute, repeat the sequence. The first request should reach the model; the second should return 429 from team-member-default.

This confirms that enforcement resumed. Suspending a policy does not reset its counters.

Schedule Behavior and Multiple Windows​

Use the following rules when defining additional suspension windows:

  • A window uses days_of_week for weekly recurrence or dates for explicit calendar dates. These fields are mutually exclusive.
  • start_time and end_time use HH:MM in the window's IANA timezone. 24:00 is valid only for end_time and means the end of the day.
  • An end_time before start_time crosses midnight and belongs to its start day. For example, Friday 22:00 to 09:00 covers Friday night through Saturday morning.
  • Multiple windows form a union; the policy is suspended while any window matches.
  • Suspension does not reset counters. A bucket retains its counts when a window opens and closes.
  • Budgets, authentication, and guardrails remain active because only the rate-limit policy is suspended.

The following schedule combines weekends, holidays, and weeknights from 22:00 to 09:00. Sunday is included in the overnight window to cover Monday morning before 09:00:

{
"schedules": [
{
"timezone": "Asia/Shanghai",
"days_of_week": ["mon", "tue", "wed", "thu", "fri", "sun"],
"start_time": "22:00",
"end_time": "09:00"
},
{
"timezone": "Asia/Shanghai",
"days_of_week": ["sat", "sun"],
"start_time": "00:00",
"end_time": "24:00"
},
{
"timezone": "Asia/Shanghai",
"dates": ["2026-10-01", "2026-10-02", "2026-10-03"],
"start_time": "00:00",
"end_time": "24:00"
}
]
}

Troubleshooting​

When a policy does not behave as expected, first confirm which request attributes it can evaluate and which other limit layers still apply.

SymptomWhat to Check
A team or member policy does not apply.Confirm that the caller API key carries the matching team or member binding. A policy grouped by member skips a request whose caller API key has no member binding.
A tag policy does not apply.Check the tags the request resolves from its JWT claims, caller API key, team, and member. A request without a value for the tag matches neither the condition nor its negation, and a policy grouped by the tag skips it.
An API key or model condition does not match.Use the resource ID. In an AISIX OSS resources file, use the entry's id, then validate and reload the complete file.
An AISIX Enterprise or Cloud environment already contains duplicate policy names.Existing policies can still be edited or converted. Renaming still requires a name that no other policy in the environment uses.
Requests still return 429 while a policy is suspended.Check for direct caller or model limits and other matching policies. A schedule suspends only the policy that carries it.
A schedule added through the AISIX Cloud Admin API does not take effect.Confirm that the policy change reached the gateway and that every attached gateway supports schedules.

Next Steps​

Review API Key and Model Rate Limits for resource-specific limits, counter storage, and shared enforcement behavior. Use Metrics to monitor rate-limit rejections.