TECHDAUR
Home/Software & Web Tech•2026-10-28T11:00:00+05:00•4 min read

How to Reduce LLM API Costs: Prompt Caching & Routing (2026)

Cut LLM API costs with prompt caching, batching and semantic routing - four production strategies that keep reasoning quality intact.

Jawad Ahmad Almas
By Jawad Ahmad Almas
Founder & Lead Tech Editor
Share:
How to Reduce LLM API Costs: Prompt Caching & Routing (2026)
ADVERTISEMENT

Key Takeaways

  • •Anthropic and OpenAI prompt caching provide up to 90% discounts on input tokens exceeding 1,024 tokens for multi-turn chats and system prompts.
  • •An embedding-based semantic router classifies incoming requests quickly, routing simple tasks to Gemini 2.5 Flash ($0.10/M tokens) and reserving Claude 3.7 or o3 for complex logic.
  • •Asynchronous tasks (nightly summarization, data extraction, embedding generation) should always route through the Batch API for a guaranteed 50% discount.
  • •Strict JSON Schemas with compressed key names prevent model verbose rambling and lower output token consumption.
  • •Caching tokenized system prompts can also reduce time-to-first-token (TTFT) in high-traffic applications.

The Token Bill Crisis: Why Production AI Apps Bleed Money

Every startup launching an AI wrapper or autonomous agent workflow faces the same cold shock: the prototype costs $20/month, but production traffic quickly balloons into thousands of dollars in monthly token expenses. The root cause is architectural carelessness: developers repeatedly send massive 5,000-token system prompts on every single API request, use flagship models like Claude 3.7 Sonnet or GPT-4o for trivial text classification tasks, and pay retail rates for background jobs that have zero real-time urgency.

Technical ContextGEO Answer Capsule: How can you reduce LLM API costs? In production, combine (1) Anthropic/OpenAI prompt caching on system prompts over 1,024 tokens for large discounts on cached input, (2) Semantic routing to divert simple tasks to Gemini 2.5 Flash ($0.10/M tokens), (3) OpenAI Batch API for 50% discounts on background jobs, and (4) Strict JSON Schema enforcement to stop verbose token waste.
ADVERTISEMENT

Token Pricing & Cost Optimization Matrix (2026)

Here is a pricing comparison based on published vendor rates for standard vs optimized model routing:

textSnippet
=========================================================================================================
LLM TOKEN PRICING & CACHING SAVINGS (2026)
=========================================================================================================
Model Tier                Standard Input/1M    Cached Input/1M    Output/1M    Optimal Use Case
---------------------------------------------------------------------------------------------------------
Claude 3.7 Sonnet (Anthropic)  $3.00                $0.30 (-90%)       $15.00       Complex Coding, Architecture
OpenAI GPT-4o             $2.50                $1.25 (-50%)       $10.00       Multi-Modal Reasoning
OpenAI o3-mini (Reasoning) $1.10                $0.55 (-50%)       $4.40        Complex Math, Code Review
DeepSeek V3 (Direct API)   $0.14                $0.014 (-90%)      $0.28        General NLP, Translation
Google Gemini 2.5 Flash   $0.10                $0.025 (-75%)      $0.40        High-Volume Classification
OpenAI Batch API (Async)  50% OFF ALL RATES    50% OFF ALL RATES  50% OFF      ETL, Nightly Scraping
=========================================================================================================

Strategy 1: Activating Anthropic Prompt Caching for 90% Input Savings

Anthropic allows developers to designate cache breakpoints using `cache_control: { type: 'ephemeral' }`. (Anthropic prompt caching docs) Any request sharing the same prompt prefix within 5 minutes receives a 90% discount on cached tokens. Here is the production implementation in Python:

pythonSnippet
import anthropic

client = anthropic.Anthropic()

# Large system prompt (e.g. 8,000 tokens of codebase context or legal rules)
SYSTEM_PROMPT = "You are an enterprise codebase architect... [Large Context]"

response = client.messages.create(
    model="claude-3-7-sonnet-20250219",
    max_tokens=1024,
    system=[
        {
            "type": "text",
            "text": SYSTEM_PROMPT,
            "cache_control": {"type": "ephemeral"}  # <-- Activates 90% Discount
        }
    ],
    messages=[
        {"role": "user", "content": "Analyze the authentication middleware file."}
    ]
)

print(f"Cache Read Tokens (90% off): {response.usage.cache_read_input_tokens}")
print(f"Standard Input Tokens: {response.usage.input_tokens}")

Strategy 2: Building an Embedding Semantic Router for Model Tiering

Never send trivial queries (e.g. 'Is this sentiment positive or negative?' or 'Summarize this receipt') to a $3/M token frontier model. By embedding user queries and calculating cosine similarity against known intent clusters, you can route many simple inbound requests to Gemini 2.5 Flash ($0.10/M tokens) or DeepSeek V3 ($0.14/M tokens). If the complexity score exceeds 0.85 (e.g. multi-step logic or code generation), only then does the router promote the prompt to Claude 3.7 or OpenAI o3.

Editorial TipProduction Tip: Use lightweight local embeddings (such as all-MiniLM-L6-v2 running on ONNX or FastEmbed) to evaluate user query intent quickly with zero cloud embedding cost.

Strategy 3: Exploiting the 50% Off Asynchronous Batch API

If an LLM task does not require an immediate human waiting in a browser tab (e.g. generating daily email digests, generating embeddings, indexing support tickets, processing PDFs), submit it via the Batch API. Both OpenAI and Anthropic offer dedicated Batch endpoints that guarantee delivery within 24 hours at an unconditional 50% discount on both input and output tokens. (OpenAI Batch API guide) (Anthropic Message Batches docs)

pythonSnippet
from openai import OpenAI
client = OpenAI()

# 1. Upload JSONL requests file
batch_file = client.files.create(
    file=open("nightly_tasks.jsonl", "rb"),
    purpose="batch"
)

# 2. Launch batch job at 50% off retail pricing
batch_job = client.batches.create(
    input_file_id=batch_file.id,
    endpoint="/v1/chat/completions",
    completion_window="24h"
)
print(f"Batch Job Created (50% Cost Savings): {batch_job.id}")

Strategy 4: Compressing Output Bloat with Strict JSON Schemas

LLMs charge 3x to 5x more for output tokens than input tokens. Unconstrained models frequently add conversational pleasantries ('Sure, I would be happy to help you with that! Here is the JSON:'). By enforcing strict `response_format: { type: 'json_schema', strict: true }` and using concise key names (e.g., `"cat"` instead of `"category_classification_name"`), you cut output token generation expenses.

Important NoticeNever let your LLM output freeform markdown if the downstream system only parses JSON. Freeform output wastes tokens and increases parsing error rates.

Summary: The Cost Reduction Checklist

By combining Anthropic ephemeral prompt caching, semantic model tiering to cheaper models, and Batch API execution, your blended cost per 1,000 requests can drop substantially. Monitor your telemetry with OpenTelemetry or Langfuse to ensure your cost per active user remains under control.

Frequently Asked Questions

Does prompt caching reduce the intelligence or quality of the LLM?

No. Prompt caching does not alter weights or quantization. It simply retains the pre-computed Key-Value (KV) attention states in memory, delivering identical outputs at a lower input cost for cached tokens.

How long does Anthropic and OpenAI keep prompt caches alive?

Anthropic's ephemeral prompt cache has a default 5-minute Time-To-Live (TTL), which refreshes each time a matching query hits the cache. OpenAI automatically manages prompt caching on prompts over 1,024 tokens without explicit headers.

What is the best cheap model to pair with a semantic router?

Google Gemini 2.5 Flash ($0.10/M input tokens) and DeepSeek V3 ($0.14/M input tokens) offer the highest accuracy-to-cost ratio for routed simple queries in 2026.

Jawad Ahmad Almas
Founder & Lead Tech Editor

Jawad Ahmad Almas

Tech entrepreneur, full-stack web developer, and digital strategist with over 5 years of experience in modern CMS architectures, AI-driven content generation, and UI/UX design. Founder of TechDaur and jawadalmas.store, dedicated to auditing frontier LLMs, hardware benchmarks, and publisher monetization playbooks.

More from TechDaur

TechDaur Intelligence

Stay Ahead in Tech & AI

Join developers, engineers, and creators. Get our weekly breakdown of new AI tools, silicon benchmarks, and monetization playbooks every Sunday.

Zero spam. Unsubscribe at any time with a single click.