How AI Agent Startups Keep Margins When Inference Costs Run Over: Which Lever Fits Your Agent
Prompt caching comes first for every agent. After that the right lever depends on what fills your context: tool output, long research loops, simple tasks or work that can wait. A worked example takes one agent from -211% to 85% margin.
Agent startups whose token bills outran their models keep gross margins by cutting inference cost per completed task, then pricing so the expensive tasks are paid for. Prompt caching is the first fix for any agent: a January 2026 study of more than 500 agent sessions found it cut API costs 41 to 80 percent. What comes next depends on the agent. Coding agents should trim tool output, research agents should clear stale context, agents with many simple tasks should route whole tasks to a model that costs a twentieth as much, and work that can wait should go through batch APIs at half price. No one has published a benchmark of all these levers on the same agent traces, so their savings cannot simply be added up; the worked example below shows how they overlap.
First, find where the tokens go
An agent costs more than the model suggests because it re-sends its context on every step. Claude Code's cost docs say it "sends your full conversation with every request," and each tool use sends another request with the results. Anthropic wrote in June 2025 that agents use about 4x the tokens of chat and multi-agent systems about 15x.
Before choosing a lever, split a few hundred real tasks into their parts: the fixed prefix (system prompt and tool definitions), tool results, reasoning and output, and the number of steps. Anthropic counted about 55,000 tokens of definitions for 58 tools across five MCP servers, before any work began. Claude Code's docs say thinking tokens are billed as output, the most expensive token class, and that thinking cannot be turned off on Opus 5.5, Sonnet 5.5 or Haiku 5.5. The split tells you which lever pays.
The stakes are the margin line. Bessemer's August 2025 State of AI report put the fastest-growing AI startups at about 25 percent gross margin, often negative, and steadier ones at about 60 percent.
Every agent: make the cache work
Both large providers now price caching the same way. Anthropic's docs charge 1.25x base input to write a five-minute cache and 0.1x to read it, or 0.05x on Sonnet 5.5 and Opus 5.5. OpenAI's guide charges 1.25x to write and 0.1x or less to read on GPT-5.6 and later. A hit needs an identical prefix: Anthropic requires "100 percent identical prompt segments," and OpenAI lists timestamps at the start of the prompt, changing tools, compaction and changing the model among the things that break it. Put everything dynamic at the end, freeze tool definitions for the life of a task, and check the cache-read share of input in each response's usage.
Choosing the next lever
| Your agent | Main cost driver | Next lever | Published evidence |
|---|---|---|---|
| Coding agent | Tool output: file reads, logs, test runs | Trim tool output at the source | Anthropic: 37% fewer tokens with programmatic tool calling |
| Research or multi-agent | Long histories, stale tool results | Context editing and compaction | Anthropic: 84% fewer tokens over 100 turns |
| Many-tool agent | Tool definitions in every call | Load tools on demand | Anthropic: about 77K to 8.7K upfront tokens |
| High volume, many easy tasks | Mid-tier price on simple work | Route whole tasks to a small model | RouteLLM: over 2x cheaper, on single queries |
| Back-office, not time-sensitive | Standard-tier price | Batch API | Anthropic and OpenAI: 50% off, stacks with caching |
Coding agents spend most of their context on what tools return. Claude Code's docs show a hook that returns only error lines from a 10,000-line log, cutting "tens of thousands of tokens to hundreds," and another that keeps the last 100 lines of test output. Anthropic's programmatic tool calling, which runs tool calls from code so intermediate results stay out of the model's context, cut average usage from 43,588 to 27,297 tokens on complex research tasks.
Parsec, a small language model lab, sells a context layer for coding agents (Claude Code, Codex, opencode) that trims unused tool output and thinking; according to its site the Pro tier is free to start. In Parsec's own benchmark of 100 SWE-bench Verified tasks on Claude Sonnet 4.6, changing only that layer cut total cost from $147.30 to $89.65, with 62 tasks solved against 57. It is Parsec's benchmark, not an independent one; the repo publishes per-task data and can be re-run, and no independent re-run has been published.
Research and multi-agent systems accumulate history. Anthropic's context editing, announced September 29, 2025, clears stale tool calls and results as the window fills; in a 100-turn web search evaluation it cut tokens 84 percent and improved task performance 29 percent. Compaction does a similar job by summarising, but Claude Code's docs warn that compacting a large context "is itself a large request," and OpenAI's guide notes it changes the prefix, so the next call misses the cache. Anthropic also cautions that multi-agent designs pay off only where "the value of the task is high enough to pay for the increased performance."
Agents with many tools should stop sending every definition. Anthropic's Tool Search Tool loads tool definitions only when needed, cutting upfront context from about 77,000 tokens to about 8,700 in its example, and lifting Opus 4.5's accuracy on its MCP evaluation from 79.5 to 88.1 percent.
High-volume agents with easy tasks can use the 20x price gap between tiers. Anthropic's Haiku 5.5 lists at $0.10 per million input tokens and $0.50 output, against $2 and $10 for Sonnet 5.5; OpenAI's gpt-6-luna and gpt-6.2-sol carry the same pairs. RouteLLM found routing between a strong and a weak model cut costs "by over 2 times in certain cases" without hurting quality, and FrugalGPT claimed up to 98 percent, but both measured single queries rather than agents. Route whole tasks, because changing the model breaks the cache, and switching back mid-task means paying to rewrite it. Cross-model K/V cache transfer, which some vendors say avoids that penalty, has not been independently measured.
Work that can wait belongs in a batch API. Anthropic and OpenAI both list batch rates at half of standard, and Anthropic's docs say caching multipliers stack with the batch discount.
Step and retry caps fit every agent, but no one has published what they save in production, or how often agents run away into long loops. Measure your own share of runaway tasks first.
A worked example: one agent, five configurations
This is arithmetic on list prices, not a measurement on real traces. The assumptions are illustrative and the prices are list prices on Sonnet 5.5, which match gpt-6.2-sol's. A task takes 20 model calls. Each carries a 15,000-token fixed prefix and adds 2,000 tokens of tool result and 400 output tokens, reasoning included. One attempt in ten runs away to 60 calls and fails anyway; 80 percent of attempts complete. The customer pays $1.00 per completed task, and inference is the only cost counted.
| Configuration | Cost per attempt | Cost per completed task | Gross margin |
|---|---|---|---|
| No levers | $2.49 | $3.11 | -211% |
| Caching (5-minute) | $0.38 | $0.48 | 52% |
| + tool results trimmed to 500 tokens | $0.25 | $0.31 | 69% |
| + cap at 20 calls | $0.20 | $0.26 | 74% |
| + half of tasks on Haiku 5.5 | $0.12 | $0.15 | 85% |
The first row is a normal task billing 756,000 input tokens at $2 per million plus 8,000 output at $10, $1.59, and a runaway billing $10.54. Caching turns the normal task into 60,600 tokens written at $2.50 and 695,400 read at $0.10, $0.30. The rows are cumulative, and their order matters: trimming alone would cut an uncached agent's cost per attempt 42 percent, but after caching it saves 35 percent, and the cap saves 18 percent on top of both. The last row assumes Haiku completes those tasks as often as Sonnet, which has not been measured, and that a task never switches models; switching back to Sonnet at call 15 would rewrite a 48,600-token prefix for $0.12, 40 percent of a cached task. If the same work could wait, the batch discount would halve the fourth row to about $0.10 per attempt and $0.13 per completed task, an 87 percent margin, provided cache hits held in batch, which has not been measured either.
Then price for the tasks that cost the most
Cutting cost per task leaves the variance. Cursor's June 16, 2025 change replaced 500 monthly requests with $20 of usage at API rates, because "the hardest requests cost an order of magnitude more than simple ones"; on July 4 it apologised, "We were not clear that 'unlimited usage' was only for Auto," and refunded surprise charges. Replit replaced a flat $0.25 per checkpoint with effort-based pricing on June 18, 2025. Sierra charges only for completed outcomes, with unresolved conversations and escalations free "in most cases," so it absorbs the cost of every failed attempt, as the example above does. ICONIQ's 2025 survey found many companies on hybrid pricing, a subscription plus usage, and 37 percent planning to change AI pricing within a year.
Bottom line
Every agent should fix its cache first. A coding agent should then trim tool output, a research agent clear stale context, a many-tool agent load tools on demand, and a high-volume agent route whole easy tasks to the small tier once an evaluation shows they still complete. Work that can wait goes to batch. Cap steps once you know how many tasks run away. Then choose pricing to match the variance that remains: usage credits when cost varies by customer, outcome pricing only when cost per completed task is low and stable.
Sources
- Lumer et al., Don't Break the Cache: https://arxiv.org/abs/2601.06007
- Claude Code docs, Manage costs effectively: https://code.claude.com/docs/en/costs
- Anthropic, How we built our multi-agent research system: https://www.anthropic.com/engineering/multi-agent-research-system
- Anthropic, Introducing advanced tool use: https://www.anthropic.com/engineering/advanced-tool-use
- Anthropic, Managing context on the Claude Developer Platform: https://claude.com/blog/context-management
- Claude docs, Prompt caching: https://platform.claude.com/docs/en/build-with-claude/prompt-caching
- Claude docs, Pricing: https://platform.claude.com/docs/en/about-claude/pricing
- OpenAI, Prompt caching guide: https://developers.openai.com/api/docs/guides/prompt-caching
- OpenAI, API pricing: https://developers.openai.com/api/docs/pricing
- Ong et al., RouteLLM: https://arxiv.org/abs/2406.18665
- Chen, Zaharia and Zou, FrugalGPT: https://arxiv.org/abs/2305.05176
- Bessemer Venture Partners, The State of AI 2025: https://www.bvp.com/atlas/the-state-of-ai-2025
- ICONIQ, 2025 State of AI: https://www.iconiq.com/growth/reports/2025-state-of-ai
- Cursor, Clarifying our pricing: https://cursor.com/blog/june-2025-pricing
- Replit, Effort-based pricing: https://replit.com/blog/effort-based-pricing
- Sierra, Outcome-based pricing for AI agents: https://sierra.ai/blog/outcome-based-pricing-for-ai-agents
- Parsec for coding agents: https://parseclab.ai/parsec/
- Parsec (getparsec.ai): https://getparsec.ai/
- Parsec, code-compression-bench: https://github.com/daseinlabs/code-compression-bench