Usage tags
Last updated: 2026-11-21T08:59:43-03:00 (UTC-3)
Tag each request with an environment, application, or cost center, and then filter and group usage and cost by those tags. The client sends the tags in a header; you define the accepted values, and each team can have default tags. Flag: usage_tags.
Tags are for attribution and reporting. They do not change authorization, price, or limits, and they do not prove origin: they are declared by the key. (To reserve targets by tag, see tag-based routing.)
How to turn it on
Section titled “How to turn it on”features: usage_analytics: true usage_tags: true # requires usage_analytics and a database usage_tag_defaults: true # optional: default tags per team usage_tag_scoped_defaults: true # optional: also per model alias and per key; requires usage_tag_defaults usage_tag_management: true # optional: edit in the console; requires ui and PostgreSQLusage_tags: allowed_values: environment: [production, staging] application: [support, batch] defaults_by_team: team_example_id: # the team ID, not its name environment: production application: support defaults_by_model: # with usage_tag_scoped_defaults embeddings-default: # the alias ID application: batch defaults_by_key: # with usage_tag_scoped_defaults key_example_id: # the key ID (YAML or managed) environment: staging| Key | What it does |
|---|---|
usage_tags.allowed_values |
The taxonomy: each tag name with its closed list of allowed values; any other name or value is refused |
usage_tags.defaults_by_team |
Map of a team ID to the tags its keys’ requests get when the client does not send them (usage_tag_defaults) |
usage_tags.defaults_by_model |
The same, per canonical model alias (usage_tag_scoped_defaults) |
usage_tags.defaults_by_key |
The same, per key ID (usage_tag_scoped_defaults); precedence, lowest first: team, model, key, then the client header |
| Rule | Limit |
|---|---|
| Tag names | up to 16 |
| Values per name | 1 to 32, unique |
| Name and value format | [A-Za-z0-9][A-Za-z0-9_.-]{0,63}, case-sensitive |
| Teams with defaults | up to 128, each with 1 to 8 pairs |
| Model aliases with defaults | up to 128, each with 1 to 8 pairs |
| Keys with defaults | up to 256, each with 1 to 8 pairs |
| Alias and key IDs | [A-Za-z0-9][A-Za-z0-9_.:/@-]{0,127} |
| Whole policy | 16 KiB |
The closed list of values is deliberate: it keeps free text (and personal data or secrets) from becoming a tag by mistake.
How to use it
Section titled “How to use it”curl http://localhost:8080/v1/embeddings \ -H "Authorization: Bearer $GATEWAY_API_KEY" \ -H 'Content-Type: application/json' \ -H 'X-Gateway-Tags: {"environment":"production","application":"batch"}' \ -d '{"model": "embeddings-default", "input": "test text"}'- A single
X-Gateway-Tags, up to 2 KiB and eight pairs, as a flat JSON object of strings. - The name and value must be on the allowed list. Outside it,
400; with the flag off,404. - Team defaults: with
usage_tag_defaults, the gateway applies the default tags of the key’s team. The client can swap a default value for another allowed one, but cannot remove it. The total is still limited to eight pairs. - Model and key defaults: with
usage_tag_scoped_defaultsas well, the defaults of the alias that serves the request (for an automatic router, the alias it chose) and of the authenticated key are layered on top, before any conditional routing reads the tags. Each layer replaces a name an earlier one set, lowest first: team, model alias, key, then the header. In the example above a request withkey_example_idtoembeddings-defaultrecordsenvironment: staging(key) andapplication: batch(alias) unless the header names them. An alias or key ID that does not exist (yet) stays latent and is not an error, so deleting a key or alias never invalidates the policy. - With the flag off,
defaults_by_modelanddefaults_by_keyfrom YAML stay validated but unused, and the API refuses to save them (403 feature_disabled). The batch check of required attribution counts team and key defaults only, because a batch is checked before its lines name their models; each line is admitted again with its own alias. - The team, key and alias always come from authentication and admission, never from the header or the body.
This applies to Chat, the other inference routes, and native Gemini. It does not apply to MCP, /v1/models, or administrative routes. The header is not sent to the provider, and tags do not go into structured logs, spans, or Prometheus metrics.
Filtering and grouping
Section titled “Filtering and grouping”Analytics, Request logs, the CSVs, valuation, and receipts accept tags: a JSON object with up to four pairs, combined with AND.
curl -b "$COOKIE_FILE" --get \ --data-urlencode 'tags={"environment":"production"}' \ --data-urlencode 'tag_dimension=application' \ http://localhost:8080/api/v1/admin/analyticstag_dimensiongroups by one tag in analytics, CSV, and valuation: up to 20 values, with one group for events without the tag.- The filter accepts values that have since left the allowed list, so you can investigate the past.
- Team roles still see only their own events.
In the console, Analytics, Request logs, and Durability have the tag filter; the drill-down from Analytics to Request logs preserves the filters.
Editing the policy
Section titled “Editing the policy”With usage_tag_management, Usage tags in the console edits the list and the per-team defaults in a JSON editor, for the global admin only. The API is /api/v1/admin/usage-tags:
| Method | What it does |
|---|---|
GET |
{version, source, effective, base_fingerprint} |
PUT |
Replaces the whole policy: {version, expected_base_fingerprint, policy} |
DELETE |
Reverts to the YAML |
Writes require a session, same origin, and CSRF, and they go into the audit log (without the policy values). Viewer, operator, and team roles do not see the global policy.
How tags are stored
Section titled “How tags are stored”- Each request records its tags once, in the usage event and in the durable receipt. Changing the list or the defaults later does not alter the past.
- Requests served by the same cache each keep their own tags.
- Without
durable_usage, recording is best effort and can be missing if the database fails. - Turning
usage_tagsoff preserves the history, but hides the tags and makes the filters respond404instead of ignoring them. Turning it back on shows everything again.
Limits
Section titled “Limits”-
Defaults per key and per alias need
usage_tag_scoped_defaults. -
No free text and no tags read from the body (
metadata,tags). -
Budgets and TPM are not enforced per tag. To budget an application, harness or repository, use attribution groups, which the server decides from the authenticated key and model.
Which layer set a tag
Section titled “Which layer set a tag”With usage_tag_provenance (off by default; requires usage_tags), each new usage event also records, per tag, the layer whose value won: team, model or key (a default) or header (X-Gateway-Tags). The request journey shows it as Tag sources (app=team, env=header) and in event.tag_sources, only while usage_tags and the flag are on. Earlier records, and records written with the flag off, have no sources; the policy of that time is in the audit log. Migration 170 adds the nullable column; nothing is written until the flag is on. The sources also travel with the event to configured log destinations, as layer names only.
features: usage_tags: true usage_tag_defaults: true usage_tag_provenance: trueSee also
Section titled “See also”- Required attribution: a team or key that refuses requests without given tag names (
attribution_requirements). - Analytics experience.
- Valuation.
Typed policy constraints
Section titled “Typed policy constraints”Tag allowlists and defaults remain typed, bounded domain maps. Names and values use the existing ASCII slug grammar; team defaults refer to authenticated team identity and explicitly allowed values. Shared parameter definitions cannot expose configured tag names/team IDs in a safe scalar catalog or grant permission. Existing parser, merged-map bounds, versioned management and team-scoped analytics remain authoritative.