Engineering Practices for Reducing LLM Inference Costs
This article examines why the same prompt can consume several times more resources across different models in coding and document review workflows, and argues that resource cost per completed task is the metric users actually perceive. Using a paper review comparison experiment as a starting point, it breaks down where cost differences come from: unit price multipliers, context read volume, tool call steps, and output length. It then presents a practical optimization framework covering context minimization, tool call budgets, structured output constraints, tiered model routing, and end-to-end measurement, along with illustrative code and a checklist to help developers cut per-task cost to roughly one quarter while preserving conclusion quality. No vendor pricing or specifications are involved; all multipliers are relative ratios from the author's own testing and should be recalibrated against your own business data.
In intelligent coding and document review scenarios, handing the same prompt to different models can produce several-fold differences in resource consumption. Many teams focus only on benchmark scores and overlook the fact that “how many resources does it take to get one thing done” is the metric users can directly perceive.
This article starts from a controlled experiment on paper review and breaks down the sources of cost differences: unit price multipliers, context read volume, tool call steps, and output length. It then lays out a practical optimization framework, including context minimization, tool call budgets, structured output constraints, tiered model routing, and end-to-end measurement, with illustrative code and a checklist. The goal is to help developers cut per-task cost to roughly one quarter of the original while keeping conclusion quality intact.
Note that this article does not cover any specific vendor’s pricing or parameters. All multipliers come from the author’s own testing as relative ratios, and readers should recalibrate them on their own business data.
Where the Cost Difference Comes From
Four factors drive the gap:
- Unit price multiplier: the relative per-token price of one model versus another.
- Context read volume: how much context the model has to read to complete the task.
- Tool call steps: how many tool invocations a single task triggers.
- Output length: how many tokens the model generates.
A model with a lower unit price can still end up more expensive if it reads more context, takes more steps, or writes longer outputs.
An Optimization Framework
Context Minimization
Send only the context the task actually needs, and drop everything else before the request goes out.
Tool Call Budget
Set an explicit cap on tool calls per task so a single run cannot spiral into unbounded steps.
Structured Output Constraints
Constrain the output format so the model returns only the required fields instead of free-form prose.
Tiered Model Routing
Route tasks to model tiers by difficulty, so simple tasks avoid the most expensive tier.
End-to-End Measurement
Measure cost across the whole chain rather than per call, since per-call price hides context, step, and output effects.
Illustrative Code
# Context minimization: keep only what the task needsdef build_context(docs, task):return [d for d in docs if d.relevant_to(task)]# Tool call budget: cap steps per taskTOOL_CALL_BUDGET = 5def run_task(task, context, budget=TOOL_CALL_BUDGET):steps = 0for step in plan(task, context):if steps >= budget:breakexecute(step)steps += 1return steps# Structured output constraint: request only required fieldsSCHEMA = {"verdict": "string", "score": "number", "reasons": "list"}# Tiered routing: send simple tasks to a cheaper tierdef route(task):return "cheap" if is_simple(task) else "strong"
Checklist
- Trim context to the minimum the task requires
- Set a tool call budget per task
- Constrain output with a schema
- Route tasks across model tiers by difficulty
- Measure cost end to end, not per call
- Recalibrate all multipliers on your own data
