DocsAuthentication

Authentication

Beta. The Langfuse AI Gateway is in public beta and can still change.

Clients authenticate with the Langfuse AI Gateway by using API keys. The gateway then maps the user and its request content to organization settings, model provider API keys, and request routes. See the Concepts page for more detail.

User and service account keys

Every key is either a user key, which belongs to the person who creates it, or a service account key, which belongs to the organization:

User keyService account key
Use forCoding agents, local developmentCI, shared services
Who can create itAny gateway userAdmins/owners
Trace userThe key owner's emailThe client's langfuse-user-id, otherwise the key name. See trace user.
When it stopsWhen it is revoked or expires, or when its owner loses gateway accessWhen it is revoked or expires. Membership changes don't affect it.

Both key types can call every model the organization's provider credentials allow.

Create a key

  1. Go to Organization settings → AI Gateway → Gateway keys and select Create key.
  2. Admins and owners choose Issued as: My user or Service account. Other users don't see this option and always create a user key.
  3. Enter a name that describes what uses the key, for example Checkout agent or CI release pipeline. The name is shown in the key list, and service account keys use it as the trace user.
  4. Optionally set an expiration.
  5. Optionally add metadata as key-value pairs.
  6. Select Create key and copy the secret key. It's shown only once.

Create gateway key dialog with the Issued as choice, name, expiration, and metadata fields

Creating and revoking a key are recorded in the audit log.

Key metadata

Metadata on a key lets you segment and attribute gateway traffic. Add key-value pairs such as:

  • team: platform
  • cost_center: 4711
  • environment: production

The gateway attaches them to every generation recorded with the key, under langfuse.gateway.api_key.metadata.<key>. Filter traces, observations, and custom dashboard charts on these keys to see usage and cost for one team, cost center, or service.

Metadata can only be set when you create a key. To change it, issue a new key and revoke the old one.

User ID

The gateway sets the trace user ID depending on the key type:

Key typeUser ID
User keyAlways the owner's email, or their Langfuse user ID if the email is unknown. Clients can't override it, so a trace from a user key always shows who made the call.
Service account keyThe langfuse-user-id header or baggage entry, so you can forward the end user's ID. Without one, the gateway uses the key name, unless the call runs inside your own trace, where the user on your spans stays in effect.

Each generation also records these user-related metadata fields:

FieldValue
langfuse.gateway.user_id_sourceWhere the user ID came from: api_key_owner, client, or api_key_name
langfuse.gateway.api_key.idThe gateway key's ID
langfuse.gateway.api_key.nameThe gateway key's name
langfuse.gateway.api_key.owner.user_idThe key owner's Langfuse user ID (user keys only)
langfuse.gateway.api_key.owner.nameThe key owner's name (user keys only)

To attribute traces by team or cost center as well, add key metadata.

A user key stops working as soon as its owner loses gateway access: they leave the organization, their role changes to one that can't call the gateway (for example Viewer), or they delete their Langfuse account. Service account keys aren't affected, so use one for shared services.


Was this page helpful?

Last updated on