Understanding Token Billing in the LLM Era: Input vs. Output Costs and Optimization
This article breaks down how token billing works for large language models, using a viral community pun as a starting point. It explains what tokens are, why input and output tokens are priced separately, how to build a cost model, and how to choose between lightweight and high-performance model tiers. You will also find six common sources of wasted spend, a practical optimization checklist, and guidance on observability and cost governance using general cloud capabilities on Baidu AI Cloud. The goal is to turn vague "it feels expensive" impressions into measurable, controllable engineering decisions.
1. Starting With a Community Pun: A Technical Topic in Disguise
A naming trend has recently appeared in developer communities: some people jokingly call a lightweight model tier the “common whale,” a high-performance tier the “ultimate whale,” output tokens “whale coins,” and input tokens “whale gulps.” The reason this pun spread quickly is that, at very low cognitive cost, it captures the two most sensitive engineering issues in LLM applications: choosing a model tier and the input/output token billing structure.
Setting the entertainment wrapper aside, the joke maps to a rigorous technical and cost framework. Rather than focusing on any specific product, this article treats the topic as a general engineering problem: how to understand tokens, how to distinguish input from output, how to model and optimize cost, and how to build observability and governance on a cloud platform such as Baidu AI Cloud using general-purpose cloud capabilities.
2. What a Token Actually Is: The Unit of Model Metering
A token is the basic unit a large language model uses to process text. It is not equivalent to a Chinese character or an English word. It is a discrete unit produced after a piece of text is split by a tokenizer, and it may be a character, a word, an affix, or even a punctuation mark.
A schematic view of the tokenization logic looks like this:
# Pseudocode: basic flow of tokenization and token countingtext = "token cost optimization for LLM applications"tokens = tokenizer.encode(text)print(len(tokens)) # output the number of tokens
Three general points are worth emphasizing:
- The token count for the same text is not fixed. It depends on the tokenizer and vocabulary used by a specific model.
- Token density varies significantly across Chinese, code, JSON, and mixed multilingual text. For the same number of characters, the token count can differ by several times.
- Tokens are the shared metering basis for both billing and the context window. They affect cost and also the upper limit on how much the model can “see” and “write.”
3. Input Tokens vs. Output Tokens: Why “Gulps” and “Coins” Are Counted Separately
Calling input “whale gulps” and output “whale coins” is vivid, but it also captures the key point: input and output are two different kinds of load.
- Input tokens include the system prompt, the user question, conversation history, retrieved document fragments from RAG, tool return values, and more. They determine the context length during inference and directly affect GPU memory usage, time to first token, and total computation.
- Output tokens are the content the model generates autoregressively, token by token. Generation cannot be completed in a single pass; it requires repeated forward computation, so the compute cost per unit of output is typically much higher than per unit of input.
This is why the industry generally adopts separate pricing for input and output, with the output unit price usually higher than the input unit price. The engineering mental model to build is this: optimizing input is the first lever for cost control, and limiting output length is the second.
4. Cost Modeling: Turning “It Feels Expensive” Into a Formula
A practical cost estimation framework looks like this:
cost per request = input tokens × input unit price + output tokens × output unit pricedaily total cost = Σ(cost per request) + supporting resource costs (retrieval/storage/logging, etc.)
Supporting resources cannot be ignored either. Common general-purpose cloud product categories include object storage (for corpora and results), message queues (for peak shaving), container platforms (for hosting inference and business services), and logging plus monitoring and alerting (for tracking token consumption and failure rates).
A simplified budget example (numbers are illustrative only and are not any vendor’s pricing):
Assumptions: 1000 input tokens/request, 300 output tokens/request, 10,000 requests/dayTotal input = 1000 × 10000 = 10 million tokens/dayTotal output = 300 × 10000 = 3 million tokens/dayCost focus: output volume is smaller but the unit price is higher, so it needs separate governance
5. Choosing a Model Tier: Dividing Work Between Lightweight and High-Performance
The “common whale” and “ultimate whale” joke reflects the general engineering practice of model tiering:
| Scenario characteristics | Recommended tier | Reason |
|---|---|---|
| Intent recognition, classification, extraction, format conversion | Lightweight | Simple tasks, throughput first, cost sensitive |
| Complex reasoning, long-form writing, code generation | High-performance | Needs stronger generalization and instruction following |
| High-concurrency online Q&A | Mostly lightweight + fallback routing | Balances latency and cost |
| Offline batch processing | Split by task difficulty | Balances throughput and quality |
The recommended approach is to build a routing layer: handle requests with the lightweight tier first, then escalate to the high-performance tier when confidence is low or the task is complex, achieving a dynamic balance between quality and cost.
6. Six Common Sources of Wasted Cost and How to Fix Them
- Overly long system prompts: keep them concise, deduplicated, and structured; avoid carrying large blocks of instructions on every request.
- Sending full conversation history: use a sliding window, summary compression, or key-information extraction.
- Too many retrieved fragments: cap the number of recalled items and fragment length, and rerank before concatenation.
- No output limit: set a reasonable maximum output length to prevent the model from diverging.
- No caching for repeated requests: introduce semantic caching for high-frequency, stable Q&A.
- Missing metering and alerting: without monitoring and alerting in place, cost overruns go unnoticed.
A corresponding general optimization checklist:
- Prompt templating + version management- Context compression and summarization- Reranking and truncation of retrieval results- Output length constraints and structured output- Semantic caching + result reuse- Token metering instrumentation + budget alerts
7. Observability and Cost Governance: Making Every Token Traceable
Log a structured record for each call, with fields including at least: request ID, model tier, input token count, output token count, latency, cache hit or not, and business scenario tag. Then use a logging service for aggregate analysis, and use monitoring and alerting to set daily budget thresholds and anomaly notifications.
A schematic log structure:
{"request_id": "r-1001","tier": "light","input_tokens": 1024,"output_tokens": 256,"latency_ms": 820,"cache_hit": false,"scene": "faq"}
With this data, teams can finally answer the key questions: which scenario consumes the most tokens? Which tier offers the best cost-performance ratio? Is the cache hit rate on target? Governance shifts from “going by feel” to “looking at data.”
8. Implementation on Baidu AI Cloud: A General Capability Combination
When building LLM applications on Baidu AI Cloud, you can combine general-purpose cloud product categories: use a container platform to host business and inference services, object storage to accumulate corpora and results, a message queue for asynchronous processing and peak shaving, and logging plus monitoring and alerting for token metering and cost warnings. Model tiers and billing details should be based on the official documentation and real-time pricing; this article does not cite any unconfirmed specific parameters.
9. Conclusion: Engineering Rationality Behind the Pun
The “common whale,” “ultimate whale,” “whale coins,” and “whale gulps” are fun because they translate an abstract billing model into a tangible everyday metaphor. But for developers, what really matters is the engineering rationality behind it: understand tokens, separate input from output, choose model tiers deliberately, compress context systematically, and build metering and alerting. Only by putting this method into practice can you sustain predictable cost and stable quality in real workloads where high concurrency and long text coexist.
