Private beta: The LLM Gateway is in private beta. Sign up for the waitlist to get access.
X-Gateway-Customer-Id: acme limits only the requests from that workspace that carry that header value. Requests from the same workspace carrying X-Gateway-Customer-Id: globex count against a different policy.
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.
Header condition rules
- One condition per policy: A policy accepts a single header key with a single value.
- Pairs with one subject scope: Combine a header condition with an organization, workspace, user, or API key scope. The subject side accepts several values and matches any of them. The header side accepts exactly one value.
- Spend caps and rate limits only: Default policies cannot carry a header condition, so the gateway never creates per-header policies on its own. To limit many header values, create one policy for each.
- A missing header matches nothing: A request that does not carry the header does not match the policy. Pair per-header policies with a broader policy on the subject itself so untagged traffic is still limited.
- 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.
Add a header condition
- 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. Header conditions give each of those end customers a separate cap under that single key.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.

