Jump straight to the numbers

← All articles

$0.18 for a CI Agent Run, With a $0.50 Ceiling

01 / A $0.18 receipt, not an unlimited agent tab

A coding agent that fixes a failing test can be useful. An agent that rereads the repository, retries six times, and leaves no usable patch is just another CI bill. Give it a dollar ceiling before giving it a shell.

Consider a pipeline with a $0.50 AI allowance. The following receipt is a worked planning example, not a measured benchmark or a CheapRelay price quote. Its rates are illustrative; replace them with the current rates for your chosen model before enabling the job.

  • ■ Uncached input: 120,000 tokens at $0.50 per million = $0.060.
  • ■ Cache writes: 40,000 tokens at $0.625 per million = $0.025.
  • ■ Cache reads: 300,000 tokens at $0.05 per million = $0.015.
  • ■ Output: 40,000 tokens at $2.00 per million = $0.080.
  • ■ Total AI API charge: $0.180.

Those quantities cover the entire hypothetical run, including retries, not one request. They use separate billing categories: the cache-write rate here is assumed to be the complete charge for those tokens, not a surcharge. Confirm your provider's accounting rules before copying the formula.

02 / Split the $0.50 ceiling into $0.40 working money and $0.10 protection

Set the admission threshold at $0.40 and keep $0.10 unallocated. After the example run spends $0.18, it has $0.22 of working budget left, plus the protected $0.10. Unused allowance is not a reason to keep iterating.

The protection margin is not a substitute for enforcement. It cushions rounding and small accounting differences. If request size, billing behavior, or hidden usage cannot be bounded, a client-side counter alone cannot promise a hard ceiling. Use an upstream spending limit where available, or fail closed until the uncertainty is resolved.

Define the scope carefully: this ceiling covers AI API charges only. Runner minutes, storage, network charges, and third-party tools need separate budgets. A cheap model call can still launch an expensive test suite.

03 / Reserve $0.016 before admitting the next request

Put a budget gateway between the agent and the API. For every request, reserve its maximum plausible cost before sending it. Include the full submitted context, maximum output, applicable cache charges, and any separately billed reasoning tokens.

Using the illustrative rates above, a request bounded to 12,000 input tokens and 4,000 output tokens costs at most $0.0155 if all input is charged at the $0.625 cache-write rate. Round that reservation up to $0.016. This bound only holds if those are genuinely the highest applicable rates and all billable token categories are covered.

  • ■ Admission rule: settled spend + outstanding reservations + new reservation must not exceed $0.40.
  • ■ Concurrency example: $0.31 settled + five $0.016 reservations = $0.39 committed.
  • ■ One more $0.016 request would reach $0.406, so reject it.

Make that check atomic. Otherwise, parallel workers can all see the same remaining balance and overspend together. Reconcile each reservation against returned usage. If a timeout leaves billing uncertain, retain the reservation until resolved; do not release it merely because the client received no answer.

04 / Stop retry loops before they consume the allowance

Use behavioral limits alongside the dollar ledger: one initial repair attempt, at most two additional attempts, bounded tool output, and a fixed job timeout. These are policy choices, not claims about an optimal retry count.

Every new API attempt needs its own reservation, including automatic SDK retries. Disable retries you cannot observe. Persist the ledger across job restarts, keyed to the pipeline run, so restarting a failed job does not silently reset its allowance.

05 / Print the receipt beside the patch

CheapRelay fits this setup as a pay-as-you-go API relay with no monthly fee or subscription. Billing follows real token usage, including cache reads and writes. Its OpenAI-compatible API base is https://api.cheapapirelay.com/v1; enforce the run budget in your gateway rather than assuming the endpoint applies your policy.

Sign up for CheapRelay, select a model, and populate the ledger with its current rates before your first capped run.

Publish the final token categories, dollar total, retry count, and stop reason as a CI artifact. The useful result is not merely “agent finished.” It is “patch produced, tests checked, $0.18 spent, $0.50 ceiling respected.”

Sign up Try the prices yourself, sign-up credit included.

More reading

DateAisleWritten inTitle
2026-10-27Coding agents, cheaplyENThe $5 Claude Code Setup Uses Two Environment Variables
Point Claude Code at CheapRelay with two variables, cap a tiny pay-as-you-go budget, and verify the first request without a subscription.
2026-10-27Coding agents, cheaplyEN$2 a Day for Claude Code: A Budget, Not a Promise
A beginner’s walkthrough for keeping Claude Code spending predictable with small tasks, token checks and a $2 daily planning limit.
2026-10-27Coding agents, cheaplyEN$1.00 for a $0.50 Coding Job
An illustrative coding-assistant receipt shows how repeated context, noisy logs, long answers and blind retries turn a $0.50 task into $1.00.
2026-10-27Coding agents, cheaplyENYour Input Bill: 90,000 Tokens From One File
A troubleshooting FAQ for coding agents: cut repeated files, noisy tool output and stale history without starving the agent of useful context.
2026-10-27Coding agents, cheaplyEN$0.192 for a coding session, not $0.480
A worked API receipt for cheap-first pair programming, with explicit assumptions, escalation limits, and a fair cost comparison.
2026-10-27Coding agents, cheaplyEN$0.18 for a Codex Task, $0.62 for a Wandering Session
An illustrative Codex receipt shows how narrow tasks, smaller context and fewer retries can cut token costs without hiding cache charges.