Beta: The LLM Gateway is in beta.
X-Gateway-Customer-Id gives acme and globex independent limits within each workspace. An explicit policy with the condition X-Gateway-Customer-Id: acme limits only requests that carry that exact value.
Matchable headers
The gateway matches on request headers prefixed withX-Gateway-, and on keys inside the X-Gateway-Metadata JSON header. No other request header is matchable.
Header names are normalized before matching: the X-Gateway- prefix is stripped, the remainder is lowercased, and every character outside a-z, 0-9, and _ is replaced with _. The headers X-Gateway-Customer-Id, x-gateway-customer_id, and X-Gateway-CUSTOMER.ID all resolve to the matcher key customer_id. Header values are compared as exact, case-sensitive strings, with no wildcard or pattern matching.
The gateway stamps caller identity itself and ignores client attempts to override it. Headers that resolve to organization_id, workspace_id, workspace_handle, user_id, user_email, api_key_id, api_key_short, auth_mode, user_agent, applied_policy_ids, or applied_policy_names, and any header whose normalized name starts with gateway, are discarded.
Separate a default spend limit by header
A default spend limit applies the same cap to every member of a subject dimension. Separating it by a header applies that cap independently to every subject and header-value pair, without requiring a policy for each value. Default spend bucketing follows these rules:- One header per default: Enter the header name only. The request supplies the value that identifies the bucket.
- Independent limits: Each subject and header-value pair receives the configured spend limit.
- Fallback limit: Requests without the configured header share a fallback limit for their subject.
- Go to Settings → Gateway → LLM Gateway and select Cost Controls.
- Click Create spend limit.
- Select Workspace, User, or API Key, then select the option to apply the limit to every subject of that type by default.
- Select Separate limits by custom header.
- Enter the Header name without its
X-Gateway-prefix. For example, enterCustomer-Idfor theX-Gateway-Customer-Idrequest header. - Set the spend limit, then click Create spend limit.
Add an explicit header condition
An explicit spend or rate limit policy can match one exact header value. Use an explicit policy to assign different limits to different header values. Explicit header conditions follow these rules:- One condition per policy: A policy accepts one header name and one value.
- One subject scope: Combine the condition with an organization, workspace, user, or API key scope. The subject side accepts several values and matches any of them.
- Missing headers do not match: A request without the configured header does not match the policy.
- Every matching policy is enforced: A request that matches both a plain subject policy and a policy with a header condition counts against both, and either one can block it.
- At most 10 conditions: A policy carries no more than 10 subject conditions in total.
- Go to Settings → Gateway → LLM Gateway.
- Click Create policy.
- Select the policy type and subject scope, then set the limits.
- Under Custom header condition (optional), enter the Header name without its
X-Gateway-prefix (for example,Customer-Id) and the Header value to match (for example,acme). - Save.
subject_matchers through the API.
Cap spend per end customer
A reseller or multi-tenant application usually calls the gateway from its own backend, using one workspace-scoped API key on behalf of many end customers. Use an explicit header condition when each customer needs a different cap. If every customer uses the same cap, separate one default spend limit by header instead.Step 1. Send a customer header on every call
Attach the header to each request your backend makes on behalf of an end customer:If your LangSmith account is on a regional instance, use the corresponding regional gateway.
Step 2. Create a cap for one customer
Create one spend policy per end customer through the LangSmith REST API:customer_id, not the header name X-Gateway-Customer-Id. The policy belongs to the organization that owns the API key.
Posting a policy whose subject_matchers already exist updates that policy instead of adding a duplicate, so this call is safe to repeat.
Step 3. Sync policies with your customer list
Because each end customer needs its own policy, keep the policy set in step with your customer list. The following script creates or updates a cap for every current customer, then deletes the caps of customers that are gone:Step 4. Read spend per customer
Each spend policy returned by the API reportscurrent_spend_usd, the spend accumulated in the policy’s active window. Use it to show each end customer their usage, or to warn them before they reach the cap. The field is omitted when the spend lookup fails, so treat a missing value as unknown rather than as zero.
The list endpoint narrows by a subject matcher key only when that key is paired with a value, so list the spend caps and select the per-customer ones in your own code:
Limit throughput per end customer
Rate limits use the same subject matchers. Swappolicy_type and config to give an end customer its own request and token allowance:
Next steps
- Spend policies: set cost caps for organizations, workspaces, users, and API keys.
- Rate limit policies: limit requests and tokens in a rolling window.
- Traces and access control: understand where gateway traces land and who can configure policies.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

