← Field notes

October 12, 2026 · Michael Rodriguez

API Cost Per Task for a Simple Agent: How to Measure It
Build in public

API Cost Per Task for a Simple Agent: How to Measure It

Learn how to calculate API cost per task for a simple AI agent, what drives that number, and how to track it with ledger-level precision.


The short answer

API cost per task for a simple agent is the total token spend (prompt tokens plus completion tokens) across every LLM call made to finish one discrete unit of work, converted to dollars at the provider's published rate. For a single-step agent doing something like classifying an email or drafting a short reply, that number typically lands between a fraction of a cent and a few cents depending on the model chosen. You measure it by logging every API response object, summing the token counts, and multiplying by the per-token price. Doing this at the task level rather than the session level is what turns a vague cost estimate into a real ledger entry.

Definition

Cost Per Task: The total dollar amount charged by an LLM provider to complete one defined unit of agent work, calculated as the sum of all prompt and completion tokens consumed across every API call in that task, multiplied by the provider's published per-token rate.

Why does cost per task matter more than cost per month?

Monthly bills tell you what you spent; cost per task tells you whether the unit economics work. If you are building an agent that handles customer support tickets, a monthly bill of 400 dollars means nothing until you know you processed 8,000 tickets and each one cost about 5 cents. That ratio is the number that decides whether the product is viable.

Note

Track cost at the task boundary, not the session or the calendar month. A task has a clear start and a clear end; a session and a month are accounting conveniences that obscure what you actually need to know.
Diagram of a simple agent loop showing prompt construction, LLM call, and token count logging at each step

What tokens actually make up the cost?

Every LLM call returns a usage object. OpenAI's API, for example, returns prompt_tokens, completion_tokens, and total_tokens in every response. The cost formula is straightforward.

For GPT-4o as of mid-2025, OpenAI publishes input tokens at 2.50 dollars per million and output tokens at 10.00 dollars per million. A task that uses 1,200 prompt tokens and 300 completion tokens costs:

  • Prompt: 1,200 divided by 1,000,000 multiplied by 2.50 = 0.003 dollars
  • Completion: 300 divided by 1,000,000 multiplied by 10.00 = 0.003 dollars
  • Task total: 0.006 dollars, or about six-tenths of a cent

For a simpler model like GPT-4o mini, those same token counts cost roughly ten times less. The model choice is the single largest lever on unit cost.

10xApproximate cost difference between GPT-4o and GPT-4o mini for the same token count

Source: OpenAI Pricing Page, 2025

How do you instrument a task to capture cost?

The measurement pattern is the same regardless of framework or model provider.

Open a task context object with a unique task ID
Make each LLM call and append the usage object to the context
After the final call, sum prompt_tokens and completion_tokens across all calls
Multiply totals by per-token rates from the provider's pricing page
Write the final cost record to your data store with the task ID as the key
Five-step pattern for logging cost per task in any agent

Here is what to log at minimum for each task:

  • task_id: a UUID you assign before the first API call
  • model: the exact model string from the response, not what you think you called
  • prompt_tokens_total: summed across all calls in the task
  • completion_tokens_total: summed across all calls in the task
  • cost_usd: calculated at log time using current published rates
  • task_type: a label like "classify", "draft", or "extract" so you can group later
  • timestamp_start and timestamp_end: so you can correlate cost with latency

Logging the model string from the response rather than from your config catches the case where a framework silently falls back to a different model on rate-limit errors, which is a real source of billing surprises.

What drives cost up in a simple agent?

Four things move the number in practice:

System prompt length. A 2,000-token system prompt that gets prepended to every call is 2,000 tokens of input cost on every single API request. For a multi-step agent making five calls per task, that is 10,000 tokens of overhead before the agent does anything useful. Trimming a bloated system prompt is usually the fastest cost reduction available.

Retry loops. If your agent retries a failed parse or a tool call error, each retry is a full additional API call with a full prompt. Log retries separately so you can see which task types generate them.

Context window carry-forward. Agents that append the full conversation history to every call pay compounding prompt costs. A task that runs four turns and appends all prior turns to each call has turn costs of 1x, 2x, 3x, and 4x the base context size.

Output verbosity. Asking the model to "explain your reasoning" or "show your work" generates completion tokens. Those tokens cost money. Strip them from production prompts if you only need the final answer.

The system prompt is the fixed cost of every API call. Every token you trim from it is a discount that applies to your entire task volume, not just one call.
Bar chart diagram comparing token costs from system prompt overhead, retries, context carry-forward, and verbose outputs across a sample task

How do you benchmark cost across models?

The only honest benchmark is a fixed eval set of real tasks from your own workload. Pick 50 to 100 representative tasks, run them through each candidate model with identical prompts, log the token counts and outputs, then calculate cost and quality side by side.

Published benchmarks like MMLU or HumanEval tell you something about general capability, but they do not tell you how a model performs on your specific task distribution or what that performance costs at your volume. Your own eval set is the only number that is relevant to your ledger.

For reference on where to find published model pricing to populate your calculations, OpenAI maintains a pricing page at openai.com/api/pricing, and Anthropic publishes Claude pricing at anthropic.com/pricing. Both update periodically, so pin the version date when you record rates in your logs.

What does a realistic cost range look like for simple tasks?

These are illustrative ranges based on published token rates, not guarantees of what you will see. Actual costs depend on your prompt design, retry rate, and context management.

| Task Type | Typical Token Range | Approximate Cost on GPT-4o mini | |---|---|---| | Single-label classification | 500 to 800 total tokens | 0.01 to 0.02 cents | | Short reply draft, under 100 words | 800 to 1,500 total tokens | 0.02 to 0.04 cents | | Structured data extraction, one record | 1,000 to 2,000 total tokens | 0.02 to 0.05 cents | | Multi-step reasoning with tool call | 3,000 to 8,000 total tokens | 0.06 to 0.16 cents |

These figures use GPT-4o mini input pricing of 0.15 dollars per million tokens and output pricing of 0.60 dollars per million tokens as published by OpenAI in 2025.

Cost per task is a four-part formula: count prompt tokens, count completion tokens, multiply each by the published per-token rate, and sum them. Instrument every API call to capture the usage object, aggregate at the task boundary, and you have a real ledger entry instead of a guess.

If you are building toward a multi-agent architecture, the same measurement pattern applies at every agent boundary. Start with single-agent instrumentation so the habit is in place before the system gets complex. For a deeper look at how multiple agents share a task and split costs, see the 10 Agents framework overview and the agent cost architecture post.

Michael Rodriguez

Michael Rodriguez has spent 20 years on a dealership floor. With no tech background, he built and runs 22 production AI agents across four businesses on less than $50 a month, in evenings and lunch breaks. Agent Empire is where he ships it in public.

Building agents around a day job? Agent Empire is where operators ship it in public, together. Come build with us.