Why Track Spend for Each Agent
An agent calls the LLM in a loop until it finishes its task. A bad prompt, a tool error, or a retry loop can make it run for hours. If all agents share one key, the invoice shows one total, and you cannot find the agent that caused it. For FinOps, each cost record needs the agent, the model, and the team. AI Studio calculates cost from the token counts in each LLM response and the model prices that you set. It does not estimate cost from your invoice.How Do I Attribute LLM Token Costs to an Agent, Team, or App?
Create one App for each agent. The App is the identity that AI Studio uses for cost, budgets, and access.- Create an App for the agent, and give it a name that identifies the agent, for example
invoice-reconciler. See Creating an App. - Grant the App access only to the LLMs and tools that the agent needs.
- Select the App’s Team. The Team is the cost center for Team budgets.
- Activate the App’s credentials. See App lifecycle.
- Give the App’s credentials to that agent only.
AI Studio adds the costs of each App to its Team. The Team Costs table on the dashboard shows the cost, share, tokens, and requests of each Team.
If agents get tokens from your identity provider instead of App keys, use the OAuth2 Client Credentials plugin (Enterprise, 2.2.1 or later). It maps each OAuth client to an App. It can also create an App for each new client from a template.
How Do I Set a Hard Budget Cap on LLM Spend per Agent or Team?
Set a monthly budget on the agent’s App. In the App form, set the budget to Fixed amount and enter the limit. You can also set budgets on an LLM configuration and on a Team. AI Studio checks every budget that applies to a request, and refuses the request if one of them is spent. When the App’s budget is spent, the gateway returns this error on the OpenAI-compatible endpoints:
The budget period is one month. For all budget settings, see Budget control.
AI Studio does not have a per-App limit for requests per minute (RPM) or tokens per minute (TPM). The monthly budget is the cap on spend.
The Agent Found It Can Call an Expensive API in a Loop: Where Does the Kill Switch Go?
Put it where the loop spends money.
A budget stops a loop only after the loop has spent the budget. A rate limit stops it within seconds. Use both for agents that can call paid APIs. For per-tool rate limits, see MCP Gateway policies. For quotas, see Request quotas.
How Do I Track LLM Costs and Latency in Production?
AI Studio gives you three views of the same data:
For the dashboard and the metrics, see Analytics. For OpenTelemetry traces, see Observability.
You must turn on analytics in the configuration of each Edge Gateway. If the dashboard shows no data for a gateway, see Edge Gateway analytics configuration.
I Need a Log of Every Call an Agent Made, and Which User It Was Acting As
AI Studio stores a proxy log row for every LLM call. The App and LLM pages show these rows. Theuser_id of a row is the App owner, not the end user. To record the end user, use one of these methods:
- Authenticate the agent with the OAuth2 Client Credentials plugin (2.2.1 or later). For a delegated token, the proxy log stores the user in
on_behalf_ofand the agent inacting_agent. The App pages show these values as For and Agent. - Create a separate App for each end user or tenant. Each App then has its own budget and its own log.
on_behalf_of and acting_agent fields are for audit only. AI Studio does not use them for budgets or authorization. Billing stays with the App.
Tool calls through Tyk Gateway go to the MCP access logs. Each record shows the JSON-RPC method, the tool name, and a hash of the consumer’s key.
Verify the Setup
- Set a small budget on a test App, for example
$1. - Send LLM requests with the App’s credentials until the App’s cost passes
$1. - Make sure that the next request fails with
403and the codebudget_exceeded. - Make sure that the App owner received the 80% and 100% alerts. See Notifications.
- Open the App page. The proxy log shows the tokens and the cost of each call.