Keeping Your AI Costs Under Control in Production
Practical tips for reducing inference costs in agentic AI architectures- from token management and model routing to caching and tool configuration on AWS.
I see companies launching their agentic workloads to production, and many times immediately after launch they notice the cost is more than they planned for.
There are several cost multipliers in agentic architectures that aren't obvious at design time. Here are the tips I share with teams to keep costs under control.
I'm sure you're already familiar with some of these, but I hope you'll find it useful.
Output tokens cost 2-6x more than input tokens
If you're building AI apps, you're paying per token. One token is roughly 0.75 words. Simple enough.
One important thing to note- output tokens cost 2-6x more than input tokens. The response your agent produces is the most expensive part of the call. Not the context you sent in. The words it generates back.
And if you never explicitly set a limit on response length, your model will happily generate 500 words when 50 would do. On every single request.
To address this, add an instruction to your system prompt: "Keep your response under 150 words unless the user explicitly asks for more detail." Set the max_tokens parameter on every API call. This can reduce output costs by 20-50% and takes about an hour to implement.
And while you're at it- use structured outputs. Instead of asking the model to respond in free-form prose, define a JSON schema for the response. The model returns only the fields you need, in the format you need them. No padding, no extra sentences, no pleasantries. Structured outputs typically cut output tokens by 30-70% compared to free-form text for the same information content.
Set session-level token budgets
Setting max_tokens on individual calls is a good start, but it doesn't protect you from the total cost of a session. A user chatting with your agent for 20 turns, each within the per-call limit, can still accumulate a large bill.
Set a total token budget per user session. For example- 200,000 tokens maximum per session. When you approach 80%, switch the agent into a more economical mode (shorter responses, cheaper model, compressed context). When you hit 100%, end the session gracefully and tell the user they can start a new one. You can tier these budgets by plan- free users get 50K, premium users get 500K. This makes your per-user costs predictable and forecastable.
Non-English languages cost more tokens
LLM tokenisers are optimised for English. When you process text in other languages, the same sentence requires significantly more tokens to encode. Hebrew can be 2-3x more tokens than English for the same content. Japanese can be 2-8x. Korean is about 1.4-2.4x. Arabic, Hindi, Thai- roughly 3-4x.
And you don't always know which language your users will end up using. Your customers might be based in the UK, but the specific person interacting with your AI feature might be more comfortable in a different language. They'll switch naturally, and your cost model shifts with them.
If you're building a product that serves customers in multiple languages, your English cost modelling is wrong. A Japanese user session can cost 3x what an English session costs for the exact same interaction.
What to do about it? First- decide which languages you actually support. Don't just accept any input and hope for the best. Use a lightweight language detection model at the boundary and either restrict to supported languages or at minimum set different token budgets per language.
Second- consider having your model reason in English internally (cheaper tokens) and only translate the final response to the user's language. Not always appropriate, but for straightforward tasks it works well and cuts costs significantly.
Reduce tools per agent to cut system prompt size
Let me explain this one.
Every tool you attach to an agent- every MCP server, every API definition- gets injected into the system prompt on every single LLM call. A single tool with its name, description, and parameter schema can add 100-500 tokens. Attach 30 tools and you're adding 3,000-15,000 tokens of overhead to every request.
Now think about an agent that loops 10 times to complete a task. That's 30,000-150,000 tokens just describing tools the agent probably won't even use on that particular request.
The principle is simple: give each agent only the tools it actually needs for its specific task. Split monolithic agents into specialists. A routing agent with 3 tools figures out what the user wants, then dispatches to a billing agent with 5 tools, or a support agent with 5 tools. Each specialist carries a fraction of the overhead.
If you're on AWS, look at AgentCore Harness with Skills- it lets you load tools on demand rather than attaching everything permanently. And AgentCore Gateway gives you centralised MCP management so you can filter which tools each agent sees at the infrastructure level.
Use MCP servers instead of web search
For internal data- databases, APIs, internal docs- implement MCP servers or Knowledge Bases designed for agents rather than having the agent search the web or learn how to interact with each and every internal resource.
An MCP tool call to your own API returns exactly the structured data the agent needs. No parsing, no wasted tokens on irrelevant results, no retry loops.
For external searches- agents can search the web, but it's much more efficient to have them search via a dedicated search MCP like Tavily. A purpose-built search MCP returns clean, structured results directly, rather than the agent having to parse raw HTML and reason over noisy snippets. That's easily the difference between 500 tokens and 5,000-15,000 tokens per lookup.
Route simple tasks to cheaper models
Not every task needs your most expensive model.
Classifying a user's intent ("is this a billing question or a support question?") does not require Claude Opus. Extracting a name and email from a form does not require frontier reasoning. For 60-80% of production queries, a model costing $0.04-0.25 per million tokens does the job as well as one costing $3-15.
Set up three tiers. Cheap models for classification and extraction. Mid-range for summarisation and standard Q&A. Premium for complex reasoning only. Use the cheap model to classify the request, then route to the appropriate tier.
A note on future-proofing: New models come out every few weeks. Prices drop, quality improves, and the model that was your best option three months ago might not be anymore. Build a model evaluation pipeline early. Define your KPIs- accuracy, latency, cost per request- and run new models against them regularly. This way, when a cheaper model hits the market that meets your quality bar, you can swap it in with confidence rather than guessing.
The teams that save the most long-term aren't just the ones who pick the right model today. They're the ones who built the pipeline to continuously re-evaluate.
Use AgentCore Gateway to control what goes into the context window
Even after splitting agents into specialists, you might still have multiple MCP servers per agent. Each one adds its full set of tool definitions to the context window on every request.
AgentCore Gateway sits between your agents and your MCP servers. It aggregates tools from multiple MCP targets behind a single endpoint- but crucially, it lets you filter which tools each agent actually sees. The agent only receives tool definitions for the tools it's allowed to use, not everything behind the gateway.
It also supports semantic search over tools. Instead of loading all tool definitions into the context window upfront, the agent can search for the right tool using a natural language query via a built-in
x_amz_bedrock_agentcore_search tool. The gateway returns only the relevant tools for that specific task. This is especially useful when you have dozens or hundreds of tools- the agent starts lightweight and loads tool definitions on demand.Fewer tool definitions in the context window = fewer tokens billed on every single LLM call in the agent loop.
Use Harness Skills to load instructions on demand
Here's a pattern I see a lot: a system prompt packed with detailed instructions for every possible task the agent might handle. Instructions for billing queries, support tickets, refund processing, escalation procedures- all stuffed into one prompt that gets sent on every request, even when the user just asked a simple FAQ.
AgentCore Harness with Skills lets you break this up. Define each set of instructions as a separate skill. The agent starts with a minimal base prompt. When it identifies that it needs a specific skill (e.g., the user is asking about refunds), it loads that skill's instructions dynamically.
This means you're only paying for the prompt tokens that are actually relevant to the current request. A simple FAQ answer doesn't carry 3,000 tokens of refund processing instructions. This adds up fast across thousands of daily requests.
Set stop conditions to cap agent loops
An agent loop without limits can burn through a significant chunk of your budget quickly. The agent tries to answer a question, keeps calling tools that return unhelpful results, and just... keeps going. No limit. No circuit breaker.
What helps here is setting stop conditions:
- Maximum turns per workflow (e.g., 10 turns for a support agent, 25 for a complex research agent)
- Token threshold triggers- at 80% of budget, compress context and switch to a cheaper model. At 95%, stop and return the best answer you have so far
- Tool call limits- cap total tool invocations per session
You can also use stop sequences at the API level- these are character strings (e.g.,
</answer> , \n\nDone ) that tell the model to stop generating immediately once it's delivered the relevant content. This prevents unnecessary follow-up text from inflating your output tokens.These aren't cost optimisations in the traditional sense. They're guardrails. They prevent unexpected spikes from becoming a problem.
Use prompt caching and semantic caching
Two types of caching matter here.
Prompt caching- Bedrock stores the computation state of your system prompt so it doesn't have to reprocess it on every call. Since your system prompt is identical across requests, you're paying for redundant computation on every single invocation without it. Enable it. It takes a day and saves 34-90% on repeated prompt prefixes.
Semantic caching- if users keep asking variations of the same question (and they do- customer support is extremely repetitive), cache the answers and serve them without calling the LLM at all. This eliminates calls entirely for cache hits.
Prune context windows as conversations grow
Your agent passes the full conversation history on every turn. Turn 1 is 500 tokens. Turn 5 is 2,000 tokens. Turn 10 is 3,500 tokens. Every turn gets more expensive than the last.
Bedrock now offers server-side compaction (currently on Claude models)- it automatically summarises older context when you approach the token limit. Zero integration code. Just enable it. For other models, implement rolling summarisation- keep recent turns, summarise older ones with a cheap model, drop anything low-value.
35-50% input token savings on long conversations.
Monitor and attribute costs per feature
All of the above works best when you have visibility into where your tokens are going. Log the cost of every LLM call- which agent made it, which feature triggered it, which user session it belongs to, how many input and output tokens it consumed, and whether it hit a cache.
With this data, you can spot the one agent that accounts for 40% of your bill, or the one feature whose system prompt grew from 500 tokens at launch to 3,000 tokens six months later.
Set budget alerts at 50%, 75%, and 90% of your daily spend. Configure automated throttling- when a feature hits 90% of its daily budget, switch it to a cheaper model or enable aggressive caching automatically. This turns cost management from a monthly surprise into an operational control.
Where I'd start
If I had to pick a few things to look at first, I'd suggest:
- Set max_tokens on every call
- Enable prompt caching
- Restrict your language support
- Reduce your tool surface area
- Add stop conditions
From there, model routing, semantic caching, and the AgentCore Gateway / Harness setup can make a big difference too- but the list above is a good starting point.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article