Estimating the cost of an AI API workflow means pricing every billable step in the pipeline, not just the final model call. The practical method is to map the workflow into steps, count input and output tokens for each step, apply verified unit prices including cached-input rates, add tool calls, retries and infrastructure, and then divide the total by the number of successful completions. That last figure — cost per successful workflow — is the number that predicts a real budget, because a cheap run that fails and retries can cost more than a slightly more expensive run that completes reliably.
This guide covers multi-step pipelines such as retrieval-augmented generation (RAG), content generation, code review agents and data extraction. It assumes you already have a pipeline that runs and that you want a defensible per-run and monthly number rather than a rough guess.
Why a per-call price list is not a cost estimate
A provider price list describes a unit cost per request: input tokens plus output tokens. A workflow is an aggregate of many such requests, plus the steps around them. AI workflow cost analysis is defined as measuring the aggregated cost of completing a full AI-driven task end to end, covering model calls, token types, cache events, tool calls, retrieval steps, retries, evaluation and infrastructure.
| Metric | Focus area | Primary calculation |
|---|---|---|
| Model API cost | Unit cost per request | Input tokens + output tokens |
| Workflow cost | Aggregate task cost | Sum of LLM calls + tool calls + retries + infrastructure |
| Cost per success | Business ROI metric | Total cost of all attempted runs ÷ number of successful completions |
The distinction matters because the metric that governs budget decisions is cost per successful workflow, not cost per API call. Dividing the total cost of all attempted runs by successful completions captures the cost of failures, which a per-call figure hides.
Step 1: Map the workflow into billable steps
Before any arithmetic, list the stages that touch a paid API. A workflow cost calculator models multi-step pipelines such as embed, retrieve/rerank, generate and validate, and ships presets for RAG pipelines, content pipelines, code review agents and data extraction. Each step in that model carries its own model, input token count, output token count and cached flag.
A typical RAG pipeline therefore has at least four billable stages: embedding the query, retrieving and reranking chunks, generating the answer, and validating the output. Retrieval itself may be free if it runs against your own index, but reranking and validation often call a model.
Step 2: Count tokens per step, including cache events
Token counting is the part most estimates get wrong, because the same text can be billed at different rates depending on whether it was read from a prompt cache. Workflow cost analysis tracks prompt cache reads and writes as distinct events rather than folding them into a single input-token number. The calculator exposes this directly: each step can be marked cached and priced at a cached-input rate rather than the standard input rate.
Practical counting rules: measure the actual prompt you send, not the text you think you send; include system prompts, retrieved chunks, few-shot examples and tool schemas; and record output tokens separately, because output is usually priced higher than input.
Step 3: Apply unit prices you can verify
Multiply input tokens by the input rate and output tokens by the output rate, per step, per million tokens. The calculator’s preset, for example, lists gpt-6-luna at $0.1 per million input tokens and $0.5 per million output tokens, with gpt-4.1-nano and claude-sonnet-5 as the other models in the same pipeline. Treat any rate you did not read from the provider’s own pricing page on the day you estimate as unverified: model names, tiers and rates change, and a stale rate silently invalidates the whole sheet.
Step 4: Add retries, tool calls and infrastructure
Workflow cost is the sum of LLM calls, tool calls, retries and infrastructure cost. Retries are the most commonly omitted line. A step that fails schema validation and is re-sent doubles that step’s cost; a step that fails three times quadruples it. Tool calls — search, database lookups, code execution, external APIs — carry their own price or quota. Infrastructure includes the retrieval index, queues, logging and any always-on service the workflow depends on.
Step 5: Divide by the success rate
Sum the cost of every attempted run, including the ones that failed, and divide by the number of successful completions. That is the cost per successful workflow. If a pipeline costs $0.01 per attempt and succeeds 70% of the time, the cost per success is roughly $0.0143, not $0.01. Keeping failure cost in the numerator is what makes the metric useful for ROI decisions.
A worked example
The following figures are the illustrative output of a public workflow cost calculator’s RAG preset, not a price quote for any provider. They show the shape of a completed estimate rather than a recommended configuration.
| # | Step | Model | Input | Output | Total |
|---|---|---|---|---|---|
| 1 | Embed query | gpt-6-luna | 200 | 0 | $0.000020 |
| 2 | Rerank chunks | gpt-4.1-nano | 4.0K | 200 | $0.00 |
| 3 | Generate answer (cached) | claude-sonnet-5 | 5.0K | 1.0K | $0.00 |
| Total per execution | $0.000020 | ||||
Batch projections from the same preset: at 100 executions per day the tool reports $0.0020 per day, $0.060 per month at 3,000 executions, and $0.730 per year at 36,500 executions. Note that the preset’s rerank and generate steps are marked cached and display $0.00, which is why the total is dominated by the embedding step. Re-running the same pipeline with uncached steps produces a different total; the point of the example is the method, not the number.
The calculator also produces a provider comparison that substitutes the cheapest model from a single provider across every step. In its output, Groq is listed at $0.0010 per execution, Anthropic and OpenAI at $0.0011, Qwen at $0.0013, Mistral at $0.0014, DeepSeek at $0.0027, Google at $0.0044, xAI at $0.0076 and Meta at $0.011. These are best-case cost figures for each provider, not quality-adjusted comparisons, and they differ from the current preset configuration — which is exactly why the tool labels them as a best-case view.
Where estimates break down
- Cache accounting. A cached step is cheaper, not free. Cache writes and cache reads are separate events, and a workflow that changes its prompt prefix on every run may never hit the cache at all.
- Retry amplification. Failure cost belongs in the numerator. A pipeline with a low success rate can be more expensive per completed task than a pricier pipeline that succeeds consistently.
- Token drift. Prompt edits, larger retrieved chunks, longer conversation history and added tool schemas all raise input tokens without any change to the code that calls the API.
- Price and version drift. Model identifiers and rates change. An estimate is only valid for the configuration and date it was measured.
- Best-case provider comparisons. Substituting one provider’s cheapest model across all steps answers a cost question, not a quality or latency question.
- Human review. Human-in-the-loop validation is part of the workflow lifecycle and belongs in the total cost of the task, even when it is not billed per token.
Making the estimate reproducible
- Instrument one real run and log input tokens, output tokens and cache events per step.
- Record the model identifier and the unit price you used, with the date you read it.
- Repeat the run at least a few times to see how much token counts vary between inputs.
- Track the success rate over a larger sample, including failed attempts and their retry cost.
- Compute cost per successful workflow and store the sheet alongside the prompt version it describes.
- Re-measure after any change to prompts, model choice, chunk size or retrieval settings.
Local models and WordPress-scheduled runs
If part of the pipeline runs on a local model, the marginal API cost for that step drops to near zero, but the total cost of ownership does not. Hardware, electricity, maintenance time and the engineering cost of keeping the runtime current belong in the same sheet, otherwise a local substitution looks free when it is only shifted.
If the workflow is triggered from WordPress — a scheduled post generator, an editorial triage hook, a webhook-driven content pipeline — the per-execution number is only half the estimate. Multiply it by the number of scheduled runs. The preset above turns $0.000020 per execution into $0.0020 per day at 100 runs, $0.060 per month at 3,000 runs and $0.730 per year at 36,500 runs. Automation schedules are where small per-run costs become visible.
What to do next
Build a one-page cost sheet for a single workflow: steps, models, token counts, unit prices with dates, retry allowance, and success rate. Compute cost per successful workflow from real logged runs before you compare providers or decide whether to move a step to a local model. If your numbers differ sharply from a calculator preset, share the pipeline configuration, token counts and observed per-run cost with the community so others can reproduce the comparison.
FAQ
What is cost per successful workflow?
It is the total cost of all attempted runs — including failed attempts and their retries — divided by the number of successful completions. It is the metric that reflects real budget impact, since a cheap run that fails and retries can cost more than a slightly more expensive run that completes reliably.
Does prompt caching make a step free?
No. Cached input is billed at a cached-input rate rather than the standard rate, and cache writes are counted as separate events. A calculator preset may display $0.00 for a cached step, but that reflects that preset's configuration rather than a general rule.
How do I turn a per-run estimate into a monthly budget?
Multiply the per-execution cost by the number of runs per day and then by the number of days. In one published preset, $0.000020 per execution becomes $0.0020 per day at 100 executions, $0.060 per month at 3,000 executions and $0.730 per year at 36,500 executions.
Is the cheapest provider always the cheapest workflow?
Not necessarily. Provider comparisons that substitute a single provider's cheapest model across every step produce a best-case cost figure and do not account for output quality, latency, retry rates or the cost of rewriting prompts for a different model.
Why do my token counts differ from a calculator preset?
Token counts depend on your actual prompt: system instructions, retrieved chunks, few-shot examples, tool schemas and conversation history. Presets use fixed example inputs, so they should be treated as a method demonstration rather than a prediction of your pipeline.