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:
OrderSourceEffect
1identity object in the request bodyTags the request and upserts the identity record (name, email, metadata)
2X-ORQ-IDENTITY-ID request headerTags the request only; does not update the identity record
3API key ownerTags the request only; applies automatically when the key is user-owned
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
curl 'https://api.orq.ai/v3/router/chat/completions' \
  -H "Authorization: Bearer $ORQ_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "anthropic/claude-sonnet-4-6",
    "messages": [{"role": "user", "content": "Hello"}],
    "identity": {"id": "user_123"}
  }'
OpenAI SDK
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.ORQ_API_KEY,
  baseURL: "https://api.orq.ai/v3/router",
});

const response = await client.responses.create({
  model: "openai/gpt-4o",
  input: "Hello",
  extra_body: {
    identity: {
      id: "user_123",
      display_name: "John Smith",
      email: "john@example.com",
      metadata: [{ plan: "pro" }],
    },
  },
});

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.
curl 'https://api.orq.ai/v2/identities/<id>' \
  -H "Authorization: Bearer $ORQ_API_KEY" \
  -H 'Accept: application/json'
The response returns the full identity record:
{
  "_id": "01ARZ3NDEKTSV4RRFFQ69G5FAV",
  "external_id": "user_12345",
  "display_name": "John Smith",
  "email": "john@example.com",
  "avatar_url": "https://example.com/avatars/john-smith.jpg",
  "tags": ["premium", "beta-user"],
  "metadata": {
    "department": "Engineering",
    "role": "Senior Developer",
    "subscription_tier": "premium"
  },
  "created": "2024-01-15T10:30:00Z",
  "updated": "2024-01-15T10:30:00Z"
}
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.
curl 'https://api.orq.ai/v2/identities?include_metrics=true' \
  -H "Authorization: Bearer $ORQ_API_KEY" \
  -H 'Accept: application/json'
Each identity includes a metrics object covering the last 30 days:
FieldDescription
total_costTotal spend in USD
total_tokensTotal tokens consumed
total_requestsTotal number of requests
error_rateRatio of failed requests (e.g. 0.33 = 33% errors)
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:
FieldTypeRequiredDescription
idstringYesUnique identity identifier (max 255 characters)
display_namestringNoHuman-readable name
emailstringNoEmail address
metadataobject[]NoArray of objects with custom key-value pairs (max 20 fields)
logo_urlstringNoURL to a profile image
tagsstring[]NoClassification tags for segmentation (max 10)

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

IssueCauseSolution
Identity not appearing in analyticsMissing or invalid identity.idEnsure identity.id is provided and non-empty
Duplicate identities in the dashboardInconsistent ID format across requestsStandardize identity ID generation in one place