Add your OpenID Connect (OIDC) identity provider as a trusted IdP in Access Management with automatic user provisioning enabled, then create an openid-connect AI Auth Strategy with principals.enabled and principals.jit set, and attach it to the AI Model.
The first authenticated request creates a matching principal automatically, and Konnect records the usage event’s subject as principal/PRINCIPAL_UUID.
This guide requires an OIDC provider. In this example, we’ll use Keycloak, but the steps are similar in any standard OIDC provider.
Because Konnect is cloud-hosted, it needs to reach your Keycloak instance over the public internet, so set up the ngrok tunnel prerequisite first.
Run Keycloak with its hostname set to your ngrok tunnel, so the tokens it issues use that URL as the issuer.
KC_PROXY_HEADERS tells Keycloak to trust the forwarded headers ngrok sends, so it reports https in the issuer instead of the http it sees internally:
Set an email on the service account user that matches a row in your org structure file, so automatic user provisioning can link the principal it creates to that row:
This client has one service account, so every token it issues carries the same sub and email.
Every request authenticated through it resolves to the same principal, Jordan Lee.
A real deployment authenticates each caller with their own token instead, so each one resolves to their own principal.
Automatic user provisioning creates a Kong Identity principal from any OIDC provider’s token the first time its caller authenticates, without needing to set up a Kong Identity directory, auth server, or client manually.
Every usage event’s subject resolves to principal/PRINCIPAL_UUID.
AI Cost Management attributes usage in two independent tracks: the subject and tags, which record context like project or team through a separate mechanism.
This guide covers subject attribution only. See Tags and headers for the other track.
This guide attributes usage to a principal built from your own OIDC provider.
A trusted IdP is the OIDC issuer Konnect verifies tokens against.
Mapping the token’s email claim lets a newly authenticated caller match an existing principal from your org chart, instead of creating an unlinked one.
Add a trusted IdP through the Konnect UI:
In the Konnect sidebar, click Access Management.
Click Identity Providers.
Click New identity provider if this is your first IdP, or Add trusted IdP if you already have one.
In the Name field, enter a label for this IdP, for example My OIDC Provider.
In the Issuer URL field, enter your issuer URL (run echo $OIDC_ISSUER_URL to print the value you exported in the prerequisites).
Enable Automatic user provisioning.
In the User provisioning claim mapping section, enable Set email.
In the Claim name field, enter email.
Click Add IdP.
In this example, we’re using email because the Keycloak setup prerequisite sets an email attribute on the service account.
This matches the email column in your org structure file.
Without a matching email claim, automatic user provisioning still creates a principal, but it won’t link to an existing org chart user.
AI Cost Management matches each automatically provisioned principal against your organization’s reporting structure.
Upload an org chart if you want spend to roll up to a cost center, user, or team.
If you skip this step, the principal is still created and the usage event still gets a subject, just without that reporting data.
The org structure file must be in CSV format and a maximum of 10 MB.
Choose whether to use an export from your HR system (HRIS) or a sample file:
Use the CSV file you exported from your HRIS.
Save it as org-structure.csv in your current directory, or replace org-structure.csv with the path to your file in the import command.
Create a small sample file named org-structure.csv:
You can set --dry-run instead of --execute to preview the import without changing any existing users or teams.
See Org chart in AI Cost Management for the full column reference and import behavior.
Create an AI Model Provider to connect AI Gateway to OpenAI, an openid-connectAI Auth Strategy that verifies bearer tokens against your trusted IdP and forwards claims for provisioning, and an AI Model that references both:
The strategy’s principals.jit.all_claims field forwards every token claim to the provisioning lookup, including the email claim you mapped on the trusted IdP.
The target has no input_cost or output_cost set, so AI Cost Management falls back to the model’s list price from the price catalog.
Get an access token from your OIDC provider, then send a chat completion to generate a usage event.
The auth strategy verifies the bearer token and resolves it to a principal, creating one automatically from the token’s forwarded claims if none matches yet.
Request an access token using the client credentials grant.
/protocol/openid-connect/token is Keycloak’s token endpoint path.
Adjust it if you’re using a different provider:
The events API returns the usage events for your organization, sorted by newest first.
Find the event your request generated. If your org has other traffic, check that time matches when you sent the request: