Skip to content
AI Product Engineer Wiki

    ↑ ↓ to move between results, Enter to open, Esc to close

    Menu

    Estimating cost per task

    Estimate what an AI feature costs per task and per successful task, from token counts and model prices to retries and caching, with a reusable cost calculator.

    Level: Intermediate 9 min read Updated
    On this page

    Why this matters

    Most software features cost almost nothing per extra use. AI features pay for every request, which means a feature can be popular and unprofitable at the same time. The worst time to discover that is after launch, when users depend on it and the invoice has arrived.

    The good news is that cost is one of the most predictable things about an AI feature. With a token count, a price and a few honest assumptions, you can estimate cost per task to the right order of magnitude before writing the feature. This article shows how, and how to turn cost per call into the number that matters: cost per successful task.

    Tokens in, tokens out

    Model APIs charge per token, separately for input and output. A token is a chunk of text, often part of a word. Output tokens cost more than input tokens, typically several times more.

    What drives each:

    • Input tokens: the system prompt, the user’s message, any documents or retrieved context, tool definitions, and the conversation history in multi-turn features. Context-heavy features are dominated by input.
    • Output tokens: the visible response, plus thinking. On models that reason before answering, thinking tokens are billed as output tokens, so effort settings affect cost as well as quality and latency.

    Current prices for the models this wiki uses:

    • Claude Fable 5.1

      claude-fable-5-1

      Context
      1M
      Max output
      128K
      Per 1M tokens
      $10 in / $50 out

      The hardest reasoning and long-running agent work, where quality matters more than cost.

    • Claude Opus 5.5

      claude-opus-5-5

      Context
      1M
      Max output
      128K
      Per 1M tokens
      $4 in / $20 out

      The default for product features: complex tasks, agents and anything quality-sensitive.

    • Claude Sonnet 5.5

      claude-sonnet-5-5

      Context
      1M
      Max output
      128K
      Per 1M tokens
      $2 in / $10 out

      Everyday features at high volume where speed and cost matter.

    • Claude Haiku 5.5

      claude-haiku-5-5

      Context
      1M
      Max output
      128K
      Per 1M tokens
      $0.10 in / $0.50 out

      For prompts up to 100K tokens; $0.50 input and $2.50 output per million beyond that.

      Classification, routing, extraction and other small, latency-sensitive steps.

    First-party Claude API list prices, checked on October 17, 2026. Prices change: see the pricing page (opens in a new tab) and models overview (opens in a new tab) before budgeting. "Good for" is the wiki's recommendation, not a benchmark.

    Prices change, and the pricing page has details such as discounts for cached input and batch processing. The table above is generated from the same configuration file as every example on this site, so it’s only as current as the date shown.

    From cost per call to cost per success

    Cost per call is where the estimate starts, not where it ends. Three things stand between a call and a successful outcome for the user:

    From cost per call to cost per success. Each step multiplies or divides; the last one is often the biggest.
    Show text descriptionHide text description

    3 parts, in order:

    1. Cost per call: input tokens × input price + output tokens × output price Example: 2,000 in, 400 out on a $4 / $20 model ≈ $0.016
    2. × calls per attempt: model calls one user attempt makes, including retries and multi-step flows Example: Route + answer = 2 calls → $0.032
    3. ÷ success rate: share of attempts that end in a success Example: 60% of answers are used → ≈ $0.053 per success
    • Calls per attempt. One user action can trigger several calls: a classification step, a retrieval step, the answer, an automatic retry on error. Count them all.
    • Retries by the user. If users regenerate an answer one time in four, every attempt costs about a quarter more.
    • Success rate. If only 60% of outputs are actually used, the 40% that aren’t still cost money. Divide by the success rate to get cost per successful task, the number to compare with what a success is worth.

    Cost per success is why quality and cost aren’t separate concerns. Improving the success rate from 50% to 75% cuts cost per success by a third, often more than switching to a cheaper model would.

    A cost estimator

    This script counts the real input tokens for a representative request with the token counting (opens in a new tab) endpoint, then applies your assumptions. Counting doesn’t generate a response, and it’s far more accurate than estimating from word counts.

    scripts/estimate-cost.ts
    import Anthropic from '@anthropic-ai/sdk';
    
    const client = new Anthropic();
    
    // USD per million tokens for the model below. Check the pricing page before relying on them.
    const PRICE = { inputPerMTok: 4, outputPerMTok: 20 };
    
    interface Assumptions {
      /** Average usage.output_tokens from a few real responses. Includes thinking, so measure it, don't guess. */
      outputTokens: number;
      /** Model calls one user attempt makes: multi-step flows, automatic retries. */
      callsPerAttempt: number;
      /** Share of attempts that end in success (used, accepted), from a prototype, evals or analytics. */
      successRate: number;
      attemptsPerMonth: number;
    }
    
    async function estimate(system: string, sampleInput: string, a: Assumptions) {
      const { input_tokens: inputTokens } = await client.messages.countTokens({
        model: 'claude-opus-5-5',
        system,
        messages: [{ role: 'user', content: sampleInput }],
      });
    
      const perCall = (inputTokens * PRICE.inputPerMTok + a.outputTokens * PRICE.outputPerMTok) / 1_000_000;
      const perAttempt = perCall * a.callsPerAttempt;
      return {
        inputTokens,
        perCall,
        perAttempt,
        perSuccess: perAttempt / a.successRate,
        perMonth: perAttempt * a.attemptsPerMonth,
      };
    }
    
    const usd = (n: number) => `$${n < 1 ? n.toFixed(4) : n.toFixed(2)}`;
    
    const result = await estimate(
      'You draft replies to customer support tickets using the help articles provided.',
      // Use a realistic input: a typical ticket plus the help articles retrieval would attach.
      'Ticket: How do I export my invoices as CSV?\n\nHelp article: To export invoices, open Billing > History and choose Export...',
      { outputTokens: 450, callsPerAttempt: 1.25, successRate: 0.6, attemptsPerMonth: 20_000 },
    );
    
    console.log(`Input tokens per call: ${result.inputTokens}`);
    console.log(`Cost per call:    ${usd(result.perCall)}`);
    console.log(`Cost per attempt: ${usd(result.perAttempt)} (includes retries)`);
    console.log(`Cost per success: ${usd(result.perSuccess)}`);
    console.log(`Monthly cost:     ${usd(result.perMonth)}`);

    Run it with npx tsx scripts/estimate-cost.ts. The assumptions are where the estimate lives or dies:

    • Measure output tokens from a handful of real responses (usage.output_tokens on each response) rather than guessing. Thinking makes guesses unreliable.
    • Use a realistic input. The example ticket is short; real tickets with several retrieved articles are much longer.
    • Be honest about success rate. If you don’t know it yet, run the estimate at 30%, 60% and 90% to see how sensitive the result is.

    Check the estimate against reality once the feature runs: every response reports its token usage, and cost dashboards track it per feature.

    Levers that cut cost

    When the estimate is too high, these levers usually help, roughly in order of how often they’re worth trying first:

    Lever What it does Trade-off
    Prompt caching Repeated input (long system prompts, documents) is billed at a reduced rate after the first request Requires a stable prefix; see the caching docs (opens in a new tab)
    Shorter output Ask for the length the job needs Must still meet the quality bar
    Lower effort Less thinking on tasks that don’t need it Measure quality on your evals first
    Less context Retrieve the relevant parts instead of sending everything Retrieval can miss things
    Smaller model for simple steps Use a cheaper model for classification or routing More moving parts; evaluate each step
    Batch processing Non-urgent work through the Batches API (opens in a new tab) at a discount Results arrive asynchronously, not in real time
    Higher success rate Better prompts, context or UX so fewer outputs are wasted Takes iteration, but compounds with every other lever

    Two warnings. First, measure quality after every cost change: a cheaper call that fails more often can raise cost per success. Second, don’t optimize too early. Prove the feature works with a capable model, then cut cost with evidence.

    Common mistakes

    • Stopping at cost per call. Retries, multi-step flows and unused outputs all cost money. Estimate cost per successful task.
    • Guessing token counts. Count input with the token counting endpoint and measure output from real responses, including thinking.
    • Testing with tiny inputs. Production inputs, with retrieved context and conversation history, are usually much larger.
    • Ignoring heavy users. A few users can account for a large share of cost. Model them separately.
    • Cutting cost without checking quality. A cheaper setting that lowers the success rate can make each success more expensive.

    Try it

    Exercise

    About 40 min

    Build a cost estimate for your feature

    1. Choose a realistic input for your feature, including any context it would send.
    2. Run three real requests and note usage.output_tokens for each.
    3. Run the estimator with your input, average output tokens, calls per attempt, and success rates of 30%, 60% and 90%.
    4. Compare cost per success with your estimate of what a success is worth, and write one sentence on whether the feature can pay for itself.
    Show a hint

    For value, a rough number is enough: “an accepted draft saves an agent about three minutes” multiplied by a loaded hourly cost gives you a value per success to compare against.

    Show a worked solution

    Example for drafted support replies, with illustrative numbers:

    • About 3,000 input tokens (ticket plus articles) and about 450 output tokens.
    • 1.25 calls per attempt (occasional regeneration).
    • Cost per success comes out at a few cents at 60% success, and roughly double at 30%.
    • Value: an accepted draft saves a few minutes of agent time, worth far more than a few cents.

    Conclusion: the feature pays for itself even at a low success rate, so optimize for quality first and revisit cost later.

    Check your understanding

    Question 1 of 4: A call costs $0.02, each attempt makes 1.5 calls on average, and 50% of attempts succeed. What is the cost per success?

    Show answer

    C. $0.06

    $0.02 × 1.5 = $0.03 per attempt; $0.03 ÷ 0.5 = $0.06 per success.

    Question 2 of 4: Why should you measure output tokens from real responses rather than estimate them from the visible answer?

    Show answer

    B. Thinking tokens are billed as output, so the visible answer understates the count

    On reasoning models, thinking counts towards output tokens and is billed as output.

    Question 3 of 4: Which change could lower cost per success without changing the model or its settings?

    Show answer

    B. Improving the success rate with better context or UX

    Fewer wasted outputs means each success carries less cost from failures.

    Question 4 of 4: Why should you model your heaviest users separately?

    Show answer

    B. Averages can hide users whose usage, and cost, is many times higher

    A feature can be profitable on average and lose money on its most active customers.

    Key takeaways

    • AI features have a real marginal cost: estimate it before you build.
    • Cost per call depends on input and output tokens; thinking is billed as output.
    • The number that matters is cost per successful task: cost per call × calls per attempt ÷ success rate.
    • Caching, shorter output, lower effort, less context, smaller models for simple steps and batching cut cost; check quality after each change.

    Progress is saved in this browser and lights up the roadmap.