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 theX-ManyLayers-Metadata header, a JSON object whose values are strings:
user_idis the identity.nameandemailonly 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_idthat 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.
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.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 asdefault_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
- The gateway authenticates the key and resolves your organization and workspace.
- It reads
user_idfrom the header and looks the user up in your organization’s registry (registering them on first sight). A blocked user is refused with403 end_user_blockedbefore any provider is called. - 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).
- The provider is called and the response returned.
- 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.
user_id) with no extra wiring.
Gateway configuration
Set these underend_users: in the gateway config (self-hosted deployments):
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.