Prompt and Context Optimization

Since you pay for every input token, the fastest way to cut the cost of a call without changing the model is to send fewer tokens — and most production prompts are carrying far more than they need.

Once you have right-sized the model, the next lever is the size of each call. You pay for every input token, so a prompt and context carrying twice the necessary tokens costs twice as much on input, on every single request, forever. This fourth post in the AI cost optimization series is about spending fewer input tokens per call — trimming prompts, pruning context, and controlling output — without losing the quality those tokens were buying. It is context engineering viewed through the cost lens.

The prompt is a recurring cost, so trim it

The system prompt and instructions are present on every call, which means every wasted token in them is paid on every request across your entire traffic. That makes prompt bloat one of the most quietly expensive things in an AI system, and one of the easiest to fix. Long, rambling instructions; redundant restatements; verbose examples that a shorter example would match; boilerplate that no longer earns its place — all of it multiplies out across millions of calls.

Trimming is not about being terse for its own sake; it is about removing tokens that do not change the output. A prompt that says the same thing in half the tokens costs half as much on that portion of every call, with identical behavior. Review prompts specifically for cost: for each section, ask whether it measurably improves results, and cut what does not. Fewer, higher-quality examples often beat many mediocre ones on both quality and cost.

Context is where the tokens hide

The system prompt is usually the smaller problem. The larger one is the dynamic context: conversation history, retrieved documents, and tool definitions, all of which can dwarf the prompt and all of which grow. The techniques from the context engineering discipline are, seen through this lens, cost optimizations:

Each of these is a token reduction on the largest, fastest-growing part of the input. For agent and RAG systems, context optimization typically dwarfs prompt trimming as a source of savings — go where the tokens are.

Control the output side too

Input is only half the bill. Output is often priced higher per token, so controlling generated length is a direct saving. Ask for the response you actually need: if downstream code uses three fields, request three fields, not an essay. Constrain format and length explicitly in the prompt (“answer in one sentence,” “return only the JSON”), because a model left to its own verbosity will often generate far more than the task requires. For tasks with heavy internal reasoning, consider whether that reasoning depth is warranted for this task or whether a lighter approach suffices — reasoning tokens are billed even when unseen. Concise, well-specified output requirements cut the output half of the cost while usually making the result easier to consume.

Optimize without degrading quality

The trap in all of this is cutting tokens that were actually doing work. A prompt line that seemed like boilerplate may have been preventing a failure mode; a retrieved chunk that seemed marginal may have contained the answer for a subset of queries. So token reduction, like model routing, must be validated against an evaluation. Cut, then measure that quality held on representative cases. When it holds, you have a pure win — same behavior, lower cost. When it drops, you have learned those tokens were load-bearing and should stay. This measure-as-you-cut loop is what separates cost optimization from quality erosion.

The compounding payoff

Token reduction has a compounding quality that makes it especially worth the effort: the savings apply to every call, and they stack with everything else. A leaner context is cheaper on a cheap model and cheaper on an expensive one; it makes caching more effective (less to cache, more hits); it speeds up responses (fewer tokens to process). Unlike a one-time fix, trimming the recurring per-call token count pays out on every request for the life of the feature, across all your traffic. It is often the highest-return work available after model selection, precisely because it is recurring and universal.

Key takeaways

Further reading

Sources & References

Why less, better-placed context helps