Optimizing LLM API Costs: A Dual-Model Plan/Build Development Practice
This article explains why LLM API bills often exceed budget and how to fix the problem by matching model capability to task complexity. It introduces a Plan/Build workflow that pairs a high-reasoning model for planning with a lightweight model for execution, along with reusable cost-control methods, engineering guardrails such as Git and minimal verification loops, and the key takeaway that cost savings come from alignment rather than cheaper models.
1. Background: Why API Costs Often Exceed Expectations
A common pattern in LLM API-based development is that a project starts with a budget, but the final bill comes in noticeably higher. The cause is usually not the per-token price, but the call structure: high-capability, high-price models are used for a large volume of low-complexity tasks.
In one month of actual usage, requests to the high-capability model approached 2,800, consuming about 673 million tokens; the lightweight model handled about 1,000 requests and about 314 million tokens. Of 70 CNY topped up, 64 CNY had been consumed. The original plan was to finish the project within 50 CNY, but that was not enough. The turning point came in the last two days: switching the main execution model to the lightweight model, with the high-capability model responsible only for solution design, improved both efficiency and spending at the same time.
This case illustrates a general rule: Cost = Σ(task complexity × model price × number of calls). What really needs optimization is not the unit price, but how well task complexity matches model capability.
2. Core Approach: Plan/Build Two-Phase Model Division
2.1 Pattern Design
In the interface of intelligent coding tools, there are usually two types of working modes: one oriented toward solution planning (read-only, focused on reasoning and decomposition), and one oriented toward execution (able to write files and run commands). Binding these two modes to models of different capability tiers creates a low-cost collaborative structure:
- Planning phase: use a high-reasoning model to output feature module breakdowns, interface contracts, and data structure designs;
- Execution phase: use a lightweight, fast model to code and make changes according to the established plan;
- Context synchronization: when switching from planning to execution, the plan content is carried over automatically, with no manual copy and paste.
The workflow can be described schematically as follows:
Requirements → [Plan: strong reasoning model] → Plan confirmation (human review) → [Build: lightweight model] → Small commits → Verification↑ ↓└──── On error, return to the plan layer for correction ─┘
2.2 Why This Division Works
The value of a strong reasoning model is concentrated in high-uncertainty steps: resolving requirement ambiguity, dividing module boundaries, and designing exception paths. These steps involve few calls but high value per call. The value of a lightweight model is concentrated in low-uncertainty steps: writing template code from clear instructions, batch renaming, and adding test stubs. These steps involve many calls and long contexts, and are the main source of token consumption.
Mixing the two means having the high-price model take on a large amount of mechanical work; layering them naturally shifts the token budget toward the low-price side. In practice, the most direct effect is reduced waiting time: a full load of work that originally took two days was completed in a day and a half.
3. Reusable Cost-Control Methods
- Set the budget before choosing models: convert the budget into a total available token amount, then work backward to a daily call limit.
- Set limits by phase: allow the high-price model in the planning phase, default to the lightweight model in the execution phase, and avoid “casually using the strong one.”
- Compress context: feed in only files relevant to the current module to keep unrelated code out of the context.
- Commit in small steps: commit immediately after each small module is completed, which reduces both the size of each change and the cost of rework.
- Review the call structure: regularly check request counts and token distribution to identify high-consumption sources.
4. Risks and Engineering Constraints (Important)
Lightweight models still have known issues in file-editing scenarios: they may lose fragments, produce syntax errors, or require a second reminder before correcting them. The engineering side must therefore add guardrails:
- Use a local Git repository for version control, and commit promptly after each small module is completed;
- Keep the working tree clean before making changes, so you can roll back quickly;
- Back up key files first or work on a branch;
- Establish a minimal verification loop (compile/unit test/static check) to catch errors before committing.
git init && git add -A && git commit -m "init"# After each module is completedgit add -A && git commit -m "feat: module-x done"
5. Conclusion
The key to saving money on LLM APIs is not finding a cheaper model, but aligning model capability level with task complexity. Making “strong model for the plan, lightweight model for execution” the default workflow, together with version control and automated verification, can both reduce costs and shorten the delivery cycle. If you use relevant Baidu AI Cloud products to host such applications, you can combine general capabilities such as log services and monitoring alerts to continuously observe and govern call volume and costs.
