Skip to main content
Identities group AI Gateway requests by user, team, project, or client, giving per-identity visibility into cost, token usage, and error rates. They can represent:
  • a User
  • a Team
  • a Project
  • a Client
Identities list showing name, source tag, request count, cost in dollars, token count, and error rate columns. Common use cases:
  • Per-user cost attribution and cross-charging to tenants or customers.
  • Enforcing per-user rate limits to prevent abuse.
  • Identifying which users generate the most load or cost.
  • Linking LLM usage to existing user analytics for cohort analysis.

Creating an identity

In the AI Gateway sidebar, go to Identities and click New Identity. Fill in the external ID and any optional fields (display name, email, metadata), then click Create.The identity is available immediately and can be attached to requests using its external ID.

Attaching an identity to a request

Every AI Gateway request can be attributed to a specific user, team, or client. The gateway checks each of the following sources in order and uses the first match found:
Pass the identity’s external_id in the identity.id field on any AI Gateway request. If no identity with that external_id exists, one is created automatically; if it does exist, its record is updated with any display_name, email, or metadata provided.
The identityId / identity_id constructor option was removed in SDK v4.10.0. Pass identity on each request instead.
Orq SDK
OpenAI SDK

Retrieving an identity via the API

Once an identity is in use, fetch its full record at any time using its _id (ULID) or external_id.
The response returns the full identity record:
See the API Reference for the full parameter and response specification.

Listing identities with metrics

Pass include_metrics=true to retrieve 30-day usage metrics for each identity.
Each identity includes a metrics object covering the last 30 days:
See the API Reference for pagination, search, and tag filtering parameters.

Identity field reference

Fields accepted on the identity object for any AI Gateway request:

Best practices

  • Consistent IDs: Use predictable identity ID patterns (e.g. user-{userId}, tenant-{orgId}-{userId}) across the application.
  • Essential metadata only: Include only relevant metadata fields to minimize payload size.
  • Tag strategy: Use tags for filtering and segmentation rather than storing detailed data.
  • Privacy compliance: Ensure identity data handling meets applicable privacy requirements.
  • Validation: Validate id format and length before sending requests.

Troubleshooting