Large Language Model API Selection and Cost Optimization: A Practical Guide
This guide explains how to choose large language model APIs based on total task cost rather than model rankings. It covers pricing structures, the hidden cost of cheap models, scenario-based capability matching, a step-by-step evaluation and routing workflow, and common pitfalls to avoid.
1. The Real Problem: Not “Which Model Is Best,” but “Which Has the Lowest Cost per Task”
When evaluating LLM APIs, many teams start by asking which model is the most capable. In engineering practice, a more useful question is: for the same business task, which combination delivers the lowest unit cost, an acceptable failure rate, and the fastest iteration speed?
The source material outlines a typical price gradient: entry-level models cost roughly RMB 0.6–0.8 per million input tokens and RMB 3.6–4.8 per million output tokens; mid-tier models cost about RMB 2.1 for input and RMB 8.4 for output; models focused on reasoning and code cost about RMB 4 for input and RMB 16–17 for output. The gap between the cheapest and most expensive is roughly 5x. That gap itself is not the problem. The problem is whether the extra spend buys capabilities the business actually needs.
Selection should therefore rest on four measurable dimensions:
- Billing structure: input and output unit prices, cache-hit policies, and batch-call discounts;
- Context window: the document size and multi-turn memory a single call can handle;
- Capability focus: Chinese generation, complex reasoning, code, multimodal, and speech;
- Ecosystem coupling: how deeply the model is tied to one platform, and the cost of migration.
2. The Cost Reality Behind Pricing
2.1 Output Tokens Are the Main Cost Driver
In most workloads, input prompts are relatively fixed after design and caching, while output length fluctuates by task. Take input at RMB 0.8 and output at RMB 4.8 per million tokens: a call with 2,000 input tokens and 1,000 output tokens costs about RMB 0.0064. Raising output to 4,000 tokens for long-form generation doubles the cost to about RMB 0.0112. This means the gains from shortening prompts are often smaller than the gains from controlling redundant output.
2.2 The Hidden Cost of Cheap Models
The lowest-priced model is not automatically the cheapest option. If a task needs several rounds of rework to pass, the cumulative call volume can erase the unit-price advantage. The more reliable engineering approach is to establish a quality baseline on a small sample, then multiply by the expected call volume to get the total task cost, rather than comparing unit prices.
Illustrative cost calculation:
def task_cost(input_price, output_price, in_tokens, out_tokens, rounds=1):per_call = (in_tokens * input_price + out_tokens * output_price) / 1_000_000return per_call * rounds# Cheap model with multiple rework rounds vs. expensive model passing in one roundlow = task_cost(0.8, 4.8, 2000, 1000, rounds=3)high = task_cost(4.0, 16.0, 2000, 1000, rounds=1)print(low, high) # Compare total task cost, not unit price
3. Match Capabilities to Scenarios Instead of Chasing Leaderboards
3.1 Chinese Content Creation
Naturalness in Chinese is the core metric for content businesses. Some entry-level models perform closer to human writing habits on Chinese corpora, making them suitable for high-frequency short-text tasks such as Q&A, notes, and marketing copy. Input prices for these tasks are very low, which allows an iterative workflow of running several revision rounds, giving strong overall value. The weakness is relatively limited complex multi-step reasoning and deep code generation.
3.2 Long Context and Agent Orchestration
Models with context windows between 128K and 1M suit long-document scenarios such as contract review, report summarization, and codebase understanding. A larger window allows more context per call, but watch for effective-context decay: recall of key information in very long inputs drops. The engineering recommendation is a layered strategy: use retrieval to narrow the scope first, then hand off to the long-window model for final reasoning.
For multi-agent orchestration, models need stable tool calling and state retention. Here, stress-test multi-turn consistency rather than judging single-turn results alone.
3.3 Multimodal and Speech
If the business involves speech synthesis, image generation, or video generation, pay attention to modality coverage and differences in billing units: speech is often billed per character, images per image, and video by duration or per clip. A solution with strong multimodal capability but a relatively independent ecosystem works best as a capability plug-in in the main pipeline, not as a replacement for all model calls.
3.4 Ecosystem-Bound Solutions
A low-cost model deeply coupled with one platform has the lowest integration cost when deploying agents inside that platform, but migration across platforms raises the rework effort significantly. During selection, assess whether the business is locked into that ecosystem long term and whether multi-vendor disaster recovery is needed.
4. A Practical Selection Workflow
- Build an evaluation set: sample 100–300 cases from real business, covering typical and edge cases;
- Define metrics: accuracy, format compliance rate, manual rework rate, and average output length;
- Run three tiers in parallel: run the same evaluation set on low-, mid-, and high-tier models;
- Calculate total task cost: unit price × token volume × rework rounds;
- Run a small-traffic canary: validate production behavior and latency with 5% of traffic;
- Set up routing: send simple tasks to the low-cost model and escalate complex tasks to the higher-capability model.
Minimal routing implementation:
def route(task):if task["complexity"] == "low" and task["lang"] == "zh":return "model_cheap"if task["need_reasoning"] or task["need_code"]:return "model_strong"return "model_mid"
5. Common Pitfalls
- Looking only at unit price and ignoring rework rate;
- Chasing the largest context window while ignoring effective recall decay;
- Treating multimodal capability as general capability, causing main-pipeline costs to spiral;
- Ignoring vendor lock-in and lacking fallback and disaster recovery plans;
- Skipping the production canary and rolling out evaluation conclusions to all traffic at once.
6. Conclusion
LLM API selection is continuous engineering work. The sound path is to account for total cost per business task, allocate capability tiers by scenario, control risk with evaluation sets and canary releases, and preserve multi-vendor routing in the architecture. If an organization already uses related cloud products from Baidu AI Cloud, it can combine their general-purpose container platform, logging service, and monitoring and alerting capabilities to build a unified model-calling gateway and cost dashboard, so selection decisions rest on observable data rather than subjective impressions.
