Most applications call the gateway with one ManyLayers key on behalf of many of their own users. An end user is how ManyLayers tells those users apart without issuing a key for each one: your backend names the user on every request, and the gateway attributes usage, enforces per-user budgets and rate limits, and exposes each user’s usage to your application.
An end user is attribution, not authentication. The API key authenticates the request and scopes it to your organization; the end-user id only partitions what that key does. It is never a ManyLayers login, and the same id in two organizations is two unrelated users.

The header

Send the user’s id in the X-ManyLayers-Metadata header, a JSON object whose values are strings:
  • user_id is the identity. name and email only make a user easier to recognise (and block). They are stored on the user’s record and refreshed whenever a later request carries them; a request that omits them leaves the stored values alone. Correcting a name never creates a second user.
  • The first request registers the user. There is nothing to create beforehand. You can also register a user ahead of time when you want a budget in place from their first request.
  • The header never reaches the provider. The gateway strips it before forwarding, so a provider never learns which of your users made a call.
  • Limits. The header may be at most 8 KB, with at most 64 keys and 512 bytes per value. A header that is malformed or over a limit, or a user_id that is longer than 512 bytes, null, an object or an array, is treated as no end user, not as an error. Prefer a string id.
Set the header from your trusted backend, where you already know who the signed-in user is. Never let a browser or mobile client set it: a value a client controls is a value a client can change to impersonate another user or escape their own budget. If a client must reach the gateway, put your own authenticated endpoint in front and have it add the header.

Configure it with an SDK

The gateway is OpenAI-compatible and also speaks the Anthropic Messages format, so the header is a custom header on the SDK client: no custom transport or wrapper is needed. There are two patterns — pick the one that matches how your client lives.
Do not put a default header on a long-lived, shared client and then switch users. Every call from that client carries the same user_id, so all of your users would be attributed to one. For a shared client, set the header per request.

Per request (shared client)

Per client (default headers)

Frameworks and other clients

Anything that lets you set HTTP headers works the same way. With LangChain, pass the header as default_headers on ChatOpenAI; with the Vercel AI SDK, pass headers to createOpenAI; with plain fetch, requests or curl, add it to the request. HTTP header values must be Latin-1: in Node, JSON.stringify leaves non-ASCII characters in a name as they are and fetch throws on them, so escape them or send only user_id. Python’s json.dumps escapes them by default.
Use the header, not a body field. The OpenAI user field and the Anthropic metadata.user_id field are not read as the end-user identity. Only X-ManyLayers-Metadata is. The OpenAI user field keeps its other uses: it is still the sticky-routing key when no X-Session-Id is sent, and the gateway forwards it to the provider, so do not put a value there you do not want the provider to see. Anthropic metadata is dropped when the request is translated.

Which endpoints carry the identity

The identity applies on /v1/chat/completions, /v1/completions, /v1/embeddings, and on /v1/responses and /v1/messages (which are translated into chat completions and keep their headers). No other endpoint carries the identity: image, audio, realtime, moderation, rerank, file, MCP and knowledge-base requests, and /v1/async jobs, are attributed on the key and never to an end user, so per-user budgets, rate limits and the usage API do not see them — see Limitations.

What happens to a request

  1. The gateway authenticates the key and resolves your organization and workspace.
  2. It reads user_id from the header and looks the user up in your organization’s registry (registering them on first sight). A blocked user is refused with 403 end_user_blocked before any provider is called.
  3. The policy engine runs first — access, model restrictions, per-request token limits, rate limits (including the user’s own) and spend budgets. Then the prompt injection firewall, PII redaction, guardrails and the cache lookup run; then the prompt is counted, token-per-minute limits are checked, and the user’s budget is reserved (see End-User Budgets).
  4. The provider is called and the response returned.
  5. Usage is recorded against (your organization, user_id), so it appears in the console and in the usage API typically within a few seconds. Enforcement does not wait for it.
The end-user controls are added to your existing policies, never a bypass of them. Guardrail rules can also match on the metadata (for example a condition on user_id) with no extra wiring.

Gateway configuration

Set these under end_users: in the gateway config (self-hosted deployments):
Turn on require_identity once every code path in your backend sets the header. Until then, requests without it quietly bypass per-user budgets.
require_identity is enforced on every request that goes through the inference pipeline, not only your customers’ traffic. Only the evaluation judge is exempt. Calls the gateway makes on its own behalf — the Auto Routing classifier, agents, channels and other console features that call a model — carry no X-ManyLayers-Metadata header and are refused with 400 end_user_identity_required. Leave require_identity off if you use those features.

Errors you can hit

All use the OpenAI error envelope, so SDKs raise them as ordinary API errors. See the budget-exceeded body for the extra fields on a 402.

Next steps

Read usage in your app

Show each user their spend, tokens and request history.

Set budgets

Cap what each user can spend and refuse requests over the cap.