AI Cost Management turns every AI request that passes through AI Gateway into a usage event with a cost, a user, and a timestamp. This guide sets up a priced model, attributes usage to a principal using OIDC automatic user provisioning, tracks spend with a budget, and captures custom tags with the attribution plugin.
Every usage event’s subject resolves to principal/PRINCIPAL_UUID.
The AI Cost Management dashboard, explorer, and events debugger show the event by the principal’s display name.
A request can generate a usage event without any setup, but that event has no cost, subject, or tags to analyze. Each of the following provides useful attribution data:
- An org structure gives the provisioned principal reporting data, so its spend rolls up to the right cost center, user, and team.
- A trusted IdP resolves the token’s caller to a principal, giving the event a subject.
- A price turns the event’s token usage into a dollar cost.
- The attribution plugin captures
ai-cost-headers as tags, so you can filter and budget spend by project, team, or any other dimension you choose.
The following diagram shows how the attribution flow works:
sequenceDiagram
participant client as Client
participant gateway as AI Gateway
participant identity as Kong Identity
participant openai as OpenAI
participant billing as AI Cost Management
client->>gateway: Bearer token, ai-cost- headers
activate gateway
gateway->>gateway: AI Auth Strategy - verify token
gateway->>identity: check trusted IdP
activate identity
identity->>identity: provision principal
identity-->>gateway: principal
deactivate identity
gateway->>gateway: attribution plugin - capture ai-cost- tags
gateway->>openai: forward request
activate openai
openai-->>gateway: prompt / completion
deactivate openai
gateway->>billing: emit usage event (subject, cost, tags)
activate billing
billing->>billing: track spend against budget
billing-->>gateway: ack
deactivate billing
gateway-->>client: response
deactivate gateway