COST OPTIMIZATION

Cut LLM API costs per finished task, not just per token

LLM API cost optimization comes down to two numbers: the price per token and the tokens a task uses before it’s done. Measure both before you change how your coding agent works.

Pick a task with a clear pass or fail

Choose a task you can accept or reject: a patch that passes tests, a reviewed migration or a resolved issue. Record every API attempt needed to finish it, including failed attempts.

RecordWhy it matters
Total billed tokens by categoryShows where the API spend went
Accepted tasksGives the denominator for cost per completed task
Retries and extra turnsReveals work that did not finish on the first attempt
Manual repairCaptures time a token-only comparison misses

Change one thing per run

Run the same accepted task before and after changing context, retries or the model. Keep the repository revision, instructions and acceptance test fixed. Use this local worksheet for each run; leave unknown values blank instead of estimating a result.

csv
run_id,client_version,model_id,repo_revision,accepted,requests,retries,uncached_input_tokens,output_tokens,cache_read_tokens,cache_write_tokens,billed_usd,manual_repair_minutes
baseline,,,,,,,,,,,,
changed,,,,,,,,,,,,

Trim context the model doesn’t need

Send the files, instructions and tool output the task needs. Remove repeated logs and irrelevant repository content. Change one input at a time so you can see whether a smaller context still produces an acceptable result.

Cap retries and stuck agent loops

Set a task budget and a retry ceiling in your application. Give the agent a clear stop condition. If the same error keeps returning, fix its cause before buying another attempt.

Count cache savings from your bill, not estimates

Separate uncached input, cache reads and cache writes where the selected model bills them separately. Compare the actual charged mix; a theoretical cache hit rate is not a saving.

Use each model’s actual multiplier

Compare the same task sample using the current Codimixa rates. Rates start at 0.3× official API pricing, while each model and billing category has its own multiplier. Keep the task definition constant when measuring the change.

Reconcile the worksheet with billed usage.

Sum the charges for every request in the task, including failed or repeated attempts that were billed. Divide the total by accepted tasks only when at least one task passed. A run with no accepted task is a failed trial, not a zero-cost success. Keep request IDs in your private records for reconciliation; do not share API keys, prompts or customer data.

FAQ

Common questions

Which cost should I track?

Track API cost per accepted task alongside token counts. This lets you see when a low token price is offset by repeated attempts or poor task completion.