Choosing Models for Multi-Stage Coding: Decide by Cost per Successful Run
Frontier model rankings do not tell you which model is cheapest to run successfully on multi-stage coding work. This article explains why peak capability often fails to match production fit, then shows how to tier tasks, measure strict pass rate, calculate cost per success, and route models by budget, retries, and failure cost.
1. Why the “strongest” model is not always the right model
As large models ship updates more often, teams easily treat the top of a leaderboard as the best production choice. Within a short window, several frontier models may raise context windows, multimodal inputs, and reasoning-intensity tiers. A default configuration that looked reasonable a few weeks ago can stop being economical. What needs reassessment is not which model name is newest, but which tier can finish the current task reliably at an acceptable cost.
Multi-stage coding makes this gap obvious. Unlike a single-turn question or a simple completion, one task often includes requirement understanding, solution breakdown, code generation, test repair, and edge-case handling. Failure at any step can make the final result fail. In public multi-stage coding evaluations, strict pass rates for frontier models often sit in a relatively low range. The gap between models may be only a few checkpoints, while total cost can differ by several times. Capability has entered a zone of diminishing returns, but the cost curve is still steep.
Raising reasoning intensity does not necessarily raise the success rate. Moving from a mid tier to an ultra-high tier can multiply cost without increasing the number of strict passes. It can even lower results through over-reasoning, context bloat, and self-reinforcement of a wrong path. Model selection should therefore shift from price per call to cost per successful run.
2. Build the evaluation frame: define success before talking about cost
2.1 Tier the work: do not use one model for every scenario
Start by grouping coding tasks by complexity:
| Tier | Typical tasks | Key metrics | Selection bias |
|---|---|---|---|
| L1 Lightweight generation | Comments, single-function completion, format conversion | Latency, unit price, first-pass rate | Prefer a low-cost tier |
| L2 Routine repair | Single-file bug fixes, test-case completion | Strict pass rate, retry count | Prefer a mid-cost tier |
| L3 Multi-stage work | Cross-file changes, requirement breakdown, test loops | Cost per success, human intervention rate | Route a high-capability tier only when needed |
| L4 High-risk work | Core-path refactors, complex migrations | Verifiability, rollback cost | Small-traffic canary, with human review |
The point of tiering is practical. High reasoning intensity is usually wasteful on L1 work. Looking only at unit price on L4 work can understate the cost of failure. Once tasks are tiered, each level can have its own routing rules and budget cap.
2.2 A strict pass rate is closer to production than an average score
Multi-stage coding should use a strict pass standard: hidden tests all pass, edge conditions are met, there are no compile or runtime errors, and constraints are satisfied. Average scores and partial pass rates tend to overstate capability, because production usually accepts only a usable final result. The evaluation set should cover real repository structure, dependencies, exception paths, and regression risk, and it should be updated regularly so models do not overfit public problems.
2.3 Cost-per-success formula
Cost per successful run can be defined as:
cost per success =(input tokens × input price + output tokens × output price + retry cost + tool-call cost)÷ strict success rate
The strict success rate should come from an evaluation set close to the production distribution, not from a single-turn demo. Retry cost should include resubmission after failure, context replay, human investigation, and pipeline wait time. If a task needs multiple samples or several repair rounds, combine the total consumption.
Illustrative code:
def cost_per_success(input_tokens, output_tokens,input_price, output_price,success_rate, retry_factor=1.0):single_cost = input_tokens * input_price + output_tokens * output_pricetotal_cost = single_cost * retry_factorreturn total_cost / success_rate
If model A is cheap but has a low success rate and many retries, while model B is more expensive but passes on the first try more often, the cost per success can reverse. Selection should also fold in asymmetric input and output prices, fast-tier premiums, tiered billing, and price-change windows.
3. Reasoning intensity and context windows: two knobs that are easy to misuse
3.1 Higher reasoning intensity is not automatically better
A reasoning-intensity tier trades more compute for more stable intermediate reasoning. On multi-stage coding, too much of it can cause three side effects. First, context grows quickly and both input and output cost rise together. Second, the model keeps elaborating a wrong assumption and produces a confident error. Third, a small early mistake is amplified by later reasoning in a long chain. Test mid, high, and ultra-high tiers for each task level, and record strict pass rate, average tokens, latency, and cost per success. Enable the ultra-high tier only when the gain in success rate covers the cost increase.
3.2 A long context window should not be filled by default
A million-token window is useful for large codebases, long documents, and multi-turn material, but that does not mean every request should be packed full. In practice, prefer retrieval, code slicing, dependency analysis, and summary compression, and keep only the context that is needed. Longer context raises input cost, latency, and noise. For multi-stage tasks, use staged context: the requirements stage keeps goals and constraints; the repair stage keeps failing tests and related code; final verification keeps the change summary and test results.
4. A practical workflow for selecting by cost per success
4.1 Build a small evaluation set from real work
Sample 30 to 100 tasks from production tickets, historical defects, and code repositories, covering different tiers. Keep hidden tests and acceptance criteria for each task, and fix the prompt template, tool permissions, and retry policy. During evaluation, record model tier, reasoning intensity, input and output tokens, elapsed time, failure cause, and human intervention count.
4.2 Normalize the price structure first
Billing shapes differ. Some models have a large gap between input and output prices, some double the price on a fast tier, and some change prices in stages. Before comparing, convert prices to input and output cost per million tokens, then add cache hits, volume discounts, retries, and tool-call cost. Do not compare models on a single list price.
4.3 Calculate cost per success and rank
Compute cost per success separately for each task tier. If a model is 2 percentage points more successful on L3 work but 80% more expensive, decide whether those 2 points actually reduce human intervention and rework. If they do not, do not default to the higher-cost tier. For L1 and L2 work, prefer a low-cost model first and escalate only after failure.
4.4 Design routing and fallback
A practical pattern is tiered routing with failure escalation:
L1/L2 tasks -> low-cost tier -> strict check fails -> retry on a mid-cost tierL3 tasks -> mid-cost tier -> on failure, escalate to a high-capability tier with the failing testsL4 tasks -> high-capability tier on a small canary -> human review -> full rollout requires approval
Also set a budget cap, a maximum retry count, and a circuit-breaker. If a tier fails repeatedly or cost crosses the threshold, fall back to a more stable tier or hand the task to a person instead of retrying without limit.
4.5 Close the loop with observability and governance
After launch, keep watching strict success rate, cost per success, P95 latency, retry rate, human intervention rate, and cache hit rate. In an engineering rollout, routed requests can be served through Baidu AI Cloud general model inference, with logging, monitoring and alerting, and object storage used for evaluation records and a cost dashboard. Version evaluation samples, prompt templates, model versions, and routing rules. Release them gradually and keep a rollback path.
5. Conclusion: replace the “strongest model” story with engineering metrics
Selecting a model for multi-stage coding is not about chasing the strongest label on the latest release. It is about a repeatable evaluation system: tier the work, define strict success, then decide by cost per successful run. Reasoning intensity and context windows are cost knobs, not defaults that should always be turned up. The price sheet is only the starting point; retries, failures, and human time dominate the bill. A steadier path is a small evaluation set, tiered routing, failure escalation, continuous monitoring, and versioned governance. That turns model selection from a one-time call into an engineering capability that can keep up with rapid model updates.
