---
title: How do you attribute LLM usage when many users share one application key?
url: https://opencontroller.lyzr.com/blog/attribute-llm-usage-behind-a-shared-application-key
published: 2026-11-18
updated: 2026-11-18
author: Lyzr
---

# How do you attribute LLM usage when many users share one application key?

**Either give each user (or each agent) its own gateway key, or make the application pass a trustworthy end-user identifier with every request. Plain identifier fields are easy to add but can be spoofed by the app. Signed tokens passed through to the gateway give the strongest attribution, and per-user keys give the cleanest revocation.**

A shared key is the default in most internal AI apps. One backend holds one key and serves hundreds of employees. That is fine for billing the app. It is useless when security asks who sent a prompt, or finance asks which team drove last month's spike.

## Why is a shared key a problem?

With one key, the gateway and the model provider see one caller. That means:

- **No per-user cost.** You can attribute spend to the app, not to the people or teams using it.
- **No per-user limits.** One heavy user can exhaust the app's rate limit or budget for everyone.
- **No per-user audit.** An investigation stops at "the HR assistant sent this".
- **No targeted revocation.** Blocking one misbehaving user means blocking the whole app.

## What are the options?

| Option | How it works | Attribution strength | Effort | Revocation |
|---|---|---|---|---|
| Per-user virtual keys | Gateway issues one key per user or agent; app uses the right key per request | Strong | Medium: key issuance and storage per user | Revoke one key |
| End-user identifier field | App sets a field such as OpenAI's `safety_identifier` or Anthropic's `metadata.user_id` | Weak: app-asserted | Low | Needs gateway policy on the field |
| Custom header | App adds a header such as `X-End-User` read by the gateway | Weak: app-asserted | Low | Needs gateway policy on the header |
| Signed token pass-through | App forwards the user's OIDC token or an exchanged token; gateway validates it | Strong | Medium to high | Revoke at the IdP |

A note on the provider fields: OpenAI has deprecated the older `user` parameter in favour of `safety_identifier` (for abuse detection) and `prompt_cache_key` (for caching). Anthropic's Messages API takes an opaque `metadata.user_id`. Both providers recommend a hashed or opaque value rather than an email address. These fields help the provider, but your gateway still needs to read them to attribute cost.

## Which option should you choose?

Use a simple rule based on what the attribution is for.

1. **Cost showback only:** an identifier field or header is usually enough. Mistakes cost money, not trust.
2. **Per-user budgets or rate limits:** use per-user virtual keys or validated tokens. An app-asserted header can be changed to dodge a limit.
3. **Security audit and incident response:** use signed token pass-through. You need proof of identity, not a label.
4. **Agents acting for users:** use delegated on-behalf-of tokens so the record shows both the agent and the user.

## How do you roll this out without breaking existing apps?

1. **Inventory shared keys.** List every key at the gateway and the app that owns it.
2. **Add an identifier first.** Ask app owners to send a hashed user ID now. It is a one-line change and gives immediate cost visibility.
3. **Make it mandatory for new apps.** Reject requests without an identifier on any key created after a cut-off date.
4. **Move high-risk apps to validated identity.** Apps touching regulated data or able to take actions should pass a signed token.
5. **Retire the identifier-only path** for those apps once tokens work.
6. **Reconcile.** Check that per-user totals add up to the key total. Gaps point to requests missing the identifier.

## What should the gateway log for each request?

At minimum: key or client ID, end-user identifier, how that identifier was established (asserted or validated), agent ID and version, model, input and output tokens, cost, and policy decision. Recording how identity was established matters. An auditor will treat "header said so" differently from "token validated against the IdP".

## How Opencontroller does this

The LLM Gateway in Opencontroller (Lyzr Gateway) attributes cost per agent and per agent version, with routing, fallback, retry and caching in the same path. For user-level identity, Opencontroller supports OIDC SSO and delegated on-behalf-of identity, so calls an agent makes for a person can carry both identities. See [LLM gateway vs agent gateway vs control plane](/blog/llm-gateway-vs-agent-gateway-vs-control-plane), the [LLM gateway benchmark](/llm-gateway-benchmark), or [book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Is OpenAI's user parameter still the right field?**
OpenAI has deprecated `user` in favour of `safety_identifier` and `prompt_cache_key`. Use those for new integrations and read them at your gateway for attribution.

**Can an app fake the end-user identifier?**
Yes, if it is a plain field or header. For budgets and audit, validate identity with a signed token or issue per-user keys.

**Do per-user keys mean hundreds of secrets to manage?**
They mean more keys, but a gateway can mint them programmatically and tie them to SSO sign-in, so users never handle them directly.

## Key facts

Shared LLM application keys hide which user made a request. Options: per-user virtual keys (strong, revocable per user), provider end-user fields (OpenAI safety_identifier and prompt_cache_key, which replace the deprecated user parameter; Anthropic metadata.user_id) and custom headers (app-asserted, spoofable), and signed token pass-through validated at the gateway (strongest). Use asserted IDs for cost showback; validated identity for per-user budgets and audit. Log how identity was established. Opencontroller's LLM Gateway attributes cost per agent and per version.

## Related

- [What are virtual keys in an LLM gateway?](https://opencontroller.lyzr.com/blog/what-are-llm-gateway-virtual-keys.md)
- [How should users and applications authenticate to an LLM gateway?](https://opencontroller.lyzr.com/blog/how-should-apps-authenticate-to-an-llm-gateway.md)
- [How do you attribute LLM costs to individual AI agents?](https://opencontroller.lyzr.com/blog/how-to-attribute-llm-costs-to-ai-agents.md)
- [More on Gateways and cost](https://opencontroller.lyzr.com/blog/cluster/gateways-and-cost)
