Skip to main content
The LLM Gateway is in beta.
A spend policy defines a cost cap for a specific scope (organization, user group, workspace, user, or API key) over a time window (monthly, weekly, daily, or hourly). Once the spend recorded for the window reaches the cap, the LLM Gateway blocks further requests with a 402 response that names the blocking policies:
The gateway records a request’s cost after the request completes. The request that crosses the cap still succeeds, and only later requests are blocked, so spend for a window can exceed the cap. Requests sent close together can all pass before the first one is recorded, so the overshoot can be larger than one request. The blocked request is traced to LangSmith with the policy violation recorded as metadata, so you can see exactly what was blocked and why. The violation also surfaces as an issue in LangSmith Engine.
Spend policies do not apply to calls billed to a Claude subscription, and those calls are left out of spend totals.

Policy dimensions

Spend policies are evaluated from broadest to most specific. All matching policies are checked, and if any one returns a block, the request is rejected. You can set a policy as a default (applying a blanket spend cap to all user groups, workspaces, users, or API keys) or as a granular policy (individual limits or limits on a group of entities).

Conflict resolution

By default, the gateway assesses the broadest scope first. Narrower scopes can only tighten limits, never loosen them. For example, if an org-level policy caps spend at $10,000/month and a workspace-level policy caps at $15,000/month, the $10,000 org cap still applies. If a caller belongs to multiple user groups, every matching group cap applies alongside organization and other applicable caps.

Defaults vs. granular policies

Spend policies have two aspects:
  1. Sums across a dimension: the total cap for that scope. Example: “This workspace’s total spend cannot exceed $5,000/month.”
  2. Defaults for each member of a dimension: a base limit that applies to every user group, workspace, API key, or user within a scope unless overridden. A user group default gives each group its own shared budget. Example: “Each API key in this workspace gets a $200/month default cap.” Individual API keys can receive additional policies that raise their specific limit, but no policy can loosen a cap set at a broader scope.

Time window period

The time window sets the period over which spend accumulates against the cap. At the end of each window, recorded spend resets to zero:
You can apply multiple time windows to the same scope. For example, a workspace can have both a $5,000/month cap and a $500/day cap. Both are enforced independently.

Create a spend policy

Creating and managing policies requires organization:gateway:manage permission. Organization Admins and Organization Operators have it by default. For what each organization role can do, see Organization roles. Selecting a user group also requires organization:user-groups:read; see User Groups for availability and setup.
  1. Go to LLM Gateway and select the Policies tab.
  2. Click + Policy.
  3. Under Policy type, select Spend limit.
  4. Define a Scope and the subjects the policy applies to.
  5. (Optional) To separate a default limit by header, select User Group, Workspace, User, or API Key. Apply the limit to every subject of that type by default. Alternatively, select exactly one subject to pin the limit to it. Select Separate limits by custom header, and enter the header name, such as Customer-Id. Send the full X-Gateway-Customer-Id header on requests. Each subject and header-value pair receives an independent limit.
  6. Set the Spend limit in USD and the Period (monthly, weekly, daily, or hourly).
  7. Click Create policy.
Policies take effect immediately. The gateway evaluates them on every incoming request with sub-second enforcement latency.
A spend policy can also use a custom request header to give each end customer, tenant, or cost center an independent cap without issuing a separate API key for each. For more information, see Header-based policies.

View spend

On the Policies tab of LLM Gateway, the Usage column shows how much each spend limit has spent, in dollars and as a percentage of its cap. To list only spend limits, filter the table by type. To analyze spend over time by user, API key, model, or request header, use the Usage tab. For more information, see Monitor LLM Gateway activity.

See also