LLM API Cost Optimization: A Dual-Model Workflow in Practice
This article explains why LLM API spending often exceeds budget and how a dual-model workflow fixes it. You will learn how to split work into decision-heavy and execution-heavy tasks, assign a strong reasoning model to planning and a lightweight model to implementation, and keep quality under control with Git and automated checks. It also covers cost observability, context management, and a practical rollout checklist.
1. The Problem: Why Token Usage Always Blows the Budget
A common frustration when building with LLM APIs is the gap between the planned budget and the actual bill. A typical case: a small project budgeted at 50 yuan ends up costing close to 1.3 times that amount. The post-mortem usually shows the issue is not unit price but call structure — the most expensive, most capable reasoning model is used for nearly every step, including large amounts of mechanical code writing, formatting, and simple refactoring.
From a cost standpoint, the token consumption of a development task splits roughly into two categories:
- Decision consumption: requirement breakdown, module partitioning, interface design, edge-case confirmation. This is a small share of total usage but demands the highest reasoning capability.
- Execution consumption: batch code generation against an agreed plan, adding comments, local rewrites. This often exceeds 70% of total usage, yet is technically simple and highly repetitive.
When both categories run on the same model tier, the cost curve is inevitably dominated by the expensive model. That is the root cause of the overrun.
2. The Core Approach: Strong Model for the Plan, Lightweight Model for Execution
The fix is to assign model tiers by task type, forming a dual-model workflow:
- Use the high-capability model during design to produce the module list, data structures, interface contracts, and implementation order.
- Once the plan is approved, switch to a lightweight, fast model that inherits the context and implements the code according to that plan.
The key is automatic context handoff: when switching modes, the prior conversation and plan content are inherited directly, with no manual copy-paste, so the execution phase does not drift from the agreed design.
A typical workflow looks like this:
[Requirement description]↓ High-capability model (plan mode)[Module plan / interface contracts / task sequence]↓ Human approval (the only human checkpoint)↓ Automatic context handoff[Lightweight model (build mode) batch implementation]↓[Unit tests + Git commit]
The benefits run both ways: calls to the high-capability model are compressed to single digits, while the execution phase that drives most of the consumption is handled by the low-cost model. Because the execution phase no longer needs to repeatedly “think,” response latency drops noticeably and overall waiting time shrinks. In practice, two full days of planned work can be finished in about a day and a half.
3. Why Many Teams Hesitate to Use Lightweight Models
The concerns are mostly about quality risk, and there are three main ones:
- Code correctness risk: lightweight models are more likely to produce syntax errors or miss branches in complex logic.
- File corruption risk: editing existing files may drop content or overwrite the wrong sections.
- Rework cost concerns: manual fixes may cost more time than the money saved.
These concerns are legitimate, but the conclusion they point to is not “don’t use it” — it is “build the safety net first.” The vast majority of lightweight-model errors are detectable and revertible, not hard-to-spot semantic defects. With version control and automated checks in place, rework cost stays minimal.
4. Required Risk Control: Treat Git as Infrastructure, Not an Option
In a dual-model workflow, version control is not a best practice but a prerequisite. The recommended minimum:
# Initialize a local repositorygit initgit add .git commit -m "chore: initial commit"# Commit as soon as a small module is done, creating the smallest revertible unitgit add src/module_agit commit -m "feat: complete module A"
Three supporting rules:
- Small commits: use “one verifiable small module” as the commit granularity; avoid accumulating large changes.
- Validate before committing: use type checks, static analysis, or unit tests as the gate so errors surface before the commit.
- Fast rollback on anomalies: when file content looks wrong, revert to the previous commit instead of letting the model patch repeatedly.
Check fails → locate with git diff → git checkout -- <file> → reissue a more explicit instruction
It is worth stressing that the execution model should receive clearly constrained instructions (specify file paths, limit the scope of changes, require existing interfaces to stay unchanged). This saves more tokens than fixing things after the fact.
5. Cost Observability: Measure First, Then Optimize
Cost optimization has to be built on observability. Track four dimensions continuously: number of requests, total tokens, input-to-output token ratio, and average consumption per module. Only with this data can you tell whether an optimization actually worked rather than relying on gut feeling.
A general cost estimation model:
Total cost ≈ Σ(input tokens × input price) + Σ(output tokens × output price)Optimization levers: ① reduce the share of expensive-model calls ② compress repeated context ③ raise the completion rate per task
Compressing repeated context is the most overlooked: carrying history back and forth in a long conversation makes input tokens grow linearly. Opening separate sessions per module and converging context promptly often saves more than switching models.
For cloud deployment and team collaboration, the chain can be rounded out with general cloud capabilities: object storage for build artifacts and datasets, a message queue to decouple long-running tasks, a container platform to host the runtime, and logging plus monitoring alerts with thresholds on call volume and failure rate so abnormal consumption is never unnoticed.
6. Rollout Checklist
- Are decision-heavy and execution-heavy tasks separated, each with an assigned model tier?
- Is plan approval the only human checkpoint, avoiding frequent intervention during execution?
- Is a local repository set up with commits per small module?
- Is automated validation configured before each commit?
- Are request count, token volume, and per-module cost recorded?
- Are alert thresholds set for context length and call volume?
7. Conclusion
Cost governance for LLM APIs is essentially a structured match between capability and price: concentrate strong reasoning on a few key decisions, let low-cost high-speed capability handle repetitive execution, and use version control plus automated checks to hold the quality floor. The method relies on no vendor-specific features, applies to most AI coding tools and model service combinations, and can be carried into team-level development workflows for repeated reuse.
