CODING AGENT API COST GUIDE

Estimate the work before you optimize the bill.

A coding agent request is more than a prompt. Separate input, output, cached context, retries, and tool loops so your estimate can explain where the budget goes.

Built around a stable OpenAI-compatible request shape.

REQUEST LEDGERillustrative
route /v1$0.42
in prompt context18.4k
out model output2.1k
↺ cached context6.8k
latency windowyour data · your keys

A

coding agent can spend more on context than on the answer. It can retry a request, call a tool, or carry a large repository slice into every turn. A useful estimate starts with the work pattern, then applies the rate inputs.

THE BASIC MODEL

estimated cost = (input tokens ÷ 1,000,000 × input rate) + (output tokens ÷ 1,000,000 × output rate)

Add cache reads, cache writes, retries, and any provider-specific terms as separate lines when they apply.

STEP 01

Count the work you send

Measure representative requests rather than a single tiny prompt. Include system instructions, repository context, tool results, and the user task.

STEP 02

Count the work you receive

Output includes explanations, patches, structured tool calls, and the extra turns created when an agent checks its own work.

STEP 03

Separate retries

A timeout or rate limit can create a second request. Keep that traffic visible so reliability work does not look like a mysterious rate increase.

STEP 04

Compare completed tasks

Cost per request is a weak metric on its own. Track cost per successful change, reviewable patch, or completed migration.

Questions for your cost worksheet
QuestionEvidence
How much context repeats?Token counts by turn and cache behavior
How many tool loops finish?Request trace or client log
What counts as success?Tests, review outcome, or task completion
What changes after a route switch?Same task set, new model/config, comparable window

TRY YOUR NUMBERS

Use the planning calculator.

Replace the illustrative inputs with rates from the account catalog and a trace from your own workload.

Open pricing calculator →

WORKED EXAMPLE

Show the assumptions beside the total

This example is deliberately illustrative. Replace every number with values from your account catalog and a trace from your workload.

Illustrative request worksheet
VariableExampleCalculation
Input tokens18,00018,000 ÷ 1,000,000 × input rate
Output tokens2,2002,200 ÷ 1,000,000 × output rate
Cache termsNot includedAdd only when the provider publishes the unit
RetriesNot includedMultiply by observed attempts per task

Reduce repeated context

Trim instructions that do not change the task, scope repository context to the files the agent needs, and measure whether caching actually reduces the billed input path.

Reduce unproductive loops

Give tools clear schemas, add a stop condition, and make test output concise enough for the next turn to use.

Compare successful work

Track cost per accepted patch or completed migration. A cheap request that needs manual repair can cost more than a larger request that finishes cleanly.

Keep a change log

When a rate, model, prompt, or retry policy changes, write down the date and the reason. Otherwise a monthly total is hard to explain.

OPEN QUESTION

The right unit may be a completed engineering task

Token pricing is necessary for an estimate, but teams usually buy outcomes: a reviewed patch, a passing migration, or a resolved incident. Keep token math visible while you learn which task-level measure predicts value for your workflow.

That measure can change as the agent gains tools or the repository grows. Revisit it when the request shape changes.