πŸ’³ Introducing Flexible Pay|
    Back to the Series
    AI Cost Optimization & Economics 18 min read Issue 17

    AI Cost Optimization and LLM Unit Economics: How to Calculate the True Cost of an AI Request

    A workflow that looks inexpensive at 100 requests per day can become a very different business at 100,000 requests per day. This is where AI engineering becomes a unit-economics problem.

    TA
    Tobe Awosanya
    Data Techcon Technical Series Β· AI Cost Optimization & Economics

    Building an AI product has taught me to ask one question much earlier than most teams do:

    What does one successful request actually cost?

    Not just: How much did the model API call cost?

    The true cost of an AI workflow can include model inference, input and output tokens, embeddings, retrieval, reranking, tool calls, retries, fallback models, observability, storage, infrastructure, and sometimes several model calls before the user receives one useful result.

    That distinction becomes increasingly important as an AI product moves from prototype to production.

    A workflow that looks inexpensive at 100 requests per day can become a very different business at 100,000 requests per day.

    And this is where AI engineering becomes a unit-economics problem.

    The unit of work

    Cost per API call is not the same as cost per user task

    One of the easiest mistakes to make when estimating AI costs is treating a single LLM call as the unit of work.

    Imagine a user asks an AI application:

    β€œReview this contract and identify the major risks.”

    From the user's perspective, that is one request. But internally, the system might:

    One user task, many billable operations
    1. 01Parse the uploaded document.
    2. 02Create or retrieve embeddings.
    3. 03Search a vector database.
    4. 04Rerank retrieved passages.
    5. 05Send context to an LLM.
    6. 06Call another model to classify identified risks.
    7. 07Use a tool to retrieve company policy.
    8. 08Ask the LLM to produce the final response.
    9. 09Retry one step because the first response failed validation.
    10. 10Record traces, metrics, and outputs for monitoring.

    The user completed one task.

    Your infrastructure may have executed several billable operations.

    That means the more useful metric is often cost per successful task rather than cost per model call.

    The model

    A practical AI cost model

    At a high level, the variable cost of an AI workflow can be represented as:

    AI Workflow Cost = Model Cost + Retrieval Cost + Tool Cost + Infrastructure Cost + Failure/Retry Cost + Supporting Service Cost

    Let's break that down.

    Component 1 Β· 01
    Model inference cost

    This is usually the most visible cost. For token-priced models, the basic calculation is: Input Cost = Input Tokens Γ— Input Token Rate. Output Cost = Output Tokens Γ— Output Token Rate. Then: Model Cost = Input Cost + Output Cost.

    But even this is more complicated than it first appears. A request may contain far more than the user's question.

    A single request may contain
    • β†’System instructions
    • β†’Conversation history
    • β†’Retrieved documents
    • β†’Tool definitions
    • β†’User input
    • β†’Structured output instructions
    • β†’Examples
    • β†’Previous agent state

    A 30-word user question can therefore become a request containing thousands of tokens. The visible user prompt is not necessarily what you are paying to process.

    Component 2 Β· 02
    Cached vs. uncached input

    Repeated context creates another important optimization opportunity. If every request includes the same long system prompt, tool definitions, schemas, instructions, or document prefixes, repeatedly processing all of that context can become expensive.

    Major model providers now support forms of prompt caching that allow repeated prompt prefixes or context to be processed at different rates from entirely new input. OpenAI documents cached-input pricing and prompt caching for supported models, while Anthropic similarly supports prompt caching and documents separate cache behavior and pricing.

    Caching works especially well when a meaningful portion of the request stays consistent.

    Examples include
    • β†’Large system prompts
    • β†’Policy documents
    • β†’Tool definitions
    • β†’Long application instructions
    • β†’Stable reference material
    • β†’Repeated document context

    But caching should be an architectural decision, not simply a checkbox.

    Before enabling caching, you still need to understand
    • β†’What portion of the prompt is reusable?
    • β†’How frequently is it reused?
    • β†’How long does the cache remain useful?
    • β†’What happens when the underlying information changes?
    • β†’Does caching reduce cost enough to justify additional complexity?
    Component 3

    Retrieval costs in RAG systems

    A RAG application has costs that exist outside the final LLM call.

    Depending on the architecture, a request may require:

    Embedding generation

    The query may need to be converted into an embedding.

    Vector search

    The application queries a vector database or search infrastructure.

    Hybrid retrieval

    Keyword search and vector search may both run.

    Reranking

    A reranking model may score the retrieved documents before sending them to the primary LLM.

    Context generation

    Retrieved chunks are assembled into the final model prompt.

    Each individual component may appear inexpensive.

    At production volume, they accumulate.

    This is why RAG optimization is not only about improving retrieval quality. You should be evaluating retrieval quality + latency + cost together.

    Retrieving 30 documents and sending all 30 to an expensive model might increase the likelihood that the answer is grounded, but it may also dramatically increase input-token consumption.

    The engineering problem becomes:

    What is the smallest amount of high-quality context required to reliably complete the task?

    Component 4

    Agent and tool-call costs

    Agentic systems introduce another layer of cost.

    A simple LLM request might require one inference call. An agent might:

    A single agent task may involve
    • β†’Plan
    • β†’Search
    • β†’Call a database
    • β†’Inspect the result
    • β†’Call another tool
    • β†’Reflect
    • β†’Replan
    • β†’Call another model
    • β†’Validate
    • β†’Generate a final response

    One user action may therefore produce five, ten, or more model interactions.

    That does not automatically make agents bad.

    But it makes execution depth an important economic metric. Track:

    Execution depth metrics
    • β†’Average model calls per task
    • β†’Average tool calls per task
    • β†’Average tokens per completed task
    • β†’Average retries per task
    • β†’Average cost per completed task

    You may discover that the expensive part of the product is not your primary model.

    It is uncontrolled orchestration.

    Component 5

    Retries and failure costs

    This is one of the most overlooked parts of AI unit economics. Suppose the first model response fails schema validation. Your system retries.

    The second response calls a tool incorrectly. It retries again.

    Eventually, the user receives a correct answer.

    From the user's perspective: one successful request. From your billing perspective: three attempts.

    This is why I like separating cost per attempt from cost per successful task. Suppose:

    Retry math
    • β†’ Average attempt cost = $0.04
    • β†’ Average attempts per completed task = 1.4
    $0.04 Γ— 1.4 = $0.056 model-related cost per completed task

    before adding other infrastructure.

    Multiply small differences like that across millions of requests and reliability becomes a financial concern, not merely a technical one.

    Component 6

    Observability is part of the cost stack

    Production AI needs observability. Teams may need to capture:

    Observability captures
    • β†’Traces
    • β†’Prompt versions
    • β†’Model responses
    • β†’Tool activity
    • β†’Retrieval results
    • β†’Token consumption
    • β†’Latency
    • β†’Evaluation results
    • β†’Safety events
    • β†’Error logs
    • β†’User feedback

    Those systems also cost money.

    The mistake is not paying for observability.

    The mistake is excluding observability from your product economics and then being surprised by infrastructure spend later.

    If a capability is required to safely operate the product, it belongs in the cost model.

    Measurement

    What should you actually measure?

    A useful AI cost dashboard should move beyond total monthly API spend.

    I would track several levels.

    Level 1: Request economics
    • β†’Input tokens per request
    • β†’Output tokens per request
    • β†’Cached input
    • β†’Model calls per request
    • β†’Tool calls per request
    • β†’Retrieval operations
    • β†’Average latency
    • β†’Cost per attempt

    These help engineering understand what is driving spend.

    Level 2: Task economics
    • β†’Successful completion rate
    • β†’Retries per task
    • β†’Failure rate
    • β†’Escalation rate
    • β†’Average cost per successful task
    • β†’Cost by workflow
    • β†’Cost by feature

    This is where the economics become much more useful.

    Imagine two features:

    Feature A

    Cost per request: $0.03

    Successful completion: 60%

    $0.03 Γ· 0.60 = $0.05 per successful task
    Feature B

    Cost per request: $0.04

    Successful completion: 95%

    $0.04 Γ· 0.95 β‰ˆ $0.042 per successful task

    Feature A looks cheaper if you only examine request cost.

    The more expensive model call produced the cheaper successful outcome.

    This is exactly why optimization cannot be separated from evaluation.

    Quality

    AI cost optimization must be evaluated against quality

    One of the worst optimization strategies is: move everything to the cheapest model.

    Lower model cost does not necessarily mean lower system cost. A cheaper model may generate:

    βœ•More retries
    βœ•Worse extraction
    βœ•More hallucinations
    βœ•More failed tool calls
    βœ•More human escalations
    βœ•Longer outputs
    βœ•Lower conversion
    βœ•Higher user abandonment

    The correct comparison is not: Model A costs less than Model B. It is:

    Which model gives us the best cost-quality tradeoff for this specific task?

    This is where evaluation becomes part of financial optimization.

    Routing

    Model routing: not every task needs your best model

    One of the strongest optimization patterns is routing workloads based on complexity.

    Your most capable model does not necessarily need to handle every task.

    A smaller model may be sufficient for
    • βœ“Classify basic requests
    • βœ“Extract simple structured fields
    • βœ“Detect language
    • βœ“Route support requests
    • βœ“Summarize short text
    • βœ“Perform straightforward transformations
    Reserve capable models for
    • β†’Complex reasoning
    • β†’Difficult synthesis
    • β†’Ambiguous decisions
    • β†’High-value generation
    • β†’Complex agent steps
    • β†’Cases where smaller models fail evaluation thresholds
    A routing strategy might look like
    Simple task β†’ Lower-cost model
    Complex task β†’ Higher-capability model
    Low-confidence result β†’ Escalate

    This turns model selection from a one-time architecture decision into an optimization system.

    Evaluation

    But model routing needs evaluation

    Routing only works if you know when each model is good enough.

    For every task category, establish:

    Thresholds per task category
    • β†’Quality threshold
    • β†’Accuracy requirement
    • β†’Latency requirement
    • β†’Safety threshold
    • β†’Cost threshold
    • β†’Escalation conditions

    Then measure the tradeoff. For example:

    ModelTask SuccessAvg. CostAvg. Latency
    Model A96%$0.082.8 sec
    Model B93%$0.031.7 sec
    Model C78%$0.011.1 sec

    The answer is not automatically Model A.

    If 93% meets the product's quality threshold, Model B could create dramatically better economics. For another workflow, that 3-point difference may be unacceptable.

    Optimization is contextual.

    Context

    Reduce context before reducing capability

    Large context windows can make it tempting to send everything to the model.

    That can quickly become expensive.

    Before downgrading model quality, examine whether you are paying to process unnecessary context. Look for:

    Context waste to look for
    • β†’Repeated instructions
    • β†’Excessive conversation history
    • β†’Duplicate retrieved chunks
    • β†’Overly large documents
    • β†’Unnecessary few-shot examples
    • β†’Tool definitions irrelevant to the current task
    • β†’Verbose metadata
    • β†’Large structured payloads
    • β†’Retrieval results the model never needs

    A better retrieval strategy or tighter prompt can sometimes produce more savings than switching models.

    Output

    Control output length

    Output tokens can be materially more expensive than input tokens depending on the model and provider.

    Do users actually need 1,500-word responses? For many workflows, they may need:

    • β†’Five extracted fields
    • β†’Three recommendations
    • β†’A 100-word summary
    • β†’A JSON object
    • β†’A classification
    • β†’A short explanation

    Product design influences inference cost. Clear output constraints can improve:

    • β†’Cost
    • β†’Latency
    • β†’Consistency
    • β†’Evaluation
    • β†’User experience

    Do not pay the model to generate content nobody needs.

    Batching

    Use batch processing when real-time responses are not required

    Not every AI workload needs synchronous inference. Examples include:

    Asynchronous-friendly workloads
    • β†’Overnight document classification
    • β†’Bulk summarization
    • β†’Periodic content enrichment
    • β†’Dataset labeling
    • β†’Offline evaluations
    • β†’Large-scale extraction
    • β†’Scheduled reporting

    Both OpenAI and Anthropic currently document batch-processing options designed for asynchronous workloads, with pricing advantages for supported workloads.

    The product question is:

    Does this task truly need to happen while the user waits?

    If not, asynchronous processing may provide both operational and economic benefits.

    Per user

    Cost per user matters more than cost per request

    Once you understand request and task economics, move one level higher. Suppose:

    • β†’ Average successful task cost = $0.05
    • β†’ Active user completes 40 tasks per month

    Variable AI cost per active user: $0.05 Γ— 40 = $2.00/month

    If the customer pays $20/month, that may look healthy. But now include:

    • β†’Hosting
    • β†’Databases
    • β†’Search infrastructure
    • β†’Monitoring
    • β†’Payment fees
    • β†’Customer support
    • β†’Other variable services

    Maybe true variable cost is $4 per user. Your gross contribution before fixed operating expenses becomes $20 – $4 = $16.

    Now consider a power user completing 500 AI tasks per month. At the same $0.05: 500 Γ— $0.05 = $25.

    Your $20 subscription is already underwater before considering anything else.

    That is why unlimited AI usage can become dangerous.

    Distribution

    AI products need usage distribution, not just average usage

    Averages hide expensive users.

    Suppose your average customer generates 40 requests. But usage actually looks like:

    • β†’60% generate fewer than 20
    • β†’30% generate 20–100
    • β†’8% generate 100–500
    • β†’2% generate more than 1,000

    That final 2% can materially change product economics. Analyze:

    • β†’Median usage
    • β†’P75
    • β†’P90
    • β†’P95
    • β†’P99
    • β†’Maximum usage
    • β†’Cost by customer segment

    Data science becomes extremely useful here.

    You can model usage distributions, identify expensive cohorts, forecast future spend, and understand whether pricing reflects actual consumption.

    Monetization

    From AI cost analysis to monetization strategy

    Once cost per successful task and cost per user are known, pricing becomes much easier to reason about. Common AI monetization models include:

    Subscription

    Users pay a fixed recurring fee.

    Best when usage is relatively predictable.

    Risk: Heavy users can destroy margins.

    Usage-Based Pricing

    Customers pay based on consumption.

    Examples:

    • β†’Requests
    • β†’Documents
    • β†’Minutes
    • β†’Tokens
    • β†’Generated assets
    • β†’Completed workflows

    This directly links revenue to usage but can make customer bills less predictable.

    Credits

    Users purchase or receive a fixed number of credits.

    Different workflows can consume different credit amounts.

    Credits provide flexibility without exposing raw token economics to customers.

    Tiered Plans

    Example: Basic β€” 100 AI tasks/month. Pro β€” 500 AI tasks/month. Business β€” 2,500 AI tasks/month.

    This creates predictable packaging while controlling exposure.

    Hybrid Pricing

    A subscription includes baseline usage, followed by overage pricing. For many AI SaaS products, this can balance predictable recurring revenue with variable infrastructure cost.

    The metric

    The metric I would put on every AI product dashboard

    I would want teams to know:

    Cost per successful user outcome

    Not: How many tokens did we spend?

    But: How much did it cost us to deliver the thing the customer came here to accomplish?

    For a resume application
    Cost per completed resume
    For an AI research product
    Cost per completed research task
    For an agent
    Cost per successfully executed workflow
    For customer support
    Cost per resolved ticket
    For a document-review platform
    Cost per successfully reviewed document

    That metric connects engineering performance directly to product economics.

    Value

    Connect cost to business value

    Cheap AI is not necessarily good AI.

    An AI workflow costing $2 per task could be extremely profitable if it replaces $50 of manual work. Another workflow costing $0.03 may be financially pointless if nobody values the output.

    The relevant question is:

    What economic value does this workflow create relative to what it costs to deliver?

    A simple framework is: Value Created per Task Γ· Cost per Successful Task

    This can help teams prioritize which AI workflows deserve continued investment.

    Governance

    AI cost optimization is also a governance problem

    Cost optimization is usually treated as an engineering concern.

    It also belongs in AI governance. Why?

    Because unchecked autonomy can create unchecked spend.

    An agent allowed to repeatedly:

    • β†’Search
    • β†’Reason
    • β†’Call tools
    • β†’Generate
    • β†’Retry
    • β†’Delegate to sub-agents

    can consume substantial resources from a single request.

    Operational controls may therefore include:

    Financial guardrails are system guardrails
    • β†’Maximum model calls
    • β†’Maximum retries
    • β†’Token budgets
    • β†’Tool-call limits
    • β†’Workflow timeouts
    • β†’Cost thresholds
    • β†’Escalation rules
    • β†’Human approval for high-cost actions
    • β†’Per-user usage limits
    • β†’Per-workflow budgets
    Framework

    A practical AI unit economics framework

    Before scaling an LLM-powered product, I would want clear answers to five levels of cost.

    01
    Cost per Attempt

    What does one execution attempt cost?

    02
    Cost per Successful Task

    What does completing the user's intended task cost after accounting for retries and failures?

    03
    Cost per Active User

    How much variable AI cost does an average active user generate?

    04
    Cost by Customer Segment

    Which cohorts generate the highest cost and the most value?

    05
    Margin at Scale

    What happens when users double, requests per user increase, model pricing changes, context grows, agent complexity increases, or usage shifts toward power users?

    Then run scenarios.

    Current usage
    2Γ— usage
    5Γ— usage
    10Γ— usage

    This gives leadership a much clearer picture than looking at this month's API invoice.

    Checklist

    A simple optimization checklist

    Before switching models, review the entire workflow.

    Model
    • β†’Are we using more model capability than the task requires?
    • β†’Can tasks be routed across models?
    • β†’Are fallback models necessary?
    Tokens
    • β†’Is repeated context being resent?
    • β†’Can prompt caching help?
    • β†’Is retrieved context larger than necessary?
    • β†’Are outputs unnecessarily verbose?
    Retrieval
    • β†’Are we retrieving too many chunks?
    • β†’Do we need reranking for every query?
    • β†’Can retrieval quality improve enough to reduce context?
    Agents
    • β†’How many model calls does one task require?
    • β†’Are tool calls actually necessary?
    • β†’Are agents looping or retrying unnecessarily?
    • β†’Can deterministic logic replace some agent steps?
    Infrastructure
    • β†’Which workloads need real-time inference?
    • β†’Which can run asynchronously?
    • β†’Are we storing unnecessary traces or outputs?
    • β†’Are observability costs proportional to their value?
    Product
    • β†’What does one successful task cost?
    • β†’Which users generate the highest variable cost?
    • β†’Does pricing reflect usage?
    • β†’Are usage limits appropriate?
    • β†’What margin does each plan generate?
    Takeaway

    The bigger lesson

    AI cost optimization is not simply: Use fewer tokens.

    And it is not: Choose the cheapest model.

    The real problem is finding the best combination of:

    Quality + Cost + Latency + Reliability + Safety + Business Value

    A technically impressive AI system can still be a bad product if its economics do not work.

    And an inexpensive system can still be a bad product if quality is too low to create value.

    The strongest AI systems are designed so that technical performance and economic performance can be evaluated together.

    Before scaling, understand:

    The economics ladder
    Cost per request β†’ Cost per successful task β†’ Cost per active user β†’ Revenue per user β†’ Margin at expected usage

    That is where AI engineering becomes AI product economics.


    About the Author. Tobe Awosanya β€” AI Engineering Leader Β· Data Scientist Β· Technical AI Advisor Β· Founder, Data Techcon. Tobe works across data science, machine learning, AI engineering, responsible AI, product analytics, and production AI systems. Her work focuses on connecting technical decisions β€” including model selection, evaluation, architecture, governance, observability, and AI economics β€” to measurable product and business outcomes. Through Data Techcon, she advises organizations and builds practical Data & AI learning experiences for professionals, founders, and technical teams.

    Download the AI Unit Economics Worksheet

    Work through cost per attempt, cost per successful task, cost per active user, cost by segment, and margin at scale for your own AI workflow.

    Get the worksheet

    Need to evaluate the economics of an AI system?

    If your team is building or scaling an AI product and needs help understanding model costs, routing decisions, token usage, architecture tradeoffs, unit economics, or monetization strategy, Data Techcon AI Strategy Advisory provides focused strategic and technical support. Our AI Cost Optimization & Unit Economics advisory work helps teams connect LLM architecture decisions to quality, scalability, pricing, and sustainable product economics.

    πŸͺ We value your privacy

    We use cookies to enhance your browsing experience, analyze site traffic, and personalize content. By clicking "Accept All", you consent to our use of cookies. Read our Privacy Policy to learn more.