- Identities, which represent a tenant or its end users on each request.
- Request metadata, which tags a call with a tenant ID or other key-value data.
Which approach to use
Choose the approach by how fixed each tenant is and by what needs to be enforced or reported. Use an Identity for tenants or end users that are known and stable, when cost and usage must be metered, capped, and reported per identity. Use metadata when requests only need a tag to filter on later, and the tenant isn’t something to budget against.Approach 1: Identity per tenant
An Identity represents a User, Team, Project, or Client. Create one identity per tenant and attach it to every request that tenant makes. Usage, cost, and traces then attribute to the identity, enabling per-tenant reporting, per-identity budgets, and trace filtering. Create an identity for each tenant once:orq.identities.create); requests run through the OpenAI-compatible SDK (openai client) or the /v3/router endpoints, which accept the identity and metadata fields on the request body.
To track both a tenant and the person acting for it, give each end user an identity ID such as tenant-{orgId}-{userId}, or create one identity per tenant and share it across that tenant’s users. See Attaching an identity to a request for the body, header, and API-key-owner sources, in the order the gateway checks them.
Approach 2: Request metadata
For tenants that don’t map to a fixed set of identities, tag requests with request metadata. Metadata adds key-value context such astenant_id, region, or tier, which appears on traces as metadata.<key> span attributes and can be used as a trace filter.
Pass a metadata object on the request:
X-ORQ-METADATA-<key> header sets one metadata key, lowercased from the header suffix:
cURL
Keep metadata to a small, fixed set of low-cardinality keys such as
tenant_id, region, and tier. High-cardinality values, such as per-request IDs, defeat filtering and increase storage. See Request metadata best practices.Identity and metadata together
Use an Identity to meter and budget a tenant; use metadata for extra context such as region or product line. The two work together: attach the tenant’s Identity for per-tenant attribution and budgets, then add metadata to describe the request.Worked example: one tenant, end to end
This example sets up Acme Corp as a tenant with per-tenant routing, a monthly budget, and per-tenant observability, using an identity plus a routing rule keyed on identity and metadata.1
Create the tenant identity
2
Cap Acme's spend
Navigate to Settings > Organization > Budgets and click Create. Set Scope > Applies to to Identity, select the
tenant-acme identity, and set a monthly Cost limit. When the limit is reached, requests matching Acme’s identity are rejected until the monthly reset, while other tenants keep working. See Budgets for period limits and alerts.3
Route and observe Acme's traffic
On each request, attach the identity and a metadata key so routing and trace filters can target Acme:Create a Routing Rule whose condition matches the Identity
tenant-acme to send Acme’s traffic to a dedicated model or variant. Combine conditions on identity and metadata (for example region) with the rule builder.4
Report Acme's usage and cost
Query the Reporting API, filtering to the tenant identity:In the Traces view, filter by Identity
tenant-acme, or by Metadata tenant_id: acme, to inspect Acme’s latency, token usage, and errors.Isolating data and knowledge bases per tenant
Request-level attribution meters usage, but it does not separate the data a tenant can retrieve. To isolate content, put each tenant in its own Project:- Projects are the isolation boundary. A Project holds Deployments, Prompts, Agents, Knowledge Bases, and Datasets, with project-scoped observability and budgets.
- Knowledge bases follow the project. A knowledge base lives under a
project/pathand is retrieved through a Deployment in that project. With one project per tenant, a tenant’s key cannot reach another tenant’s knowledge base. - Single-project keys stay inside the tenant. Only keys created with single-project scope are confined to that tenant’s project. Workspace-wide and legacy keys can reach every project, so issue single-project keys to tenants and never hand out a workspace-wide key.
- Or share one knowledge base among trusted tenants. If tenants trust one another, tag chunks with a
client_idmetadata field and add afilter_bycondition to narrow retrieval to that tenant. This is a query-time filter, not enforced access control: any caller can omit it and read every tenant’s chunks. Use it only among trusted tenants; otherwise separate tenants into per-tenant projects. See Chunk Metadata in Knowledge Bases.
See also
Identities
Create identities and attach them to requests for per-tenant attribution and budgets.
Request Metadata
Attach name, identity, thread, tags, and custom metadata to AI Gateway requests.
Budgets
Cap spend per workspace, project, identity, API key, provider, or model.
Reporting API
Query per-tenant usage, cost, and performance programmatically.