By Greg Nowak.
An AI workflow can extract the fields from an invoice in seconds. If someone still has to fix the vendor name, rerun the extraction and check that the invoice made it into the accounting system, those seconds tell you very little about the cost. Before you scale the workflow, measure what you spend to deliver work your team can actually use.
How to calculate cost per completed task
Choose one workflow and agree with the person who owns it on what counts as finished. An invoice might count when its required fields pass validation and the record is saved in the accounting system. A draft might count when the client’s editor approves it. Count each accepted task once, even if it took several model calls or a manual correction. Track which tasks needed that correction.
API cost per completed task = all API spend for the tasks you’re measuring ÷ the number of those tasks accepted.
For example, if 100 invoices enter the workflow, 80 are accepted and API charges total €40, the API cost is €0.50 per completed invoice. If review and corrections cost €60 and allocated tool and hosting costs add €20, the operating cost is €1.50 per completed invoice. Include charges from retries and rejected work in the same group. Keep pending tasks visible and give each group the same amount of time to finish before you compare results. If zero tasks finish, show the spend and completion count and leave the unit cost blank.
Connect API spend to the work your team accepts
Assign a task ID at intake and carry it through every attempt, model call and tool step. Log the gateway or provider request ID for each call. Record retry reasons, review minutes, final status and delivery time against the task ID. For an agency running several client workflows, also record the client and workflow so you can allocate a shared API bill.
If you use LiteLLM, pass a workflow label via metadata.tags and look for it under request_tags in the spend logs. Join request costs to task outcomes in your application. Reconcile the logs with the provider’s usage and billing for the same period. If they differ, check for missing requests, cache token categories and model or tier pricing. LiteLLM request tags · LiteLLM spend tracking
Test the change that matches the cost you see
Trace a few clean completions and a few expensive ones before changing the model. If correcting one field reruns the entire invoice, test rerunning that step alone and check that retries cannot create duplicate records. If you change a prompt, model or effort setting, keep the acceptance checks the same and compare similar work.
| What you see | First test | What to measure |
|---|---|---|
| The same reference material goes out with most requests | Cache the shared prompt prefix | Input spend, including cache writes and reads |
| A queue of work can wait | Move it to asynchronous batches | Cost per accepted result delivered by the deadline |
| Validation errors trigger full reruns | Retry only the failed step | Attempts and review minutes per accepted task |
| A few jobs account for much of the spend | Set per-task retry or spending limits | Spend on stopped work and time to resolve it |
Cache repeated context
With Claude’s Messages API, put stable instructions and reference material first. Set cache_control on the last shared block, then add the task-specific content. Check the model’s minimum cacheable length and log cache_creation_input_tokens and cache_read_input_tokens across busy and quiet periods. Five-minute cache writes cost 1.25 times the base input rate and one-hour writes cost twice that rate. Read rates vary by model. Test the expiry window that fits how often requests reuse the same content and compare total input spend with your uncached baseline. Claude prompt caching docs
Batch work with a flexible deadline
Claude’s Message Batches API charges half the standard input and output token rates. Anthropic says most batches finish within an hour, and unfinished processing expires after 24 hours. For scheduled work such as overnight document classification, map each request’s custom_id back to its task, validate returned outputs and leave time to handle expired requests before delivery is due. Batch discounts can combine with cache pricing. Measure actual cache reuse because batch cache hits are best effort. Claude batch processing docs
Check what happens when the budget runs out
In LiteLLM, spend budgets require a connected database. For team keys, use a team budget and any team-member limits you need. Test with a small allowance using the same key type and routing as production. Confirm which limit blocks a request and check that automatic retries and fallback routes respect the stop. Give stopped tasks a visible status and an owner who can resolve or resume them after the budget resets or is raised. LiteLLM budgets and rate limits
Decide whether the workflow is ready to scale
Put API and operating cost per completion next to the acceptance rate, review time, on-time delivery rate and failed or pending counts. Compare those figures with your baseline and factor in what the change will cost to implement and maintain. A lower API bill can be outweighed by extra time in the review queue, especially when a pilot becomes a daily process.
If you have a workflow in mind, talk to Greg about an AI workflow cost audit. Bring a recent API bill and an example of a task your team accepted. Greg can help connect those records, measure the baseline and work out which change is worth testing first.
Related on GrN.dk
- AI automations need a spend dashboard before the first runaway bill
- When AI writes JSON, one bad field can break the workflow
- Prompt Cache Write Costs: Check What Your Workflow Actually Reuses
Need help with this kind of work?
Talk to Greg about an AI workflow cost audit Get in touch with Greg.