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

    This guide explains how LLM tokens work as a billing unit, how to obtain access and credentials, and how to estimate API costs with a reusable formula. It covers six engineering techniques for reducing token usage—shorter prompts, retrieval instead of long context, context summarization, prefix-cache-friendly formatting, structured output limits, and model routing—plus the observability metrics and model selection criteria needed to keep inference spending predictable.

    1. Start With the Basics: What a Token Is and Why Billing Uses It

    Before asking how to buy tokens or what they cost, you need to be clear about the unit of measurement. A token is the smallest chunk of text a large language model processes, and it is not the same as “a character” or “a word.” In Chinese, a common character is usually split into one or two tokens; English is closer to sub-word granularity, so a longer word may be broken into several tokens. Punctuation, spaces, line breaks, and code indentation all consume tokens too.

    Billing is based on tokens rather than request count because inference cost grows roughly linearly with text length. The cost of a single request has two parts:

    1. total tokens = prompt tokens (system + conversation history + user input) + model output tokens

    The part most often underestimated is conversation history. In a multi-turn session, every turn resends all previous context to the model, so the input tokens of the 10th request are often more than ten times those of the first. When teams see higher-than-expected bills after launch, the root cause is usually not the unit price but context accumulating without limits.

    2. How to Get Tokens: From Free Quotas to Paid Billing

    The process is essentially the same for individual developers and enterprise users; the differences are mainly in quota and settlement.

    1. Sign up and verify your account. Register on a platform such as Baidu AI Cloud and complete individual or enterprise verification, which is a prerequisite for enabling model services and receiving invoices.
    2. Enable the model service. Select the model service in the console and enable it. This typically grants new users a free token quota or a short-term trial package, which is suitable for capability validation.
    3. Get access credentials. Generate an API Key and Secret Key in the console, or use the platform’s access token mechanism. Credentials should only be stored in server-side environment variables or a key management service, never in frontend code or committed to a code repository.
    4. Top up or enable pay-as-you-go. Once the free quota is exhausted, you can choose a prepaid resource package (usually a better unit price) or pay-as-you-go billing based on actual usage.
    5. Set usage limits. Configure account balance alerts and call quotas in the console so that an abnormal loop cannot drain your quota.

    Note that specific prices, free quota sizes, and discounts change dynamically with model versions and platform policies. The correct approach is to check the official billing information on the page of the model you selected rather than relying on numbers quoted by any third party.

    3. How to Calculate the Cost: A Reusable Estimation Model

    Do not guess your budget. Use the formula below to model it quantitatively:

    1. # Single-call cost estimate (illustrative; unit prices must follow the official billing page)
    2. def estimate_cost(input_tokens, output_tokens,
    3. price_in_per_1k, price_out_per_1k):
    4. return input_tokens / 1000 * price_in_per_1k \
    5. + output_tokens / 1000 * price_out_per_1k
    6. # daily cost = cost per call × daily request volume × context inflation factor
    7. daily = estimate_cost(1800, 400, 0.001, 0.002) * 5000 * 1.6
    8. print(f"Estimated daily cost: {daily:.2f}")

    Three variables matter:

    • Input and output are usually priced separately, and output is generally more expensive than input, so “making the model less verbose” is a direct way to save money.
    • The context inflation factor grows significantly in multi-turn and agent scenarios, so measure it rather than assume it.
    • Cached portions are discounted on most platforms, so a stable system prompt should be placed at the very front to maximize cache hits.

    4. Six Engineering Ways to Bring Costs Down

    1. Trim the system prompt. Remove redundant examples and repeated constraints, and split long documents into retrieval chunks injected on demand instead of stuffing the whole document into the context.
    2. Use retrieval instead of long context. Keep the knowledge base in object storage or a vector retrieval service and recall only the few most relevant passages each time, which can cut input tokens by an order of magnitude.
    3. Compress and summarize context. Apply rolling summaries to earlier conversation turns, keeping only conclusions and key entities to control history length.
    4. Write in a prefix-cache-friendly way. Put fixed content first and dynamic content last, and avoid polluting the prefix with volatile fields such as timestamps.
    5. Constrain output length with structure. Use a JSON Schema to limit fields and enums, together with a max_tokens cap, to prevent runaway output.
    1. payload = {
    2. "model": "<your-model-name>",
    3. "messages": [
    4. {"role": "system", "content": "You are a rigorous technical assistant. Output JSON only."},
    5. {"role": "user", "content": "Summarize the root cause of the anomalies in the following logs"}
    6. ],
    7. "max_tokens": 512,
    8. "temperature": 0.2
    9. }
    1. Route by tier. Send simple intent classification and format conversion to smaller models and escalate to large-parameter models only for complex reasoning; the overall bill often drops by more than half.

    5. Observability: No Monitoring, No Cost Governance

    Before launch, wire three things into your logging service and monitoring/alerting system: input and output token counts per call, cost per call and cumulative cost, and failure and rate-limit counts. Set a daily budget threshold and a period-over-period spike alert so that when an endpoint’s token consumption doubles, you can trace it to the specific caller. Also build bill attribution with tags per business line, so costs can be allocated to teams rather than lumped into a single total.

    6. Model Selection: Match the Task, Not the Leaderboard

    If you only need everyday Q&A or writing polish and have no particular style preference, a general-purpose model with moderate parameter size, solid knowledge coverage, and long-term stable availability is enough; there is no need to chase the largest size. Judge on these dimensions: accuracy on the target task, whether the context window is sufficient, response latency, rate-limit quota, and billing transparency. The most reliable method is a small blind test on 50 to 100 of your own real samples, comparing quality and cost per item before scaling up.

    7. FAQ

    • Why is the bill higher than estimated? Most likely accumulated conversation history and overly long output. Look at the token distribution before discussing unit price.
    • Can the free quota be used commercially? It depends on the platform’s terms; for commercial use, go through paid billing and the compliance process directly.
    • How do I prevent credential leaks? Keep keys server-side only, with least privilege and regular rotation.

    In short, buying tokens is buying predictable inference capacity: quantify usage first, then choose prepaid or pay-as-you-go, and finally use caching, retrieval, routing, and monitoring to keep pushing unit cost down.