Skip to content
Token Controller Docs
Docs / Start / How it works

How it works

When your team uses AI agents, you may get bills from more than one provider, or two bills from the same one, such as an API account and a seat plan. You may want to know what each bill paid for, which project or client it belongs to, and whether it matches what your agents used. This page builds up how Token Controller answers that, in three small steps. Every term is in the glossary, and the formulas are on the data model page.

Step 1: usage

Collectorstc · mod · Actionyour own scriptUsage endpointsAPI · OpenTelemetryCSV uploadMessageperson · agent · modeltime · tokens by kindCosttokens × priceper kindsendstorePrice tableprovider · model · kind

Your agents call models, and each call uses tokens. A collector, such as tc, the Claude Code mod or your own script, gathers these calls where the agents run and sends them to a usage endpoint: the token entries API, the OpenTelemetry endpoint or a CSV upload. Token Controller first stores what it received, as it arrived, and then reads it. Nothing that arrives is thrown away, except content text such as prompts, which is removed unless your organization switches keeping it on.

Each model call becomes a message: who ran it, which agent, which model, when, and how many tokens of each kind. Everything else that came along, such as the branch, the repository or how the agent was signed in, is kept as a signal. Signals may help later, when you want to say what the work was for.

A message's cost is its tokens times the price table, kind by kind:

Tokens Price per million Cost
Input 12,000 3.00 0.036
Output 2,000 15.00 0.030
Cache read 80,000 0.30 0.024
Message 0.090

The price table knows the provider, the model and the kind. The provider is who charges you, which is not always who made the model, so Token Controller never guesses it from the model's name. When it cannot price a message for certain, the message shows as not priced yet, with its token counts, and never as zero.

Step 2: bills

Bill sourcesbilling APIsCSV uploadBillamount · datesone contractbring

Bills come in on their own, from a provider's billing API or a CSV upload. Each bill belongs to one contract: one thing a provider charges you under. A contract may be metered, like an API account billed per token, or flat, like a seat plan with a fixed fee and maybe some extra usage on top. You may have two contracts with the same provider, and each one gets its own bills. Connecting or uploading a bill creates its contract, so there is nothing to set up first. See Bills.

Step 3: tags connect the two

Usagemessages, fromstep 1Messagesignals: branch,sign-in, anythingTag sourcesJira · CRM · a listby handTagsproject · featureclient · contractBillsfrom step 2Billone contract tagThe checkbill = messages+ unexplainedbringby a rule, a default or by handone contract per billmessages with the contractamount

So far, messages and bills know nothing about each other. Tags connect them. A tag says what something was for, such as project: shop, feature: KD-1 or client: acme. Tag values may come from a tag source such as Jira or a CRM, from a list, or be typed by hand.

Tags go on messages afterwards, by a rule that reads a signal ("repository kestrel/shop is project Shop"), by a default ("feature KD-1 belongs to project Shop"), or by hand in the review list. They also run back over messages since the cutoff, so a rule you add today may tag last month's messages too. A contract rule may run back further, since it changes no figure as of the cutoff.

One tag is built in for the money side: contract. A bill has exactly one contract, and a message gets at most one, from the first of these that applies:

  1. Someone set it by hand, or the collector sent it.
  2. A rule matched a signal, such as the account the agent was signed in to, or the agent's name. Token Controller ships sign-in rules for the agents that report their sign-in.
  3. The message's project brings a contract by default.
  4. The message's provider has only one contract.

With the contract on both, a bill can be checked against its own messages. For a metered contract, the bill should equal the cost of the messages with that contract, plus what no message explains, such as usage in the provider's own chat app. For a flat contract, the bill is the fee plus any extra usage. Next to every check you also see the messages of the same provider that have no contract yet, and those that got their contract only because the provider has one, so a check cannot look right by leaving messages out.

The whole picture

Usage sourcescollectors send tousage endpointsMessagetokens by kindsignalsCosttokens × priceper kindReportscost by any tagTag sourcesJira · CRM · listby handTagsproject · featureclient · contractPrice tableours, or thecontract's ownBill sourcesbilling APIsCSV uploadBillamount · datesThe checkbill = messages+ unexplainedrulescontract

Usage, tags and bills each come from their own sources and load in any order. The price table turns messages into cost. Reports show that cost by any tag, and the check compares each bill with the messages under its contract.

A worked month

A small agency works in March with three contracts: a Claude seat plan claude-team (flat, fee 200), an Anthropic API account anthropic-api (metered) and an OpenAI API account openai-api (metered). Features KD-1 and KD-2 have the default project Shop, and Shop has the default client Acme. Mara and Tom have the attribute team web, and team web has the default department engineering. Tom holds the service token of the review bot.

Session Person Agent Contract Set by Cost
S1 Mara Claude Code claude-team rule: signed in to the team's Claude organization 400
S2 Mara Codex openai-api the provider's only contract 300
S3 Tom review bot anthropic-api rule: agent name review bot 100
S4 Tom Claude Code anthropic-api by hand, in the review list 150
All messages 950

The same sessions by what the work was for:

Session Split Cost Deepest tag Label
S1 100 % 400 KD-1 direct
S2 60 % 180 KD-1 direct
S2 40 % 120 KD-2 direct
S3 100 % 100 Shop project overhead
S4 100 % 150 none organization overhead

The three bills and their checks:

Contract Bill Messages Unexplained Fee Extra usage Covered by the plan
anthropic-api, metered 270 250 20
openai-api, metered 300 300 0
claude-team, flat 250 400 200 50 350

Check, metered: 250 + 20 − 270 = 0 and 300 + 0 − 300 = 0. Check, flat: 200 + 50 − 250 = 0. Beside the checks: no Anthropic message without a contract, and the 300 of OpenAI messages that got their contract from the fallback.

Reports show cost at the price table: 950 in all, of which 400 is marked "on a plan" because the seat plan's fee already paid for most of it. The bills add up to 820. They differ from 950 because the seat plan covered 350 of its 400 for a fee of 200, and the Anthropic API bill has 20 that no message explains: 950 − 350 + 200 + 20 = 820.

Every slice of the same 950: person Mara 700, Tom 250. Feature KD-1 580, KD-2 120, Shop only 100, none 150. Label direct 700, project overhead 100, organization overhead 150. Project Shop 800, none 150. Client Acme 800. Team web 950. Department engineering 950. Contract claude-team 400, openai-api 300, anthropic-api 250.

Who and how much

A session may have worked on more than one thing. A split puts fractions of it on different tags, such as 60 % on KD-1 and 40 % on KD-2. People carry attributes, such as their team, so you may also ask what a team or a department spent. A split with a feature is direct, with a project and no feature project overhead, with neither organization overhead. It always keeps its person.

Every report uses one formula: the cost of a filter, which is any set of tags and attributes, over a date range. For one tag name the values add up to the total, so cost per project adds up to the whole. Two filters on different names, such as team: web and project: shop, may count the same money and are never added up. See Reports.

Figures as of a date

Your organization keeps everything as an append-only log. A correction is a new entry that reverses an older one, and the older one stays visible. Every figure is computed when you look, as of a date: today for the current figures, or the cutoff for the figures you already gave to finance. A rule or a contract that runs back in time never changes figures as of the cutoff.

Plans and deviation

On top of cost you may plan. An estimate is what described work may cost, as bands with a median. Accepting one makes it the plan for its tags, spread over its days. The deviation is plan minus cost, for any filter and date range, and positive is favourable. Plans read cost and never change it. See Deviation and forecast.

Agents

An agent is software that calls a model on a person's behalf. Token Controller keeps no record of agents, only their messages, each with its agent and an optional agent name. A person typing in a provider's own chat app is not an agent; that usage is what a bill has that no message explains. What is kept and what is removed is on Security and privacy.

Local first

The CLI is useful with no service connected, including an export for a spreadsheet. The local tool and the service talk over the documented API, so the local tool can connect to any compatible service, or none.

Last updated 27 November 2026 · Edit this page© 2026 Jan Beck · Privacy · Imprint