How to Cut LLM API Costs During the Price Hike Wave
As major language model providers raise API prices, engineering teams need a systematic way to keep spending under control. This article breaks down where API costs actually come from, then walks through practical levers: prompt caching to make repeated input nearly free, tiered model orchestration that assigns planning, execution, and review to different model sizes, batch and asynchronous pipelines that trade latency for lower prices, context and output compression, and cost observability built around cost per task rather than per-token price. It also covers how to use free tiers and trial resources appropriately, and closes with a deployment checklist. Most teams can reduce cost per task by an order of magnitude within weeks without sacrificing output quality.
1. The Cost Logic Behind the Price Hikes: Know Where the Money Goes
LLM APIs are typically billed per input token and per output token, and output tokens usually cost more because they are generated autoregressively, one token at a time. This is the starting point for any optimization: every cost-reduction technique is essentially doing one of three things — reducing the total number of tokens, increasing the reusable portion of the input, or shifting expensive generation onto a cheaper path.
The cost of a typical request can be abstracted as:
Cost = (T_in × P_in) + (T_out × P_out)where T_in is input tokens, T_out is output tokens, and P is the price per token
In scenarios like AI coding assistants and batch document processing, T_in is often much larger than T_out, and the input is highly repetitive (the same system prompt, the same batch of code context, the same set of tool definitions). This means the main battlefield for cost optimization is the input side, and the biggest waste on the input side is paying twice for the same content.
2. Prompt Caching: Turn Repeated Input into Zero Cost
Most inference services offer context caching: when a request prefix exactly matches previous requests, those tokens can be reused and are typically billed at a significant discount, with some platforms not charging for the cached portion at all. To take full advantage of this, the key is to put stable content first and variable content last.
The recommended layered request structure is:
[ Global system prompt / tool definitions ] ← constant, cached long-term[ Project conventions / repository summary ] ← changes infrequently[ Conversation history ] ← changes moderately[ Current user input ] ← changes every time
Practical guidelines:
- Do not insert timestamps, random IDs, or request sequence numbers into the system prompt; a single change invalidates the entire prefix cache.
- Keep tool and function definitions in a stable order, and avoid dynamic additions or removals that cause prefix drift.
- Place variable content at the end of the conversation, and append historical turns as-is without rewriting them.
- Before going live, send two consecutive requests with fixed input and compare the cache-hit fields to verify the hit rate meets expectations.
On the engineering side, you can normalize prefixes at the gateway layer and feed the cache hit rate into monitoring and alerting as a core metric. An abnormal drop in the hit rate usually means a template was changed or the cache expiration policy shifted.
3. Tiered Model Orchestration: Planning, Execution, and Review Each Do Their Job
Models of different sizes vary significantly in cost-effectiveness: large models are strong at planning but expensive, mid-sized models execute reliably with high throughput, and small models are well suited to format validation and extraction. Splitting tasks into layers is the most effective architectural approach to reducing cost.
# Example: three-stage tiered orchestrationplan = call_large_model(system=PLAN_PROMPT, user=task) # decomposition only, output structured stepssteps = parse_steps(plan) # validate step legalityresults = []for s in steps:results.append(call_mid_model(system=EXEC_PROMPT, user=s)) # batch execution, can run concurrentlyfinal = call_mid_or_small(system=REVIEW_PROMPT, # review as a fallbackuser=build_report(results))
The key points: the planning stage uses few tokens and is called infrequently, so using an expensive model keeps total cost under control; the execution stage involves a large volume of tokens, so hand it to a model with better cost-effectiveness; the review stage produces short output, so a small model can handle consistency checks. If the execution model “lacks initiative,” do not let the model decide the next step on its own — have the planning layer output a fully deterministic sequence of steps, confining uncertainty to the cheapest layer.
4. Batching and Asynchrony: Trading Latency for Price
Most cloud platforms offer batch or offline inference channels that accept asynchronous submission with result polling or callbacks. The price is usually lower than real-time calls, at the cost of response latency shifting from seconds to minutes. This suits scenarios like log analysis, batch document summarization, code repository scanning, and offline evaluation.
Real-time path: user request → synchronous inference → return directlyOffline path: task enqueued (message queue) → batch submission → results written to object storage → callback notification
Combined with concurrency control and retry backoff, this can significantly increase throughput and smooth out peaks, avoiding duplicate charges caused by rate limiting.
5. Context and Output Compression: Cut Tokens Directly
- Retrieval side: use vector retrieval instead of stuffing in everything, keep only the Top-K fragments, and apply deduplication and reranking.
- Structure side: convert long documents into a summary plus a table of contents with on-demand expansion, avoiding a full input all at once.
- Output side: constrain the output format (JSON Schema, fixed templates) and prohibit leaking the reasoning process to reduce ineffective generation.
- Conversation side: compress history with rolling summaries, keeping decision conclusions rather than verbatim records.
{"schema": "steps[]", "max_steps": 8, "fields": ["action", "target", "expect"]}
Structured constraints both reduce output tokens and make downstream parsing more stable, reducing the secondary cost of failed retries.
6. Cost Observability: No Measurement, No Optimization
It is recommended to log the following for every call: model tier, input/output tokens, cached token volume, task success rate, and cost per task. Use cost per task rather than per-token price as the north star metric, drill down by business line, scenario, and model tier, connect to logging and monitoring with alerting, and set budget thresholds with automatic downgrade policies (automatically switch to a lower-tier model or the offline queue when over budget).
7. Using Free and Trial Resources Correctly
Platforms usually offer free quotas, trial resource packages, or sandbox environments, which are suitable for capability evaluation and regression baselines. It is recommended to use free quotas for: prompt template regression testing, cache hit rate verification, and A/B comparison of tiered orchestration. Production traffic should be isolated through budgets and rate limits to avoid mixing evaluation traffic into production billing.
8. Deployment Checklist
- First normalize the input prefix to push the cache hit rate high.
- Set up three-tier model routing: high tier for planning, mid tier for execution, low tier for validation.
- Route all offline tasks through the batch channel.
- Make retrieval and context compression routine, and enforce structured output.
- Build a cost-per-task dashboard with budget circuit breakers.
- Re-run the model selection evaluation every quarter; both prices and capabilities change, so the routing table needs to be updated accordingly.
By following this path, most teams can reduce cost per task by an order of magnitude within weeks while keeping quality under control — the key to cost reduction is not finding a single cheaper model, but routing every type of token through the channel that best matches its value.
