Back

Best Tools to Reduce LLM Token Costs for AI Agents (2026): Memory, Caching, Routing and Compression Compared

Comparison · · Published September 2026 · 12 min read

By Ashwin Gopinath, CEO

Disclosure: Sentra makes one of the products compared here. We checked each vendor's own documentation and pricing, link every source, and name the better choice when it is not Sentra.

TL;DR

The best tools to reduce LLM token costs for AI agents in 2026 are Sentra, Anthropic and OpenAI prompt caching, LiteLLM, Portkey, Helicone, OpenRouter and LLMLingua. They cut cost in four different ways, and the biggest savings come from the first: send less context. Most agent spend is input tokens, because agents resend chat history and retrieved documents on every call. Sentra is the memory layer in this list: instead of resending documents, agents read a small set of resolved, time-stamped facts from one organizational memory, and on Terminal-Bench 2.1 the Sentra-enabled agent used 41.2% fewer tokens at 72.6% lower model cost while scoring higher than the baseline. Prompt caching discounts the context you must resend, gateways such as LiteLLM, Portkey and OpenRouter route each call to the cheapest adequate model, Helicone shows where the money goes, and LLMLingua compresses prompts. The ranking, a comparison table and a playbook are below.

Best by use case

  • Agents that resend the same company context on every call: Sentra, which replaces documents with a small set of resolved facts.
  • Long system prompts and repeated context: Anthropic or OpenAI prompt caching.
  • Routing each call to the cheapest adequate model: LiteLLM, Portkey or OpenRouter.
  • Seeing where token spend goes: Helicone.
  • Compressing long prompts: LLMLingua.

Where agent token spend actually goes

Before choosing a tool, measure. In most production agents, the bill is dominated by input tokens, not output. Three patterns cause it.

  • History stuffing. The whole conversation or task log is resent on every turn, so cost grows with every step.
  • Retrieval bloat. RAG pipelines resend large chunks on every query, often several versions of the same fact.
  • Overpowered models. Every call goes to the most capable model, including classification and formatting steps a smaller model handles fine.

Each tool below attacks one of these. The largest and most durable saving comes from shrinking what the agent reads, because it compounds across every call.

Why are my LLM API costs so high?

When an LLM bill climbs faster than usage, the cause is almost always one of seven patterns. Each has a published number behind it, so check them in this order before buying anything.

  • Output costs five times input. On Anthropic's published price list, Claude Opus 5.5 is $4 per million input tokens and $20 per million output tokens, and Sonnet 5.5 is $2 and $10. Thinking tokens bill as output, so long reasoning on every call is the most expensive habit an agent can have.
  • Agents resend their context on every turn. A multi-step agent pays for its history again at each step, so input dominates the bill. In Sentra's Terminal-Bench 2.1 evaluation, adding a memory layer cut input tokens by 52.1% while output tokens fell by only 13.0%, which shows where the waste sits.
  • The wrong default model. Anthropic's own Claude Code documentation says unexpectedly high spend "usually traces back to long sessions that were never cleared or to Opus left as the default model."
  • A new tokenizer. Anthropic notes that Claude 4.7 and later models use a tokenizer that produces approximately 30% more tokens for the same text, so a migration can raise cost with no change in prompts.
  • Cache misses. Anthropic's default cache lives five minutes, and OpenAI's in-memory cache lasts roughly 5 to 10 minutes of inactivity. The first call after a break reprocesses the full context at the full price.
  • Multi-agent fan-out. Anthropic reports that Claude Code agent teams use approximately 7x more tokens than standard sessions when teammates run in plan mode.
  • Long context that does not pay for itself. Bigger windows are billed per token, and they do not buy accuracy: the Lost in the Middle study (Liu et al., TACL) found performance degrades when the relevant fact sits in the middle of a long input, and Chroma's Context Rot report found all 18 models it tested grew less reliable as input length grew.

The pattern across all seven is the same. Most of the money pays for context the model has already seen. That is why the ranking below starts with the tool that sends less context, and only then moves to discounting, routing and compression.

The best tools to reduce LLM token costs, compared

  • Sentra. Replaces resent documents and history with resolved facts. Sentra reads the company's tools, stores each fact once with its time, source and permissions, and gives agents only the facts a task needs over REST and MCP. On Terminal-Bench 2.1 the Sentra-enabled agent scored 88.31% mean reward against an 83.37% baseline while cutting model cost by 72.6% and tokens by 41.2%. Because the memory is shared, every agent in the company benefits from facts resolved once.
  • Anthropic prompt caching. Caches a stable prompt prefix, such as system instructions or a large document, so later calls read it at a fraction of the normal input price. Cache reads are billed at a tenth of the base input rate on most Claude models and a twentieth on Opus 5.5, which makes it the single easiest saving for agents with long fixed instructions.
  • OpenAI prompt caching. Applies automatically to repeated prompt prefixes on supported models and bills cached input tokens at a discount, with no code changes.
  • LiteLLM. An open-source gateway that puts one API in front of more than 100 model providers, with routing, fallbacks, caching and per-team budgets. The standard choice for teams that want cost controls they host themselves.
  • Portkey. A managed AI gateway with routing, semantic caching, budgets and observability across providers.
  • Helicone. Open-source LLM observability that logs every request with its cost, so you can see which agent, user or prompt drives spend, plus response caching.
  • OpenRouter. One API for hundreds of models with provider routing, useful for sending low-stakes steps to cheaper models without separate contracts.
  • LLMLingua. Microsoft Research's prompt compression method, which removes low-information tokens from long prompts and reports compression of up to 20x with limited loss on its benchmarks.
  • Anthropic context editing and compaction. Context editing, in beta, clears old tool results and thinking blocks server-side once the context passes a threshold you set, and reports how many input tokens it cleared (platform.claude.com). Server-side compaction summarizes older conversation context as a conversation approaches the context window limit.
  • GPTCache. An MIT-licensed semantic cache from Zilliz that turns queries into embeddings and serves a stored answer when a new query is close enough to an earlier one, integrated with LangChain and LlamaIndex (github.com).
  • RouteLLM. An Apache-2.0 framework from LMSYS for serving and evaluating LLM routers, with an OpenAI-compatible server. Its trained routers report cutting cost by up to 85% while keeping 95% of GPT-4 performance on MT Bench (github.com).
  • vLLM. An Apache-2.0 inference and serving engine for self-hosted models, with PagedAttention, continuous batching, prefix caching and quantization formats including FP8, INT8, INT4, GPTQ and AWQ, behind an OpenAI-compatible API (github.com).

Comparison: how each tool cuts cost

ToolHow it cuts costWorks onAccuracy effectOpen sourceBest for
SentraSends resolved facts instead of documents and historyAll input context about the companyImproves it, 88.31% vs 83.37% on Terminal-Bench 2.1No, managed with VPC and on-prem optionsAgents working on company knowledge
Anthropic prompt cachingDiscounts repeated prompt prefixesStable instructions and documentsNoneNative API featureLong fixed system prompts on Claude
OpenAI prompt cachingDiscounts repeated prompt prefixes automaticallyStable prefixesNoneNative API featureRepeated prefixes on OpenAI models
LiteLLMRouting, caching and budgetsEvery call through the gatewayDepends on routing choicesYesSelf-hosted cost control
PortkeyRouting, semantic caching and budgetsEvery call through the gatewayDepends on cache thresholdsGateway is open source, managed productManaged gateway with caching
HeliconeVisibility into spend, plus cachingEvery logged callNoneYesFinding where the money goes
OpenRouterRoutes steps to cheaper modelsEvery call through the APIDepends on model choiceNoMixing models without separate contracts
LLMLinguaCompresses long promptsLong prompts and retrieved textSmall loss at high compressionYesLong prompts that cannot be shortened by design
Anthropic context editingClears old tool results and thinking blocksLong agent sessions on ClaudeDepends on what is clearedNative API feature, betaTool-heavy agents with growing context
GPTCacheServes cached answers to similar queriesRepeated or near-duplicate questionsDepends on similarity thresholdYesHigh-volume question answering
RouteLLMRoutes easy queries to cheaper modelsEvery call through the routerDepends on router thresholdYesTeams training their own router
vLLMCheaper self-hosted inference through batching, prefix caching and quantizationSelf-hosted open modelsDepends on quantization levelYesHigh-volume workloads on your own GPUs

LLM cost optimization best practices: a playbook

  • Measure first. Put Helicone or your gateway's logging in front of every agent and find the top three prompts by spend. Most teams find one or two prompts carry the majority of the bill.
  • Shrink the context. Replace resent history and retrieved chunks with a memory layer that sends resolved facts. This is the step with the largest saving: on Terminal-Bench 2.1 the Sentra-enabled agent used 41.2% fewer tokens at 72.6% lower model cost, and scored 88.31% against an 83.37% baseline.
  • Cache what must be resent. Anthropic charges 1.25x the base input price to write a five-minute cache and 0.1x to read it on most models (0.05x on Opus 5.5 and Sonnet 5.5), and says caching pays off after a single read. OpenAI discounts cached input by up to 90% automatically on prompts over 1,024 tokens.
  • Batch anything that can wait. Anthropic and OpenAI both discount batch requests by 50%, OpenAI completes batches within 24 hours, and Anthropic's batch and caching discounts stack.
  • Route by difficulty. Send classification, extraction and formatting to smaller models through LiteLLM, Portkey or OpenRouter. The RouteLLM study (UC Berkeley and LMSYS) cut cost by over 85% on MT Bench while keeping 95% of GPT-4's quality, and FrugalGPT (Stanford) reports matching GPT-4 with up to 98% lower cost on its benchmarks.
  • Compress what is left. Apply LLMLingua to long prompts that cannot be restructured.
  • Set budgets. Enforce per-team and per-agent limits in the gateway so cost stays visible.

Context window optimization for agents

Context window optimization means controlling which tokens reach the model on each call. Agents need it more than chat apps, because tool outputs, logs and retrieved text pile up with every step. These are the techniques, from the one that removes the most tokens to the one that only moves them.

  • Replace raw context with resolved facts. Instead of resending documents, messages and retrieved chunks, give the agent short, sourced facts about the people, accounts and projects in the task. This is how Sentra works, and its MCP server caps search at 20 results per call so one call cannot flood the context. Sentra for agents: the MCP server and API explains the mechanism behind the Terminal-Bench 2.1 result.
  • Clear finished tool output. Old tool results are usually the largest block in an agent's context. Anthropic's context editing clears them server-side once input passes a threshold, and its clear_at_least setting avoids clearing so little that the lost cache costs more than the saved tokens.
  • Summarize or compact old turns. Keep recent turns in full and replace older ones with a summary. Anthropic's server-side compaction does this automatically near the context limit, and /compact does it in Claude Code.
  • Keep a sliding window. For chat-style agents, send only the last several turns plus a summary of the rest.
  • Cap output. Set max_tokens per step to what the step needs, since output is billed at five times input on Claude.
  • Place what matters at the start or end. This saves no tokens, but the Lost in the Middle study found models use facts in the middle of a long input least reliably.

Watch the interaction with caching. Anything that changes an earlier part of the prompt, including clearing tool results, invalidates the cached prefix after that point, so clear in large steps rather than on every call.

How much does it cost to run Claude Code for a team?

Anthropic publishes the numbers. Across enterprise deployments, Claude Code averages around $13 per developer per active day and $150 to $250 per developer per month, and 90% of users stay below $30 per active day. Spend above that range usually has one of the causes above: long sessions that were never cleared, Opus left as the default, or verbose tool output flowing into the context.

  • Clear between tasks with /clear, which costs nothing, and use /compact with instructions when you want to keep continuity.
  • Keep CLAUDE.md under 200 lines and move workflow-specific instructions into skills, which load only when needed.
  • Default to Sonnet 5.5 for most coding, reserve Opus 5.5 for hard reasoning, and set simple subagents to Haiku.
  • Disable MCP servers you are not using, lower effort for routine work, and use hooks to trim large logs before they reach the model.
  • Give the team shared memory so each session starts with the repository's conventions and decisions already resolved, instead of every engineer re-teaching them. Sentra Code Memory does this for coding agents.

For plan prices and seat costs, see the Claude Code pricing guide; this section covers usage cost only.

Where Sentra is not the best fit

Sentra is not the best fit if your cost comes from one prompt template called many times with little company context. Prompt caching and model routing cut that cost without adding a system.

How we compared

We grouped each tool by how it cuts cost: sending less context, discounting repeated context, routing to cheaper models, measuring spend, or compressing prompts. Prices and features come from each vendor's documentation, linked in each section. Sentra's figures come from its published Terminal-Bench 2.1 evaluation. Anthropic context editing, GPTCache, RouteLLM and vLLM were added on 5 November 2026 and checked against their own documentation and repositories that day.

How to choose

  • Your agents resend company documents and history on every call: Sentra.
  • Your agents carry long, fixed instructions: prompt caching from Anthropic or OpenAI.
  • You need routing, fallbacks and budgets across providers: LiteLLM, self-hosted, or Portkey, managed.
  • You do not yet know where the spend goes: Helicone.
  • You want many models behind one API: OpenRouter.
  • You have long prompts that cannot be restructured: LLMLingua.

Frequently Asked Questions

How do I reduce LLM token costs at scale?

Send less context first, by replacing resent history and retrieved chunks with a memory layer, then cache what must be resent, route easy steps to smaller models, and set budgets. The first step usually saves the most.

What drives the cost of running AI agents?

Mostly input tokens: history, instructions and retrieved documents resent on every call. Output tokens and model choice matter, but context size is the largest lever.

What is the most cost-effective way to give an AI agent long-term context?

A memory layer that stores resolved facts and sends only what a task needs. Sentra's Terminal-Bench 2.1 result shows 72.6% lower model cost with higher accuracy than the baseline agent.

Does prompt caching reduce costs for agents?

Yes, for the parts of the prompt that repeat exactly. Anthropic bills cache reads at a tenth of the base input rate on most models and a twentieth on Opus 5.5 and Sonnet 5.5, and a cache write pays for itself after one read. It does not help with context that changes on every call, which is where a memory layer helps.

How do I cut context window cost without losing accuracy?

Replace raw context with resolved facts rather than truncating it. Truncation loses information; a memory layer keeps the facts and drops the repetition.

Why are my LLM API costs so high?

Usually because the agent resends context it has already seen: history, instructions and retrieved documents on every call. The other common causes are output-heavy reasoning (output costs five times input on Claude), an expensive default model, cache misses after idle periods, and multi-agent fan-out.

What are the best practices for LLM cost optimization?

Measure spend per prompt, shrink the context with a memory layer, cache what must repeat, batch anything that can wait for a 50% discount, route easy steps to smaller models, compress long prompts, and set per-team budgets. The context step usually saves the most.

How much does it cost to run Claude Code for a team?

Anthropic reports an average of around $13 per developer per active day and $150 to $250 per developer per month across enterprise deployments, with 90% of users under $30 per active day. Plan and seat prices are separate.

What are the best ways to reduce Claude token cost for engineering teams?

Clear sessions between tasks, keep CLAUDE.md short, default to Sonnet 5.5 with Opus reserved for hard problems, turn on prompt caching, and give the team shared code memory so conventions are resolved once rather than re-read in every session.

How do I optimize RAG costs for a production AI app?

Send fewer, better tokens. Deduplicate chunks, cache the stable parts of the prompt, and for facts that change over time, replace chunk retrieval with a memory layer that returns the current fact instead of every version of it.

What is the difference between semantic caching and prompt caching?

Prompt caching, from Anthropic and OpenAI, discounts a repeated prompt prefix, and the model still runs on every call. Semantic caching, such as GPTCache, skips the model call entirely when a new query is similar enough to one already answered. Prompt caching never changes the answer. Semantic caching can return a stale or wrong answer if the similarity threshold is too loose.

Does a larger context window improve LLM output?

Not by itself. Longer inputs cost more per call, and the Lost in the Middle study and Chroma's Context Rot report both found models grow less reliable as input length grows. Sending fewer, more relevant tokens usually improves both cost and accuracy, which is what Sentra's Terminal-Bench 2.1 result shows.

What is context window optimization?

Controlling which tokens reach the model on each call: replacing raw context with resolved facts, clearing finished tool output, summarizing old turns, capping output length and placing key facts where the model attends best.

Should I quantize or self-host models to cut cost?

Only at high, steady volume. Engines such as vLLM make self-hosted inference cheaper through batching, prefix caching and quantization, but you take on GPUs and operations. For most agent workloads, shrinking context and routing easy steps to smaller API models saves more for less effort.

Which Sentra is this?

Sentra at sentra.app is an organizational memory layer for teams and AI agents. It is unrelated to Sentra.io, the data security company.