The cost of an AI system: tokens, evals and CI minutes
When people talk about the cost of an LLM feature they mean tokens in production. On the AI layer for a fintech platform there were three bills, and the one everyone watches was not the one that ran out first. Model calls in production, eval runs against real models and CI minutes each needed a cap, and each cap has a place where it leaks.
Bill one: model calls
There are three limits, all in money:
| Limit | Value |
|---|---|
| A run started by a user’s question | $0.50 |
| A system-triggered run | $0.05 |
| One user, per their local day | $3.00 |
All three are environment variables, set explicitly on every environment. There is no ‘unlimited’: a zero stops the run from starting, so the cheapest mistake in configuration is a run that doesn’t happen, not one that spends freely. When a limit is hit, the step raises its own budget error, and steps that generate text fall back to a fixed text written in advance rather than failing the run.
The check runs before each model call and reserves nothing. That is a deliberate trade-off, and it leaks: two parallel tasks of the same user can each pass the check and each make one more call over the limit. With runs this short the overshoot is one call per parallel task, and an atomic reservation would add a write to the hot path of every call. If long parallel runs appear, I would reserve instead of check.
Cost is recorded per attempt, when the attempt finishes, as the sum of its calls. A call the provider returns without a price counts as zero and is stored as empty, not as zero – so ‘we don’t know’ never reads as ‘it was free’.
There is a quieter leak worth knowing about. LiteLLM computes cost from its own price table, so a model configured under a name the pinned LiteLLM version doesn’t know is priced at $0.00. Every limit above then passes forever. The model names in configuration have to be ones the pinned version can price, and that belongs in a test, not in a code review.
Choosing models by class, not by request
Model choice is a fixed policy from a task class to a primary and a fallback model:
| Task class | Primary | Fallback |
|---|---|---|
structuring |
GPT-5.6 Terra | Claude Sonnet 5 |
grounded_answer |
Gemini 3.1 Flash-Lite | GPT-5.6 Luna |
client_text |
Claude Fable 5 | Claude Opus 5 |
bulk_extraction |
Gemini 3.1 Flash-Lite | GPT-5.6 Luna |
table_extraction |
Gemini 3.1 Pro | Gemini 3.7 Flash |
There is no semantic router deciding per request. A router can save money on easy requests, but it makes cost and behaviour depend on a classifier you also have to evaluate, and it turns ‘which model answered this?’ into a question with many answers. A fixed table makes cost predictable per class, makes the fallback path testable – I wrote about why that matters in testing LLM integrations – and keeps the expensive models where the text reaches a client.
The critic has no class of its own. It runs as structuring, and the worker refuses to start if the critic’s models are the same as the author’s. Independence is enforced by code, not by remembering to configure it.
I don’t have a summary of production spend per class to publish – only the eval runs below – so I won’t quote one.
Bill two: eval runs
Evals against real models cost money, so they don’t run in CI. On the back-office QA set of 115 questions a full run cost $1.62, then $2.53, then $3.64 and $3.63 as the agents improved. The curve runs the wrong way on purpose: a run that stops at a clarifying question is cheap, and one that reaches the final text and the critic isn’t. A better system makes its eval more expensive. The runner estimates a run from recent costs per agent before it starts and refuses one over the operator’s $20 limit.
Bill three: CI minutes
The bill that actually ran out was GitHub Actions minutes.
The suite outgrew its runner first. On 2 vCPU a full run no longer fit in 30 minutes. Two changes fixed it:
- Cleaning the test database. It had taken 9 to 11 minutes of a run. It became one function that deletes from every table, children before parents, in a single transaction, used by all 12 fixtures that had each cleaned up their own way. That brought it down to about four minutes.
- Parallelism with isolation.
pytest-xdistwith a database per worker, and four shards on separate runners – use cases, agents, Temporal, platform – plus a job that combines coverage. On 20 October that was 5,565 tests in 16.1 minutes. A test fails if any test file belongs to no shard or to two, so a new module can’t silently drop out of CI.
Two smaller choices helped. In CI the database runs in memory with fsync off, since tests need no durability. And schema builds take an advisory lock, because creating a schema takes about 1,500 locks on the server’s shared table and parallel workers building theirs at once would collide.
Then the minutes ran out anyway. Every promotion into the integration branch ran the full CI twice: once for the push, and once for the open pull request from that branch to the release branch. Same commit, same tests, double the minutes. I proposed removing the duplicate to the team; at the time of writing it is still open, and I don’t have a figure for how many minutes it cost.
What I would do from day one
- Treat CI triggers as a budget line. Deduplicate push and pull-request runs for the same commit before the suite is large enough for it to matter.
- Test that every configured model has a price. A $0.00 model disables every cost limit you have.
- Reserve budget atomically as soon as runs get long or parallel, not after the first overshoot.
None of the three bills is exotic. The point is that each one needs a cap set in money or minutes, a test that the cap works, and a known place where it leaks. The broader design these caps sit in is in multi-agent pipeline architecture.