LLM API Pricing Comparison: How to Calculate Cost Per Task
API pricingLLM costsmodel comparisonAI budgetingcloud AI

LLM API Pricing Comparison: How to Calculate Cost Per Task

PPromptCraft Lab Editorial Team
2026-11-30
7 min read

Learn how to compare LLM API costs per task by accounting for tokens, retries, caching, batch processing, tools, and long-context usage.

LLM API pricing is easy to underestimate because providers charge separately for input tokens, output tokens, caching, batch jobs, tools, and sometimes multimodal requests. This guide gives you a repeatable way to compare models, calculate cost per task, test production assumptions, and identify the cheapest option for your actual workload rather than relying on cost per million tokens alone.

Overview

The right question in an AI API pricing comparison is not simply “Which model has the lowest token price?” It is “Which model completes this task at the required quality, latency, reliability, and operational cost?” A less expensive model can become costly if it needs more retries, produces longer answers, requires extensive post-processing, or fails often enough to trigger human review.

Start by separating three measurements:

  • Unit price: the provider’s charge for a billing unit, commonly a million input tokens and a million output tokens.
  • Task cost: the estimated cost of one complete workflow, including prompts, outputs, retries, tool calls, and context.
  • Business cost: task cost plus storage, retrieval, monitoring, human review, engineering overhead, and other services.

Published rates change, model names are retired or replaced, and billing rules differ between providers. Treat any comparison table as a dated decision aid, not a permanent fact. Before deployment, verify the selected model’s current pricing page, billing unit, context limits, feature fees, and regional terms.

Pricing is only one part of an LLM comparison. For a practical selection process, pair this cost worksheet with a representative evaluation, such as the method described in How to Benchmark LLMs for Your Real-World Use Case.

How to estimate

Use this basic formula when a provider charges separately for input and output:

Cost per task = (input tokens ÷ 1,000,000 × input price) + (output tokens ÷ 1,000,000 × output price)

If your workload uses cached input, batch processing, tools, or multiple model calls, calculate each component separately:

Total task cost = standard input cost + cached input cost + output cost + tool or feature cost + retry cost

For a monthly forecast, multiply the average task cost by the number of completed tasks. Then add a contingency for retries and variance:

Monthly forecast = average task cost × monthly task volume × (1 + retry and variance rate)

Use a spreadsheet with one row per model and columns for:

  1. Model and provider.
  2. Input price per million tokens.
  3. Output price per million tokens.
  4. Average input tokens per task.
  5. Average output tokens per task.
  6. Cached or discounted input tokens.
  7. Expected retries.
  8. Tool, search, image, audio, or other feature charges.
  9. Estimated cost per task and per month.
  10. Quality, latency, and failure notes from your evaluation.

Keep input and output tokens separate. Many applications have a small user request but a large system prompt, retrieved document set, schema, or conversation history. Others have modest input but generate long reports. A single blended token estimate can hide the cost driver.

Inputs and assumptions

Token volume

Measure token usage from representative requests rather than guessing from word count. Sample short, typical, and unusually large requests. Include system instructions, conversation history, retrieved passages, tool definitions, structured output schemas, and any other content sent on every call.

For a retrieval-augmented generation workflow, estimate the retrieved context separately. A prompt that retrieves five passages today may retrieve more after a search configuration change. Record both the average and a high-percentile case so your forecast does not depend on an unrealistically small context.

Output length

Output tokens can vary substantially by task. Set an output limit where appropriate, but do not assume the limit is the average. Measure the actual distribution. A summarizer, classifier, extraction job, and coding assistant have different output profiles even when they use the same model.

Retries and fallbacks

Count calls that fail validation, time out, exceed a rate limit, or are sent to a fallback model. If a structured output parser rejects an answer and your application retries, that retry belongs in the cost model. A useful estimate is:

Retry cost = base task cost × expected number of additional attempts

Do not assume every retry has the same token volume. A fallback request may include a shorter prompt, while a repair request may include the original answer and error details.

Long context and caching

Long-context usage can dominate costs when a large document or conversation is repeatedly sent. Identify which tokens are fixed, which are dynamic, and which may qualify for a provider’s caching mechanism. Use the provider’s current rules for cache eligibility, minimums, duration, and read or write charges. If caching is unavailable or unreliable for your request pattern, model the standard input price instead.

Features beyond text

Tool calls, web retrieval, image inputs, audio, embeddings, storage, and batch execution may use different billing units. Put each feature on its own spreadsheet line. Do not fold an uncertain feature charge into the token price; label it as an assumption and confirm it before approval.

Worked examples

The following examples use hypothetical rates for demonstrating the method. They are not current provider prices or rankings.

Example 1: A short extraction task

Assume one task sends 12,000 input tokens and receives 2,000 output tokens. A hypothetical model charges $X per million input tokens and $Y per million output tokens.

The calculation is:

(12,000 ÷ 1,000,000 × X) + (2,000 ÷ 1,000,000 × Y)

If the application processes 100,000 tasks per month, multiply that result by 100,000. Then add the expected cost of validation failures and retries. This is more useful than comparing X and Y in isolation because it reflects the actual input-to-output ratio.

Example 2: Cached context

Suppose a support assistant sends a 50,000-token policy library on every request, but only 2,000 tokens change. Separate the fixed context from the dynamic prompt. If the provider offers a lower cached-input rate, calculate the fixed portion using that rate and the dynamic portion using the standard input rate. If 10% of calls miss the cache, model both paths:

  • Cache hit cost: cached fixed context + standard dynamic input + output.
  • Cache miss cost: standard fixed context + standard dynamic input + output.
  • Blended cost: cache hit cost × hit rate + cache miss cost × miss rate.

This blended result is safer than assuming perfect caching.

Example 3: Quality-adjusted comparison

Model A costs less per task but fails validation on 8% of requests. Model B costs more but fails on 2%. If each failed request triggers one additional call, calculate the expected retry cost for both models. Then compare the results against your quality threshold and review burden.

For production workflows, track cost alongside pass rate, latency, refusal rate, citation or extraction accuracy, and human escalation. The cheapest LLM API is not necessarily the cheapest system when failure handling is included. Prompt regression testing can help detect changes before they affect the forecast; see LLM Prompt Regression Testing: A Practical Test Suite for Production Apps.

When to recalculate

Recalculate your LLM API cost estimate whenever a provider changes input or output rates, introduces a new billing unit, modifies caching terms, retires a model, or changes the availability of batch and tool features. Also recalculate after an application change that affects prompt length, retrieval settings, output limits, retry logic, or model routing.

A monthly audit is a reasonable operating habit for active production systems. Review:

  • Actual input and output tokens versus forecast.
  • Average and worst-case context size.
  • Retry, fallback, and validation-failure rates.
  • Cache hit rate and feature usage.
  • Cost per successful task, not only cost per API call.
  • Quality and latency against the acceptance criteria.

Before your next architecture review, export a sample of real request logs, calculate the median and high-end token volumes, and rerun the worksheet for at least two viable models. Record the date, source pricing pages, model identifiers, assumptions, and exclusions. If a model is deprecated or its endpoint changes, consult the LLM Model Deprecation Guide before updating the forecast.

The result should be a living cost model: transparent enough for procurement, detailed enough for engineering, and easy to refresh when rates or workloads change.

Related Topics

#API pricing#LLM costs#model comparison#AI budgeting#cloud AI
P

PromptCraft Lab Editorial Team

AI Development Editors

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.