Identity Headers
After API Management authenticates a request on a route linked to an API, it adds identity headers to the request that it sends to your upstream service.
Middlewares on the same route can read these headers, for example to select an ai-quota budget.
The response that goes back to the client does not include these headers.
Headers by Authentication Method
Each authentication method sets only the headers in its column.
| Header | API key | JWT | LDAP | Keyless |
|---|---|---|---|---|
Hub-App-Id | The spec.appId of the ManagedApplication that owns the key | The value of the claim named in jwt.appIdClaim | The username used to authenticate | Not set |
Hub-App-Name | The metadata.name of the ManagedApplication that owns the key | Not set, unless jwt.forwardHeaders maps it to a claim | Not set | Not set |
Hub-Token-Name | The title of the key in apiKeys[]. Traefik Hub sends an empty value when the key has no title | The value of the claim named in jwt.tokenNameClaim. Traefik Hub does not set the header when jwt.tokenNameClaim is empty, unless jwt.forwardHeaders maps it to a claim | Not set | Not set |
Traefik Hub forwards the key title unchanged in Hub-Token-Name. Upstream services must treat it as untrusted text.
A title that contains a line break or another control character makes every request with that key fail with a 500 error.
For a JWT, jwt.forwardHeaders adds more headers. Each entry maps a header name to a claim name.
jwt:
forwardHeaders:
X-User-Email: email
See JWT Authentication for the full APIAuth options.
Set Hub-User-Id for a JWT
The AI Gateway fills the user_id label of the GenAI metrics from the Hub-User-Id header. No authentication method sets this header by default.
For a JWT, map the header to a claim in jwt.forwardHeaders, for example Hub-User-Id: sub.
Client-Sent Header Removal
Starting in v3.21.5, Traefik Hub removes these headers from each request on a route linked to an API, before it authenticates the request:
Hub-App-Id,Hub-App-Name, andHub-Token-Name.- Every header named in
forwardHeadersof theAPIAuthresources that apply to the API.
The upstream service receives only the values that the authentication method wrote after it accepted the request.
This applies to every API, including an API with keyless authentication, so a client cannot supply its own Hub-App-Id.
Traefik Hub removes headers by exact name. It does not remove:
- Other
Hub-*headers, such asHub-User-IdandHub-User-Email, unless you list them injwt.forwardHeaders. Treat aHub-User-*value as client input. - A header with a different separator, such as
Hub_App_Id. Read only the exact header names in the table.
Before v3.21.5, Traefik Hub keeps a client-sent value for every header that the authentication method does not set. For example, a keyless API forwards a client-sent Hub-App-Id.
Routes Not Linked to an API
A route is linked to an API when its IngressRoute, Ingress, or HTTPRoute has the annotation hub.traefik.io/api: <API name>, or hub.traefik.io/api-version: <APIVersion name> for an APIVersion.
On any other route, Traefik Hub does not authenticate the request, and it neither sets nor removes these headers. The upstream service and the middlewares receive whatever the client sends.
Before you use these headers as budget keys or as an identity, link the route to an API.
Limit Budgets per Application or API Key
The ai-quota middleware keeps one budget for each value of the header that sourceCriterion.requestHeaderName names.
Create one ai-quota middleware for each budget, and set sourceCriterion to the header that selects the budget:
# Budget for each application
sourceCriterion:
requestHeaderName: Hub-App-Id
---
# Budget for each API key
sourceCriterion:
requestHeaderName: Hub-Token-Name
Add both middlewares to the IngressRoute that is linked to the API, after the Chat Completion middleware.
See Per-User Limits with Source Criterion for the other middleware options, such as store and totalTokenLimit.
When both middlewares are on the route:
- Each middleware enforces its own budget. When one key spends its budget, the other keys of the application keep working until the application budget is spent.
- A client cannot reset a budget by sending its own
Hub-Token-NameorHub-App-Id. Traefik Hub replaces the value before the middleware runs. - A key without a
titlesends an emptyHub-Token-Name.ai-quotacounts every request with an empty or missing header in one shared budget, across all clients and applications. Set atitleon every key that you use as a budget key.
Troubleshooting
| Issue | Cause | Fix |
|---|---|---|
The upstream service receives no Hub-* header | The route is not linked to an API, or the API uses keyless authentication | Add the hub.traefik.io/api annotation to the route, and use an APIAuth with apiKey, jwt, or ldap |
Hub-Token-Name is missing on a JWT API | jwt.tokenNameClaim is not set, or the token lacks that claim. An ai-quota that uses Hub-Token-Name then counts these requests from all clients and applications in one budget, so one client can use up the budget for all of them | Set jwt.tokenNameClaim to the claim that holds the token name, and issue tokens that include the claim |
Hub-Token-Name is empty | The API key has no title. An ai-quota that uses Hub-Token-Name then counts requests from all untitled keys, and from requests without the header, in one budget, so one client can use up the budget for all of them | Set title on the key in apiKeys[] of the ManagedApplication |
A client-sent Hub-App-Id reaches the upstream service | The route is not linked to an API | Add the hub.traefik.io/api annotation to the route |
Next steps
- Read about API authentication.
- Read about Managed Applications and their API keys.
- Read about token and cost limits.
