BlogAI Governance
AI Governance3 min read read

How to Reduce LLM API Token Costs in Production

Caching Math, Architecture, and Margin Protection When building AI software, every API call to OpenAI, Anthropic, or Google costs real money. If your application relies on multi-agent execution loops,...

By Richard Ewing·
Share:

How to Reduce LLM API Token Costs in Production

Caching Math, Architecture, and Margin Protection

When building AI software, every API call to OpenAI, Anthropic, or Google costs real money. If your application relies on multi-agent execution loops, a single user click can easily trigger 10 to 20 separate model calls.

Without a deliberate caching strategy, your cloud bill will quickly erode your unit economics.

This research note breaks down how we structured semantic caching inside Exogram.ai to cut token spend by over 50% while dramatically improving response speed for end users.

Traditional web caching matches exact URLs or exact database keys, but AI users ask questions using different words for the exact same intent.

Semantic caching generates a vector representation of the incoming query and checks whether a mathematically similar query already exists inside the cache database.

Cosine similarity scores range from 0.0 to 1.0.

0.95+ Threshold: Extremely safe for factual, transactional queries, carrying virtually zero risk of serving an irrelevant answer.

0.88 - 0.92 Threshold: Good for general intent classification, though it requires ongoing monitoring for subtle nuance loss.

Rule: Start at 0.94 and tune downward based on real user feedback.

AI context changes over time, so you should never store semantic cache entries indefinitely.

Static Context (System Rules, FAQs): 30-day TTL.

Dynamic Context (User Career Profiles, Active Workflows): 1-hour to 24-hour TTL.

Real-time State Checks: Do not cache, forcing live deterministic evaluations every time.

During an automated attack or bot scrape, malicious traffic can trigger thousands of LLM API calls per minute. Placing Cloudflare Turnstile and strict edge rate-limiting in front of your caching layer ensures that bot traffic is dropped before touching either your cache database or your LLM endpoints.

By deploying semantic caching and edge pre-filtering across our runtime:

Average Cache Hit Rate: Settled at roughly 38% across routine agent execution loops.

Cost per 1,000 Requests: Dropped from $4.20 down to $1.85.

User-Perceived Speed: Cache hits feel instantaneous, consistently returning under 20ms.

This economic buffer is what allows us to run infrastructure for Exogram.ai and CareerWin.ai efficiently without sacrificing capability or performance.

Built In: Is Anything Standing Between Your AI Agent and Your Database? (https://builtin.com/articles/ai-agent-security-gates)

Systems Infrastructure: Learn how Exogram.ai enforces runtime security and how CareerWin.ai applies context systems to career intelligence.

Join the list to receive our newest posts straight to your inbox.

Enter your email to unlock the Product Debt Index Calculator, and join the private ledger where I break down the exact strategies bridging technical execution with financial viability for B2B SaaS.

Home

Archive

Login

Reset Password

Update Password

Profile

Search

Like this analysis?

Get the weekly engineering economics briefing - one email, every Monday.

Subscribe Free →

More in AI Governance

Canonical Frameworks

Innovation Tax

The Innovation Tax is the hidden cost of maintenance work that gets reported as innovation investment. It is OpEx masquerading as R&D investment, causing organizations to dramatically overestimate their effective engineering velocity and R&D productivity. Here's how it works: A VP of Engineering reports to the CEO that "65% of engineering time is spent on new features." The actual breakdown, when forensically audited, reveals that only 23% of engineering time produces genuine new capabilities. The remaining 42% is maintenance work embedded within feature sprints - bug fixes bundled into feature stories, infrastructure upgrades coded as dependencies, and refactoring disguised as feature prerequisites. This 42-point gap between reported and actual innovation investment is the Innovation Tax. It's not fraud - it's systematic self-deception enabled by the way agile teams organize work. When a sprint contains 10 stories and 4 of them are technical debt cleanup dressed as "tech stories" within a feature epic, the team genuinely believes they're spending 100% on features. The Innovation Tax is insidious because it compounds. As the maintenance burden grows quarter-over-quarter, the tax increases. But because teams don't measure it, CFOs and boards continue to believe R&D spending is generating proportional innovation output. By the time the gap becomes visible (missed deadlines, slow feature delivery, competitive lag), the organization is often approaching the Technical Insolvency Date. Benchmarks from Richard Ewing's audits show that most engineering organizations have an Innovation Tax between 30-50%. Organizations with Innovation Tax above 40% are in dangerous territory. Above 70% is terminal - the organization is approaching technical insolvency within 4-6 quarters.

Read Definition →

Kill Switch Protocol

The Kill Switch Protocol is a structured framework for identifying and deprecating "Zombie Features" - code that requires ongoing maintenance but generates zero incremental business value. Most software organizations have a dangerous bias: they add features but never remove them. Product teams celebrate launches. Nobody celebrates deletions. Over time, this creates what Richard Ewing calls "feature gravity" - a constantly growing codebase where 40-60% of the code serves no active users and generates no measurable revenue, yet still consumes engineering maintenance hours. Zombie features come in several varieties: - **Ghost Features**: features that were built, launched, and never adopted. They sit in the codebase, requiring maintenance, but have near-zero usage. - **Legacy Bridges**: compatibility layers, deprecated API versions, and backward-compatible code paths that serve a tiny percentage of users but add complexity to every future change. - **Vanity Features**: features built because a senior stakeholder wanted them, not because users needed them. Often protected by organizational politics rather than business merit. - **Abandoned Experiments**: A/B test variants that were never cleaned up, prototypes that became permanent, and "temporary" solutions that became load-bearing. The Kill Switch Protocol provides a systematic approach to identification, evaluation, and deprecation: 1. **Identify**: Flag features with less than 5% of peak usage, zero revenue attribution, or maintenance cost exceeding 10% of the feature's value contribution. 2. **Quantify**: Calculate the total cost of keeping each zombie alive (maintenance hours × fully-loaded engineer cost × opportunity cost multiplier). 3. **Assess Risk**: Evaluate deprecation risk - what breaks if this feature is removed? What customers are affected? 4. **Sunset Timeline**: Create a communication plan and graduated deprecation (warning → deprecation notice → feature flag → removal). 5. **Execute**: Remove the code with rollback capability. Monitor for unexpected breakage. The typical Kill Switch audit reveals that 30-50% of maintenance burden comes from zombie features. Removing them frees up 15-25% of engineering capacity for actual innovation.

Read Definition →
📊

Richard Ewing

The AI Economist - Quantifying engineering economics for technology leaders, PE firms, and boards.

Want to apply this to your organization?

Run a free diagnostic first. If the numbers concern you, book a session to build a remediation plan.

Richard Ewing - AI Economist & Capital Auditor