# Price an AI Agent's CI Runs Before the Monthly Bill Does

> One test-triage agent priced call by call at list prices checked 6 October 2026: input climbs from 7,500 to 51,450 tokens as history is re-sent, prompt caching takes the month from $961 to $424, a 0% hit rate makes it $1,176, and summarising loses to caching once the summariser's own calls are counted.

- Author: [Shashank Rawlani](https://shashank.rawlani.com)

- Published: 2026-11-27T05:30:00.000Z

- Updated: 2026-11-27T05:30:00.000Z

- Category: Tools & Reviews

- Canonical source: https://automationtester.in/blog/tools-reviews/price-ai-agent-ci-runs-before-the-bill

- Tags: ai-agents, llm-cost, prompt-caching, ci-cd, ai-testing

**Quick answer:** Describe one agent run as steps with their new input and output tokens, set how the loop handles history, and multiply by CI runs per pull request and pull requests per day. In a loop that re-sends its history, the later calls carry most of the bill, so the per-step token counts understate the run several times over. Price that in the [Agent Cost-per-Run Estimator](https://automationtester.in/tools/agent-cost-estimator) before choosing a fix. For the CI agent below, prompt caching took the month from $961.08 to $423.60. Summarising the history looked as cheap until the calls that write the summary were priced, and then it cost more than caching alone.

A test-triage agent runs on every pull request whose CI fails. It reads the failure, the job log and the spec, patches the test up to four times, and writes a comment. Add up its steps and one run is 39,300 tokens of new input and 7,050 of output, which at Claude Sonnet 5.5's list price of $2 and $10 per million tokens is about 15 cents. Priced the way the API bills it, the run costs 73 cents, because the eighth call does not send 800 new tokens. It sends 51,450.

That gap is the whole reason a plain token calculator gets agent costs wrong. This walk-through prices one CI agent with every term that matters, finds that 63% of its cost is history sent again, and compares the two usual fixes on the same numbers. All prices are list prices read from each provider's official pricing page on 6 October 2026, and every figure below comes from the estimator's output for the scenario described.

## One triage run, described as steps

The agent has a 6,000-token fixed prefix: its system prompt plus the definitions of four tools, sent on every call. Anthropic's pricing page lists the tool definitions and the tool-use system prompt among the input tokens a request pays for, so they belong in the prefix and not in the steps. Each step's new input is what arrived since the previous call: the task itself, or the tool results the model asked for.

```
Step                            New input  Output  Times per run
Read the failure summary            1,500     400              1
Read the job log                   18,000     350              1
Read the spec and page object       9,000     600              1
Patch and rerun the test            2,500   1,200              4
Write the PR comment                  800     900              1

Fixed prefix 6,000 · history re-sent in full · 10% extra attempts per call
2 runs per pull request × 30 pull requests per day × 22 working days
```

The 10% extra attempts stand for calls whose answer the loop discarded and requested again, such as a patch that did not apply. Each one is billed like the first. Two runs per pull request accounts for the push that follows the agent's own fix. This scenario is the estimator's built-in sample, so **Load sample** reproduces every number in this section.

The estimate, from the tool's **Copy breakdown** output with the output-token column dropped:

```
| Per run (8 model calls)  | $0.728  |
| Per day (60 runs)        | $43.69  |
| Per month (1,320 runs)   | $961.08 |

| Step                          | Calls | Input tokens | Cost   | Share |
| Read the failure summary      | 1     | 8,250        | $0.021 | 2.9%  |
| Read the job log              | 1     | 28,490       | $0.061 | 8.4%  |
| Read the spec and page object | 1     | 38,775       | $0.084 | 12%   |
| Patch and rerun the test      | 4     | 193,160      | $0.439 | 60%   |
| Write the PR comment          | 1     | 56,595       | $0.123 | 17%   |

| Input: fixed prefix    | $0.106 |
| Input: re-sent history | $0.458 |
| Input: new per step    | $0.086 |
| Output                 | $0.078 |
```

The patch loop carries 60% of the cost while adding 10,000 of the run's 39,300 new input tokens. Its four calls are expensive because they arrive late, after the job log and the spec are already in the conversation.

## Input per call climbs from 7,500 to 51,450 tokens

The per-call table, abridged, shows the mechanism directly. Each later call sends the prefix, every earlier input and output, and its own new input:

```
#  Step                           History  Total input  Cost
1  Read the failure summary             0        7,500  $0.021
2  Read the job log                 1,900       25,900  $0.061
3  Read the spec and page object   20,250       35,250  $0.084
4  Patch and rerun the test        29,850       38,350  $0.098
5  Patch and rerun the test (2)    33,550       42,050  $0.106
6  Patch and rerun the test (3)    37,250       45,750  $0.114
7  Patch and rerun the test (4)    40,950       49,450  $0.122
8  Write the PR comment            44,650       51,450  $0.123
```

The 18,000-token job log is paid for seven times: once when it arrives and once in each of the six calls after it. A step's cost depends on its position in the run as much as on its size, and that is why history grows with the square of the call count. A loop of n calls that each add s tokens re-sends s × n(n − 1) / 2 tokens of history, so doubling the patch attempts more than doubles what the loop costs. At eight attempts instead of four, the loop goes from $0.439 to $1.01 a run, and the run from $0.728 to $1.33.

Moving the history to the server does not change this. OpenAI's conversation-state guide says that even with `previous_response_id`, "all previous input tokens for responses in the chain are billed as input tokens". The client sends less; the bill is the same.

## Caching cut the month from $961 to $424

On Anthropic's API, automatic caching is one top-level field. The breakpoint moves to the last cacheable block as the conversation grows, so every call reads what the previous call wrote:

```
response = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=2048,
    cache_control={"type": "ephemeral"},   # 5-minute cache, written at 1.25x input
    system=SYSTEM_PROMPT,
    tools=TOOLS,
    messages=history,
)
```

Anthropic's caching guide spells out what a multi-turn request pays for: the system prompt through the previous user turn is read from cache, and the previous assistant reply plus the new user turn are written. A read on Sonnet 5.5 costs $0.20 per million tokens, a tenth of the input price, and a write costs $2.50. The estimator prices each call the same way, with a hit rate for the share of the previously sent part that is actually read. At 90%, the same run comes to $0.321, or $423.60 a month. The re-sent history drops from $0.458 to $0.113 per run.

Two lines of the new breakdown barely improve or get worse, and both are the write premium. New input per step rises from $0.086 to $0.108, because new tokens are now written at 1.25 times the input price. The job-log step barely moves, from $0.061 to $0.058: its 18,000 tokens are written once, and the saving only appears in the six calls that read them afterwards. Caching pays for content that is reused, so a step with a large new input and few calls after it gains nothing.

The hit rate is the number to be honest about. The same run costs $757.89 a month at a 50% hit rate, and $1,176 at 0%, which is more than not caching at all, because every token is then written at 1.25 times input and never read. Three things push a real agent toward that end:

- The cache lives five minutes, refreshed each time it is read. "Patch and rerun the test" waits for a test run between calls, and a rerun that takes longer than five minutes returns to an expired cache. Anthropic's one-hour cache writes at twice the input price; overriding the write price to $4 gives $577.09 a month at the same 90% hit rate, still well under the uncached $961.08.

- A prompt shorter than the model's minimum is not cached, and Anthropic says no error is returned. The minimum is 512 tokens on Sonnet 5.5 and 4,096 on Haiku 4.5, so moving a lean agent to the cheaper model can quietly switch caching off for every call under 4,096 tokens. The only sign is that `cache_creation_input_tokens` and `cache_read_input_tokens` are both 0.

- The cache lookup checks at most 20 content blocks back from a breakpoint. If the conversation moves the breakpoint 20 or more blocks past the last write, the next call misses. A run of consecutive tool results counts as one block, so parallel tool calls alone do not cause it; long interleaved turns can.

Measure the hit rate rather than assuming one. Anthropic's `input_tokens` counts only the tokens after the last breakpoint, and the guide gives the total as the sum of three fields:

```
def cache_hit_rate(usages):
    """Share of input tokens read from cache across a run's responses."""
    read = sum(u.cache_read_input_tokens for u in usages)
    total = sum(u.cache_read_input_tokens + u.cache_creation_input_tokens + u.input_tokens
                for u in usages)
    return read / total if total else 0.0
```

That ratio is over all input, while the estimator's hit rate is over the part an earlier request already sent. For this run, a 90% estimator setting corresponds to 247,748 of 325,270 input tokens read from cache, or 76% by the formula above. Compare like with like before trusting either figure.

## Summarising looked cheaper until the summariser was priced

The other common fix replaces the history with a summary. With a 3,000-token summary in place of the history from the third call on, the estimator reports $413.67 a month, a little under caching. Combined with caching, it reports $347.23. [Open the summarised and cached scenario in the estimator](https://automationtester.in/tools/agent-cost-estimator#p=eyJ2IjoxLCJpbnB1dCI6IntcIm1vZGVsSWRcIjpcImNsYXVkZS1zb25uZXQtNS01XCIsXCJvdmVycmlkZXNcIjp7fSxcImJhdGNoXCI6ZmFsc2UsXCJmaXhlZFByZWZpeFwiOjYwMDAsXCJzdGVwc1wiOlt7XCJsYWJlbFwiOlwiUmVhZCB0aGUgZmFpbHVyZSBzdW1tYXJ5XCIsXCJpbnB1dFwiOjE1MDAsXCJvdXRwdXRcIjo0MDAsXCJ0b29sQ2FsbHNcIjoxLFwicmVwZWF0XCI6MX0se1wibGFiZWxcIjpcIlJlYWQgdGhlIGpvYiBsb2dcIixcImlucHV0XCI6MTgwMDAsXCJvdXRwdXRcIjozNTAsXCJ0b29sQ2FsbHNcIjoyLFwicmVwZWF0XCI6MX0se1wibGFiZWxcIjpcIlJlYWQgdGhlIHNwZWMgYW5kIHBhZ2Ugb2JqZWN0XCIsXCJpbnB1dFwiOjkwMDAsXCJvdXRwdXRcIjo2MDAsXCJ0b29sQ2FsbHNcIjoxLFwicmVwZWF0XCI6MX0se1wibGFiZWxcIjpcIlBhdGNoIGFuZCByZXJ1biB0aGUgdGVzdFwiLFwiaW5wdXRcIjoyNTAwLFwib3V0cHV0XCI6MTIwMCxcInRvb2xDYWxsc1wiOjIsXCJyZXBlYXRcIjo0fSx7XCJsYWJlbFwiOlwiV3JpdGUgdGhlIFBSIGNvbW1lbnRcIixcImlucHV0XCI6ODAwLFwib3V0cHV0XCI6OTAwLFwidG9vbENhbGxzXCI6MCxcInJlcGVhdFwiOjF9XSxcImhpc3RvcnlcIjpcInN1bW1hcnlcIixcInN1bW1hcnlUb2tlbnNcIjozMDAwLFwiY2FjaGluZ1wiOnRydWUsXCJjYWNoZUhpdFJhdGVcIjo5MCxcInJldHJ5UmF0ZVwiOjEwLFwidG9vbENhbGxQcmljZVwiOjAsXCJ2b2x1bWVNb2RlXCI6XCJjaVwiLFwicnVuc1BlckRheVwiOjUwLFwicnVuc1BlclByXCI6MixcInByc1BlckRheVwiOjMwLFwiZGF5c1Blck1vbnRoXCI6MjJ9In0) to see that breakdown.

Neither number includes the calls that write the summary. A summary has to absorb each new step, or the patch loop forgets its last attempt, so it is rewritten six times per run: once from the first two calls, once to fold in the spec, and once after each patch. Priced as its own scenario on Claude Haiku 4.5 ($1 input, $5 output), with no history and the same 10% retries and volume:

```
Summariser: Haiku 4.5, 500-token prefix, history not re-sent
Step                         New input  Output  Times per run
Summarise calls 1 and 2         20,250   3,000              1
Fold in the spec read           12,600   3,000              1
Fold in a patch attempt          6,700   3,000              4

Per run (6 model calls)    $0.168
Per month (1,320 runs)     $221.65
```

Added back, summarising alone costs $635.32 a month and summarising with caching costs $568.88, both above the $423.60 that caching alone gets to. The summariser's output is the larger part: 3,000 tokens at $5 per million, six times a run, is 59% of its cost. Summaries also lose detail, and a triage agent that forgets which locator it tried two attempts ago is likely to try it again.

Summarising wins in a different shape of run: a long history that later steps barely use, a summary written once rather than after every step, or a conversation that would otherwise cross a long-context price tier. On this agent, with a short loop over material it keeps needing, it does not.

## The same run on other price lists

With caching at a 90% hit rate and everything else unchanged, the estimator gives these monthly figures, at list prices checked on 6 October 2026:

```
Model                  Input  Cache read  Output   Per month
Claude Sonnet 5.5      $2.00     $0.20    $10.00    $423.60
GPT-6.1 Sol            $2.00     $0.10    $10.00    $390.89
Claude Haiku 4.5       $1.00     $0.10     $5.00    $211.80
Gemini 3.8 Flash       $0.75     $0.075    $3.75    $139.66
```

Sonnet 5.5 and GPT-6.1 Sol have the same input and output prices, and without caching they produce the same $961.08. With caching they differ by $32.71 a month, entirely because OpenAI bills a cache read on Sol at 0.05 times input and Anthropic bills Sonnet 5.5 at 0.1 times. On an agent dominated by re-sent history, the cache-read price is the one to compare.

Three cautions apply to this table. The Gemini 3.8 Flash prices are promotional: Google lists them through 31 December 2026, then $1.50 input, $0.15 cached and $7.50 output, which doubles that row. The token counts are not portable either. Anthropic's pricing page says Claude 4.7 and later models use a tokenizer that produces about 30% more tokens for the same text, so counts measured on one model family are an approximation on another. And a cheaper model is only cheaper if it can still fix the test; run the same failures through both before switching, for example as cases built with the [LLM Eval Test-Case Builder](https://automationtester.in/tools/llm-eval-case-builder).

Batch pricing halves the bill on paper, to $480.54 on Sonnet 5.5, and does not apply here. Anthropic says most batches finish in less than an hour, and OpenAI's batch window is 24 hours. An agent whose next call needs the previous answer cannot wait for either. The estimator says so when batch rates are switched on for a multi-step loop.

## Where the estimate stops being right

The arithmetic is exact; the inputs are not. The largest error is usually the hit rate, which the estimator applies to every call alike. A run whose loop crosses the cache lifetime on some iterations and not others falls between two scenarios, so price both.

Retries are billed at the full cost of the first attempt. With caching, a retried call reads more of its input from cache than the original did, so the estimate is slightly high there. Retries caused by a tool timing out cost wall-clock time rather than tokens unless the model is called again; when they do re-call the model, [testing API idempotency, retries and timeouts](https://automationtester.in/blog/automation-tutorials/test-api-idempotency-retries-timeouts) covers making sure the retried tool call is safe before paying for it twice.

Long-context tiers are applied per call. OpenAI prices a request with more than 272,000 input tokens at twice the input and cache rates and 1.5 times the output rate for the whole request; Gemini 3.1 Pro switches tier above 200,000. A loop whose history crosses the line midway pays the higher rate on every call after it. Overriding any price turns the tiers off, since a negotiated rate replaces the list price at every size.

The price table carries the date it was read, and the page shows a visible warning once that date is more than 30 days behind the reader's clock. Output prices include reasoning or thinking tokens, which Google states on its pricing page and which a step's output estimate should include.

## Questions about pricing an agent run

**Where should the token counts come from?** From a recorded run. The [Agent Trace Viewer](https://automationtester.in/tools/agent-trace-viewer) shows input and output tokens for each model call in an OpenTelemetry trace, and its JSON export can be pasted into the estimator, which works out each step's new input from the growth between calls.

**Does a provider-side conversation store avoid paying for history?** Not at OpenAI, which bills every earlier input token in a `previous_response_id` chain as input. Check the provider's statement for any other store before assuming it does.

**Why does caching make new input more expensive per token?** Because a write costs 1.25 times input on Anthropic's five-minute cache and on OpenAI's GPT-5.6 and later models. Google's pricing page lists no write price for implicit caching, only a cached-token price and an hourly storage price for explicit caches, so the estimator prices Gemini writes at the input rate.

**Is a monthly figure from list prices what the invoice will say?** Only for the token charges. Data residency, regional endpoints and server-side tools such as web search are priced separately. The estimator takes a per-call fee for those tools, and the regional multipliers belong in a price override.

## Apply this now

Take one real run of your agent, from a trace or from the API's usage fields, and enter it as steps with its prefix, new input and output per call. Read two numbers from the estimate: the share of cost labelled re-sent history, and the share of the costliest step. If history is above a third of the run, switch on caching and check the monthly figure at 50% and at 90% hit rates; if the gap between them is large, measure your real hit rate with the three usage fields before committing. If a loop step waits on something slower than the cache lifetime, price the one-hour cache too. Price any summarising scheme together with the calls that write the summary, and record the date of the prices you used next to the figure.

## Pricing and caching references

- [Anthropic: pricing](https://platform.claude.com/docs/en/about-claude/pricing): per-model input, output, cache write and cache hit prices, the 1.25x and 2x write multipliers, the 0.05x read on Opus 5.5, the 50% batch discount stacking with caching, tool definitions billed as input, and the newer tokenizer's roughly 30% more tokens. Checked 6 October 2026.

- [Anthropic: prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching): automatic caching, the multi-turn read and write pattern, per-model minimum lengths with no error below them, the 20-block lookback, the five-minute lifetime refreshed on use, and the three usage fields.

- [Anthropic: batch processing](https://platform.claude.com/docs/en/build-with-claude/batch-processing): asynchronous processing, with most batches finishing in less than an hour.

- [OpenAI: API pricing](https://developers.openai.com/api/docs/pricing): GPT-6.1 Sol and GPT-6 Astra and Luna standard, batch, cached-input and cache-write prices, short and long context. Checked 6 October 2026.

- [OpenAI: GPT-6.1 Sol model page](https://developers.openai.com/api/docs/models/gpt-6.1-sol): prompts above 272K input tokens priced at 2x input and cache rates and 1.5x output for the full request.

- [OpenAI: prompt caching](https://developers.openai.com/api/docs/guides/prompt-caching): cache writes at 1.25x and reads at 0.1x (0.05x on GPT-6.1 Sol) for GPT-5.6 and later, and the 1,024-token minimum.

- [OpenAI: conversation state](https://developers.openai.com/api/docs/guides/conversation-state): earlier input in a `previous_response_id` chain is billed as input.

- [OpenAI: Batch API](https://developers.openai.com/api/docs/guides/batch): 50% discount and a 24-hour completion window.

- [Google: Gemini API pricing](https://ai.google.dev/gemini-api/docs/pricing): Gemini 3.8 Flash promotional prices through 31 December 2026 and the prices after, Gemini 3.1 Pro's 200K tier, batch prices, and output prices including thinking tokens. Checked 6 October 2026.

- [Google: context caching](https://ai.google.dev/gemini-api/docs/caching): implicit caching on by default for Gemini 2.5 and newer, and the 4,096-token minimum for current Gemini 3 models.

- [AutomationTester.in Agent Cost-per-Run Estimator](https://automationtester.in/tools/agent-cost-estimator): the sample scenario, breakdowns and dated price table used above.

## Continue reading on AutomationTester.in

- [CLIProxyAPI Session Affinity: What the Logs Prove and What They Don't](https://automationtester.in/blog/ai-in-testing/cliproxyapi-session-affinity-what-logs-prove)
- [Find the Tool Call That Dominates an Agent Run's OpenTelemetry Trace](https://automationtester.in/blog/tools-reviews/find-tool-call-dominating-agent-trace)
- [Gate an MCP Server and Client on the Official Conformance Suite](https://automationtester.in/blog/ai-in-testing/mcp-conformance-framework-ci)
- [Check MCP Tool Schemas Before an Agent Calls Them](https://automationtester.in/blog/tools-reviews/check-mcp-tool-schemas-before-agents-call-them)
- [Playwright MCP Is Not Your Regression Test Suite](https://automationtester.in/blog/ai-in-testing/playwright-mcp-vs-regression-test-suite)

Source: [Price an AI Agent's CI Runs Before the Monthly Bill Does](https://automationtester.in/blog/tools-reviews/price-ai-agent-ci-runs-before-the-bill) by Shashank Rawlani.
