# Traffic Controls

After the [request path](https://docs.api7.ai/ai-gateway/endpoints/request-lifecycle.md) is working, traffic controls let you decide who can use it and how it should behave under real application traffic. They bind callers to access rules, protect shared model capacity, enforce spend and content policy, and cache reusable work.

For model traffic, start with [Caller API Keys](https://docs.api7.ai/ai-gateway/traffic-controls/caller-api-keys.md) to give each application a governed identity and model access. Applications that already use an identity provider can present a JWT that AISIX resolves to one of those keys.

Gateway-local controls such as API key and model limits, guardrails, caching, and telemetry exporters are available across the AISIX products. Centralized organization access management, usage, budgets, and audit history require AISIX Enterprise or AISIX Cloud. [Compare AISIX Products](https://docs.api7.ai/ai-gateway/getting-started/products-and-deployment-options.md) before choosing the management path for these controls.

Some controls run before AISIX calls the provider. Others run after the provider returns a response. The request path looks like this:

Caller**Application request**

AISIX gateway

Before the provider

**Authenticate the caller**Caller API key and model access

**Resolve the model**Model alias, IP rules, and route selection

**Check input guardrails**Block or redact early, before spending quota

**Apply budget and rate limits**Budget check in AISIX Enterprise and AISIX Cloud, then gateway limits

**Look up the cache**Non-streaming Chat Completions; a hit skips the provider

Cache miss

Upstream · outside the gateway**Provider model API**Retries and failover; limits of a model group's target models counted per attempt

After the provider

**Check output guardrails**Runs on provider responses and cache hits

**Meter and record**Usage metering, cache store, access logs

**Streaming path**Skips the cache; enforcing output guardrails scan the buffered stream before release

Caller**Response returned**

Request-side controls can stop a request before AISIX calls the provider. Rate limits, budgets, and input guardrails decide whether the request is allowed to continue. Cache lookup can return a stored response on a hit; on a miss, AISIX calls the provider.

After the provider returns, output guardrails can inspect the response before AISIX returns it to the caller.

## Choose a Control[​](#choose-a-control "Direct link to Choose a Control")

Start with caller identity, then add the controls required for the workload.

### Establish Caller Identity and Access[​](#establish-caller-identity-and-access "Direct link to Establish Caller Identity and Access")

[Caller API Keys](https://docs.api7.ai/ai-gateway/traffic-controls/caller-api-keys.md) authenticate applications and define the models, MCP tools, A2A agents, and passthrough routes they can use. They also carry caller-specific rate limits and provide the principal used for policy matching and usage attribution.

[JWT Authentication](https://docs.api7.ai/ai-gateway/traffic-controls/jwt-authentication.md) lets an application present a short-lived token from an OIDC identity provider instead of a long-lived caller key. AISIX verifies the token and resolves it to a caller API key, so the key's access and traffic controls still apply. Use [JWT Claim Mappings](https://docs.api7.ai/ai-gateway/traffic-controls/claim-mappings.md) when groups, departments, or other verified claims should select a shared policy key without maintaining one direct subject binding per identity.

When an internal upstream must authorize on the end user rather than on the gateway, [forward the caller's own headers](https://docs.api7.ai/ai-gateway/models/upstream-request-headers.md#forwarding-the-callers-credential) to it after authentication. No caller credential is forwarded by default, and a public model provider should never be sent one.

### Protect Capacity and Spend[​](#protect-capacity-and-spend "Direct link to Protect Capacity and Spend")

| Goal                                                                                        | Control                                                                                          | Behavior                                                                                                                                         |
| ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| Limit request volume, token usage, or concurrent work on one key or model                   | [API Key and Model Rate Limits](https://docs.api7.ai/ai-gateway/traffic-controls/rate-limits.md) | Request and concurrency limits run before the provider call. Token usage settles after the response reports it.                                  |
| Apply conditional quotas across teams, members, API keys, models, model names, or providers | [Rate Limit Policies](https://docs.api7.ai/ai-gateway/traffic-controls/rate-limit-policies.md)   | Every matching policy applies alongside the limits configured directly on API keys and models.                                                   |
| Cap AI spend across organizational scopes and application identities                        | [Budgets](https://docs.api7.ai/ai-gateway/traffic-controls/budgets.md)                           | The control plane evaluates matching organization, environment, caller API key, provider key, team, and member budgets before the provider call. |

### Enforce Content Policy[​](#enforce-content-policy "Direct link to Enforce Content Policy")

[Guardrails](https://docs.api7.ai/ai-gateway/traffic-controls/guardrails/overview.md) detect, block, or mask sensitive and unsafe content. Input guardrails run before the provider request, output guardrails inspect returned content, and attachments determine which traffic each guardrail covers.

### Reuse Provider Work[​](#reuse-provider-work "Direct link to Reuse Provider Work")

Choose the cache according to what should be reused:

| Goal                                                             | Control                                                                                        | Behavior                                                                                                       |
| ---------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
| Reuse an eligible response for the same Chat Completions request | [Response Caching](https://docs.api7.ai/ai-gateway/traffic-controls/caching.md)                | AISIX returns an exact gateway-side cache hit without contacting the provider.                                 |
| Reuse an eligible response for a meaningfully similar prompt     | [Semantic Caching](https://docs.api7.ai/ai-gateway/traffic-controls/semantic-caching.md)       | An embedding comparison extends response caching beyond exact request matches.                                 |
| Let Anthropic reuse a repeated prompt prefix                     | [Anthropic Prompt Caching](https://docs.api7.ai/ai-gateway/traffic-controls/prompt-caching.md) | AISIX adds provider cache markers to eligible direct Claude requests; Anthropic still generates each response. |

Controls compose on the same request. For example, a Chat Completions request can authenticate a caller, resolve its model, evaluate input guardrails, and check a control-plane budget when configured. AISIX can then reserve rate-limit capacity and look for a cached response. Configure each control independently, then verify the combined path with the same caller API key and model alias the application will use.
