LLM API Token Pricing and Billing: A Practical Guide to Buying Tokens and Controlling Costs

    This guide explains how LLM API tokens work as a billing unit, what factors drive pricing, how to purchase and activate token-based access, and how to estimate costs before launch. It also covers six engineering techniques for reducing token spend, common estimation mistakes, compliance considerations, and model selection advice for building cost-controlled LLM applications at scale.

    1. Start With the Billing Unit: What a Token Actually Is

    Before asking how to buy tokens or what they cost, you need to understand the unit of measurement. A token is the smallest billable unit of text processed by a large language model, roughly the basic unit produced when the model’s tokenizer splits text. A passage of Chinese text is typically split into several tokens, and the splitting rules for English, code, punctuation, numbers, and whitespace all differ, so character count and token count are not equivalent.

    Two billing categories are standard across the industry:

    • Input tokens (prompt tokens): the prompt you send, system instructions, conversation history, and any material retrieved and concatenated in through RAG all count as input.
    • Output tokens (completion tokens): the model’s generated response counts as output, and the per-token price is usually higher than for input.

    Some models also bill reasoning tokens (intermediate consumption used internally during the reasoning process) separately; check the pricing notes for the specific model you choose. This distinction matters: for the same question, whether you include a long context, enable multi-turn memory, or trigger a tool call can significantly change actual consumption.

    A simplified illustration of the calculation (for demonstration only, not real prices):

    1. Cost per call = input tokens × input unit price
    2. + output tokens × output unit price
    3. + possible reasoning tokens × corresponding unit price

    2. What Determines the Price

    LLM API pricing is not a single number but a combination of several dimensions:

    1. Model size and capability tier: larger models with stronger capabilities cost more per token; lightweight models suit high-throughput scenarios such as classification, extraction, and rewriting.
    2. Differentiated input and output pricing: the output side requires more computation and generally costs more per token, so output cost deserves close attention in long-response scenarios.
    3. Context window length: very long contexts put pressure on memory and compute, and costs rise noticeably for long-text scenarios.
    4. Whether cache hits are enabled: repeated prefixes that hit the cache are usually billed at a lower price.
    5. Batch and asynchronous jobs: offline batch processing is generally more economical than real-time calls and suits tasks such as data cleaning and batch summarization.
    6. Free tiers and tiered strategies: trial quotas for new users, pay-as-you-go, resource packages, and tiered pricing coexist, so choose based on your business’s traffic patterns.

    3. How to Buy and Activate Tokens

    On Baidu AI Cloud, access to LLM capabilities follows a standard flow of activate the service, obtain credentials, and pay as you go:

    1. Sign up and complete identity verification: registration and identity verification are prerequisites for activating services and issuing invoices.
    2. Activate the model service: select the model you need in the console, read and accept the terms of service, then activate it.
    3. Create access credentials: generate an API Key and Secret Key, store them securely, and never commit them to a code repository.
    4. Configure quotas and alerts: set usage limits, budget thresholds, and alert notifications to prevent losses from abnormal calls.
    5. Choose a payment method: pay-as-you-go suits fluctuating workloads; resource packages suit stable, predictable long-term load.
    6. Integrate and test: validate quality and token consumption with a small sample first, then scale up gradually.

    Illustrative call skeleton (pseudocode; refer to the official documentation for actual API fields):

    1. resp = client.chat(
    2. model="model-name",
    3. messages=[
    4. {"role": "system", "content": "You are a rigorous technical assistant"},
    5. {"role": "user", "content": user_input}
    6. ],
    7. temperature=0.3,
    8. max_tokens=1024
    9. )
    10. usage = resp.usage # prompt_tokens / completion_tokens / total_tokens

    4. Cost Estimation: Do the Math Before You Launch

    Quantitative estimation before launch is the most effective way to control budget. A four-step approach:

    1. Sample: pull 200–500 typical requests from real business logs.
    2. Measure: use the tokenizer of your chosen model to compute the input token distribution (mean, P95).
    3. Extrapolate: daily cost ≈ average daily requests × (average input tokens × input unit price + average output tokens × output unit price).
    4. Leave headroom: reserve 30%–50% margin to cover prompt iterations and long-tail requests.

    One caveat: if multi-turn conversations carry the full history every time, tokens grow roughly linearly with the number of turns, so long sessions should introduce summary compression or a sliding window.

    5. Six Engineering Techniques to Cut Costs

    • Prefix cache reuse: place fixed system instructions and knowledge base snippets at the very front of the prompt to improve cache hit rates.
    • Context compression: apply rolling summaries to conversation history, keeping only conclusions and key entities.
    • Tiered model routing: send simple tasks to lightweight models and complex reasoning to larger models.
    • Batch processing and off-peak scheduling: run offline jobs through asynchronous batch processing to avoid peak hours.
    • Output length constraints: set max_tokens explicitly and define structured output formats to reduce redundant generation.
    • Full-chain monitoring: build monitoring and alerting dashboards for token consumption, failure rate, and latency, with attribution by business dimension.

    6. Common Mistakes and Compliance Points

    • Mistake 1: estimating cost by character count. Token density varies widely across Chinese, English, code, and JSON, so measure with the tokenizer instead.
    • Mistake 2: looking only at unit price, not hit rate. Discounts from caching and compression often exceed the difference between model tiers.
    • Mistake 3: appending history without limit. The longer the context, the more cost and latency rise together.
    • Compliance points: keep credentials out of code repositories and container images; redact logs before using them for analysis; define data retention and training-use policies; set separate budgets and rate limits for each type of business.

    7. Selection Recommendations

    If your business is mainly conversational Q&A and you want stable performance, choose a higher capability tier and pair it with caching and prefix optimization. For high-concurrency, low-complexity extraction and classification, prefer lightweight models plus batch processing. For long-document understanding, focus on evaluating the context window and long-text unit price. Baidu AI Cloud offers multiple model tiers along with unified pay-as-you-go billing, budget management, and monitoring and alerting, making it easier for teams to handle selection, cost accounting, and governance within one system and deploy at scale with controllable costs.