DEV Community

kkkevin
kkkevin

Posted on Originally published at opshubs.space

How to Cut LLM API Costs by 70% in Production: Prompt Caching & Tiered Routing

When an AI feature moves from prototype to 10,000 daily users, API bills rarely scale linearly—they spike. Sending a 3,000-token system prompt and RAG context to a frontier model on every single request burns thousands of dollars per month unnecessarily.

Here are three battle-tested engineering patterns that routinely cut production LLM API spend by 60% to 75% without hurting answer quality—plus an interactive calculator to model your own traffic.

1. Enable Prompt Caching on Static Prefixes

Most production calls share an identical prefix: system instructions, JSON tool definitions, or few-shot examples. OpenAI, Anthropic, and Google Gemini all discount cached input tokens by 50% to 90%.

Rule of thumb: Put static instructions and schemas at the very top of your prompt, and append dynamic user queries or retrieved chunks strictly at the end so prefix cache hits stay above 70%.

2. Use Tiered Model Routing (80/20 Split)

Not every request needs a flagship reasoning model. Classify incoming traffic with a lightweight router:

  • Tier 1 (80% of traffic): Extraction, classification, summarization, and simple Q&A routed to Gemini 2.5 Flash, GPT-4o mini, or DeepSeek-V3 (often 10x–20x cheaper).

  • Tier 2 (20% of traffic): Complex multi-step reasoning, code generation, or low-confidence escalations routed to Claude 3.7 Sonnet or Gemini 2.5 Pro.

3. Cap Output Tokens (They Cost 3x–5x More)

Output tokens are priced 3 to 5 times higher than input tokens. Enforce concise JSON schemas, avoid asking the model to repeat input context, and always set explicit max_tokens bounds on background batch jobs.

Model Your Monthly Bill Before Shipping

Plug your daily requests, average input/output token counts, and expected cache hit rate into our free LLM API Token & Monthly Cost Calculator to compare OpenAI, Claude, Gemini, and DeepSeek side by side.

Considering self-hosting open-weight models instead? Check the hardware math with our vLLM & Local LLM GPU VRAM Calculator.

Originally published at OpsHubs. Found it useful? Buy us a coffee ☕.

Top comments (0)