Skip to content

Policies ​

A policy decides what a request may do. The gateway evaluates it before any provider is called and refuses the request with a clear code when it breaks a rule.

What you can restrict ​

  • Models: allowed_models
  • Providers: allowed_providers
  • Regions: allowed_regions (matched against each deployment's region_name or aws_region_name)
  • Output size: max_tokens
  • External providers: allow_external: false limits callers to models marked model_info: {internal: true}
  • Caching: cache_ttl

Scopes ​

Policies can be set at the default, domain, organisation, team and key level, and the most restrictive result applies. See Policy File.

Teams, keys and domains come from the caller's virtual key on the server. In the SDK you pass them as team=, key= and domain=.

Named policies and attachments ​

Define a policy once and attach it by pattern:

yaml
policies:
  phi-strict:
    max_tokens: 2000
    guardrails: {add: [pii-strict, claims-phi]}

policy_attachments:
  - {policy: phi-strict, teams: ["claims-*"]}

Refusals ​

SituationHTTPcode
Model not allowed403policy_violation
Provider or region not allowed403policy_violation
External provider forbidden403policy_violation
max_tokens over the limit400max_tokens_exceeded
Unknown domain403unknown_domain
No routing rule can serve the request403 or 400no_route
Budget used up402budget_exceeded

In the SDK these become PolicyViolation and BudgetExceeded, both subclasses of GatewayDenied carrying status_code, code and message.

Fallbacks respect policy ​

If a model fails and LiteLLM would fall back to another, a fallback the caller's policy forbids is dropped. A downgraded model is still checked against the policy.

Caller identity ​

ValueSource, most trusted first
UserA key scoped to a user, then the X-User-Id header, then the OpenAI user field
AgentA key scoped to an agent, then the X-Agent-Id header

For keys that are not user-scoped, the id is an assertion by the calling application. The gateway records it and enforces budgets on it but cannot verify it.

Copyright © 2026 elsai foundry.