▶️ LISTEN TO THIS ARTICLE
The True Cost of Running AI Agents in Production
By Tyler Casey · AI-assisted research & drafting · Human editorial oversight
@getboski
Production agent budgets should include posted token prices plus tool calls, orchestration, tracing, monitoring, retries, and workflow boundaries. A useful question is what one successful task costs after all the supporting work is included.
This guide gives you a practical cost model for answering that question before launch and revisiting it after real usage arrives.
The Sticker Price Is Misleading
Every major provider publishes model pricing, and those pages are worth checking before you ship. But pricing tables usually describe a single request: input tokens in, output tokens out. Agents are not single requests.
A production agent task can include planning, retrieval, tool selection, API calls, result interpretation, verification, response drafting, and fallback behavior. Each step may add tokens, latency, logs, and operational risk. The same user-facing task can have very different costs depending on:
- How much context is attached to each call
- Whether tool definitions are repeated every turn
- How many intermediate steps the agent takes
- How often calls fail and retry
- Which steps require a larger model
- Whether outputs need human review
- How much evaluation and observability you run around the system
That is why model choice matters, but call shape often matters more than the sticker price alone. A cheap completion can still cost more overall if it is called wastefully, triggers retries, or creates manual cleanup.

Where the Real Money Goes
Raw inference is only part of the production budget. The rest lives in the system around the model.
Orchestration overhead shows up whenever an agent breaks work into steps. Frameworks such as LangGraph, AutoGen, or CrewAI can make multi-step systems easier to build, but coordination still has a cost. System prompts, tool schemas, retrieved documents, conversation history, and intermediate outputs may be carried from call to call. The coordination tax in multi-agent systems is not just organizational complexity; it is also token flow, duplicated context, and more places for work to branch.
Tool calls can be more expensive than they look. The LLM call that chooses a tool is only the beginning. You may also pay for search, database queries, browser sessions, third-party APIs, sandbox execution, file storage, or queue workers. Tool results then come back into the context window, where they influence the next model call.
Retries and error handling are easy to underbudget. Agents misread tool outputs, produce invalid parameters, run into rate limits, or lose the thread of a longer task. Production systems need retry policies, fallback models, timeout behavior, idempotency protection, and escalation paths. The testing and debugging guide covers how to find these failure modes before they become recurring spend.
Monitoring and observability are part of the product, not a luxury. Teams need traces, prompt and response logs, token accounting, error categories, latency tracking, and per-task cost attribution. The observability guide covers what to track so cost problems can be tied back to specific workflows instead of guessed from a monthly invoice.
Evaluation costs are real because every regression test, model comparison, and quality check consumes compute. The model evaluation guide explains why evals need to match the actual task, not just a generic benchmark. A thin eval suite can miss expensive failures; an oversized one can become its own recurring cost center.
Human review loops can dominate the cost of sensitive workflows. If mistakes would create meaningful customer, operational, or business risk, a person may need to approve, correct, or sample agent outputs. The price of that review depends on the work and the seniority required, but it should be modeled explicitly instead of treated as a temporary launch cost.
Incidents and rollbacks belong in the budget too. A bad agent release can create support tickets, corrupted records, customer credits, rework, or emergency engineering time. Those costs do not appear in token dashboards, but they are part of the true cost of operating the system.
The Optimization Playbook
Good cost optimization starts with measurement. Do not begin by chasing the lowest posted model price; begin by making each task traceable from request to outcome.
Prompt caching can help when large parts of the prompt stay stable. Tool definitions, policy instructions, product context, and long reference material are common candidates. Caching is less useful when every request assembles a completely different context. The practical move is to separate stable instructions from dynamic task data, then measure cache hit rate and output quality.
Model routing sends different subtasks to different models. Simple classification, extraction, formatting, and routing work may not need the same model as complex reasoning or synthesis. Research such as RouteLLM and FrugalGPT supports the broader idea that routing can reduce cost while preserving useful quality, but every production team still needs task-specific evaluation before trusting a route.
Prompt compression reduces unnecessary context. LLMLingua and related work show that prompt compression is a serious research direction, but the simplest version is editorial: remove instructions that do not change behavior, shorten repeated examples, trim stale conversation history, and keep retrieved passages focused. Measure before and after; compressed prompts that remove decisive context can create more downstream cost than they save.
Batching is useful for work that does not need an immediate answer. Classification queues, nightly enrichment, bulk content checks, and offline eval runs are often better suited to asynchronous processing than interactive APIs. When a provider offers discounted batch processing, compare the savings against the operational tradeoff of delayed completion.
Context design is one of the highest-leverage controls. Put stable context where it can be reused, keep tool schemas concise, summarize long histories, and avoid attaching documents "just in case." For retrieval-heavy agents, retrieval quality is a cost control because irrelevant passages consume tokens and can lead the model into unnecessary follow-up work.
Failure budgeting prevents fake savings. A cheaper route is not cheaper if it increases invalid outputs, repeated calls, customer escalations, or manual review. Track cost per successful task, not cost per model call.
When Self-Hosting Might Beat APIs
Self-hosting can be attractive when usage is high, workloads are predictable, data-control requirements are strict, or latency needs fit a dedicated deployment. It can also be a distraction when a team has not yet stabilized the product.
The self-hosting calculation should include:
- Hardware or cloud GPU cost
- Utilization during quiet periods
- Serving infrastructure and autoscaling
- Model updates and compatibility testing
- Security, access control, and audit logging
- On-call support and incident response
- Performance tuning and capacity planning
- Evaluation against the hosted API baseline
APIs often reduce operational burden and can make it easier to switch models. Self-hosting can improve unit economics in high-utilization deployments, but only if the team can keep the system highly utilized and operationally healthy. Open-weight models, including systems discussed in the DeepSeek economics breakdown, make the build-versus-buy question more interesting, but they do not remove the need for careful measurement.
Treat self-hosting as an engineering and operations decision, not just a token-price comparison.

The Hidden Multipliers
Several cost factors tend to appear after the pilot, when real users start pushing the system in messier ways.
Token growth over time. Early demos often use short, clean prompts. Production users bring longer histories, larger files, ambiguous requests, and edge cases. Teams should watch whether average input tokens, output tokens, and steps per task are drifting upward.
Expanded usage. When an agent works, people find more places to use it. That can be good, but it means lower unit cost does not automatically lower total spend. Reports such as the AI Index are reminders that model-performance costs and adoption patterns can move quickly. Budgeting should leave room for product usage to grow if the agent proves useful.
Evaluation drift. Evals start small and then expand as the system takes on more workflows. New models, new prompts, new tools, and new policies all need regression checks. Keep eval suites focused on decisions that matter, and retire tests that no longer predict production quality.
Operational drag. Agents create queues to monitor, prompts to version, traces to review, vendors to manage, and exceptions to investigate. These are normal operating costs. They become dangerous only when they are invisible.
A Cost Calculator Framework
Use this framework before launch, then replace estimates with live data as soon as you have traffic.
Step 1: Define a successful task. Pick the unit that matters to the business: resolved support conversation, completed research brief, approved invoice, merged code change, enriched account, or reviewed document. Avoid optimizing for isolated calls if the product succeeds or fails at the task level.
Step 2: Map the call pattern. For each task type, list the expected LLM calls, average input tokens, average output tokens, tools used, retrieval size, and whether any step requires a stronger model.
Step 3: Add failure paths. Include retries, validation failures, timeouts, fallback models, human escalation, and abandoned tasks. A cost model that only covers the happy path will be too low.
Step 4: Apply current provider pricing. Pull model prices from the provider pages at the time you run the estimate. Keep input, output, cached input, batch, and fine-tuned model prices separate because they may behave differently.
Step 5: Add platform costs. Include observability, queues, vector storage, search, database reads and writes, external APIs, sandbox execution, and storage for traces or artifacts.
Step 6: Add human and incident costs. Estimate review time, support escalation, audit work, and rollback effort for workflows where mistakes carry consequences.
Step 7: Model optimization scenarios. Compare a baseline system with realistic improvements such as caching, routing, shorter prompts, better retrieval, and batching. Keep quality gates attached to each scenario so savings do not come from quiet degradation.
Step 8: Set review triggers. Recalculate when model prices change, a provider launches a relevant feature, task volume changes, average tokens drift, failure rate rises, or a new workflow is added.
What Actually Matters
The teams that control AI agent costs often share a few habits.
First, they measure cost per successful task from day one. This captures retries, failures, escalations, review, and support work that average token spend hides. If per-task cost rises, the problem may be quality, not pricing.
Second, they use the cheapest model that reliably works for each subtask. A mixture of experts approach at the system level means routing work by difficulty instead of sending everything to the most capable model by default.
Third, they treat cost optimization as continuous. Model prices, provider features, open-weight options, caching behavior, and workload shape all change. A cost model should be a living operating artifact, not a spreadsheet from the launch meeting.
The true cost of running AI agents is not just a provider invoice. It is the cost of producing reliable outcomes with models, tools, people, tests, and operations working together. Track that whole system and the budget becomes easier to control.
Sources
Research Papers:
- An LLM Compiler for Parallel Function Calling -- Kim et al. (2023)
- LLMLingua: Compressing Prompts for Accelerated Inference -- Jiang et al., Microsoft (2023)
- RouteLLM: Learning to Route LLMs with Preference Data -- Ong et al., Berkeley (2024)
- FrugalGPT: How to Use Large Language Models While Reducing Cost -- Chen et al., Stanford (2023)
Industry / Case Studies:
- Klarna AI Assistant Handles Two-Thirds of Customer Chats -- Klarna (2024)
- The AI Index Report 2025 -- Stanford HAI
- OpenAI API Pricing -- OpenAI
- Anthropic API Pricing -- Anthropic
- DeepSeek API Pricing -- DeepSeek
Commentary:
- The Economics of Large Language Models -- a16z (2024)
- AI Cost Optimization: A Practical Guide -- Martian AI
Related Swarm Signal Coverage:
- The Budget Problem: Why AI Agents Are Learning to Be Cheap
- AutoGen vs CrewAI vs LangGraph: Picking a Multi-Agent Framework
- The Coordination Tax in Multi-Agent Systems
- DeepSeek Explained: How a Chinese Lab Rewrote AI Economics
- How to Test and Debug AI Agents
- Mixture of Experts Explained: The Architecture Behind Every Frontier Model