LLM API Cost Accounting: From Unit Pricing to Comprehensive Selection
Selecting LLM API channels by merely comparing listed unit prices for tokens often leads to incorrect conclusions. This article outlines a practical approach to accurate API cost accounting. It explains how to build a comprehensive unit price model weighted by actual input and output token ratios and cache hit rates, and analyzes the cost structures of different access channels to guide effective model selection.
1. Relying Solely on Listed Prices Leads to Flawed Selections
LLM APIs are typically billed by token, with input and output priced separately, and the output unit price generally being higher than the input. The listed price for the same model can vary across channels due to factors such as intermediate reselling, regional deployment, tiered pricing, package bundles, or recharge discounts. Therefore, directly comparing the unit price lists of two channels often leads to incorrect conclusions.
Common comparison errors in engineering generally fall into three categories:
- Inconsistent Units: Some channels price per million tokens, others per API call, and some prices may include taxes while others do not.
- Inconsistent Versions: Models with the same name may correspond to different versions, context length tiers, or deployment regions, making their performance and pricing not directly comparable.
- Inconsistent Consumption Structures: The input-output token ratio varies significantly across different business use cases. When this ratio changes, the overall ranking of comprehensive costs can completely reverse.
Therefore, before selection, you need to unify the pricing of all channels to the same standard and perform a weighted calculation using the actual consumption structure of your business.
2. Establishing a Comprehensive Unit Price Model
The core idea is to weight the input and output prices based on the actual token proportions of your business to determine a comprehensive unit price per million tokens:
Comprehensive Unit Price = s_in × P_in,eff + s_out × P_out
Here, s_in and s_out represent the proportions of input and output tokens to the total, respectively, and their sum equals 1. P_in,eff is the effective input price considering caching, calculated as:
P_in,eff = (1 − h) × P_in + h × P_cache
h represents the cache hit rate, and P_cache is the input price when a cache hit occurs. For channels that do not offer cache billing, you can set P_cache equal to P_in.
Derive Input/Output Ratios from Logs
These ratios should not be guessed based on experience. Multi-turn conversations and agent tasks repeatedly carry historical context, so the input proportion is usually much higher than in single-turn Q&A. Conversely, tasks like code generation or long-form writing may have a higher output proportion. These ratios should be derived from statistical results of production call logs and categorized by task type, as the optimal channel may differ across tasks.
Explicitly Record Currencies and Exchange Rates
When comparing across currencies, convert them uniformly to a single currency and explicitly record the exchange rate and the date it was taken. Exchange rate fluctuations and price adjustments can both alter the ranking conclusions. Without these two pieces of information documented, the conclusions cannot be verified.
3. Understanding Channel Cost Structures
Based on the access method, common LLM channels can be divided into four categories.
1. Direct Connection to Model Providers
Direct connection pricing is given directly by the provider. The settlement link is the shortest, and the documentation is typically the most complete. However, the downside is that each provider requires separate integration, resulting in higher adaptation costs when switching between multiple models.
2. Cloud Platform Hosting or Resale
Cloud platforms provide unified consoles, billing, and quota management, facilitating centralized procurement and access control for enterprises. The pricing may differ from direct connections. It is essential to verify whether regional surcharges, minimum spending limits, resource package deduction rules are included, and whether higher quota tiers are required for high-concurrency scenarios.
3. Aggregator Routing Gateways
Aggregator gateways connect to multiple upstream models using a unified protocol, making model switching and disaster recovery easier. Their pricing is influenced by upstream pricing, platform markups, recharge policies, and billing granularity. You need to confirm whether billing is based on the actual number of tokens used and whether failed requests are also billed.
4. Self-Built Proxies or Private Deployment
Self-built solutions shift costs from token-based billing to compute, storage, and operational costs. When call volume is large and stable, the unit cost may be lower. However, fixed costs must be amortized based on equipment utilization; in low-load scenarios, this approach can actually be more expensive.
