59API

← Voltar aos guias

How Tokens Are Counted: A 40% API Savings Example

Preços · EN · 2026-10-14

What are tokens, and why do they affect your bill?

Tokens are the units an AI model processes when reading your request and generating its response. A token might represent a whole word, part of a word, punctuation, or whitespace. Tokens are not the same as words, characters, or bytes.

For ordinary English prose, one token is roughly four characters, or about three-quarters of a word. That makes 1,000 tokens approximately 750 words. These are planning estimates, not billing rules: code, URLs, identifiers, emoji, and different languages can produce very different counts.

Most text API pricing separates input tokens from output tokens. Input is what the model receives; output is what it generates. Because output often costs more per token, controlling response length can save more than trimming the same number of tokens from a prompt.

How tokens are actually counted

Each model uses a tokenizer to split text into token IDs. Different tokenizers can count the same text differently, so a GPT estimate should not be treated as an exact Claude count.

A context window is a capacity limit, not a free allowance. A model supporting a large context can still charge for every billable token you send.

Calculate a request cost with concrete numbers

Use this formula: cost = input tokens ÷ 1,000,000 × input rate + output tokens ÷ 1,000,000 × output rate. Apply any cache or other pricing categories separately when relevant.

Suppose a model costs $1 per million input tokens and $5 per million output tokens. These are illustrative rates, not a quoted 59API price. A request with 2,000 input tokens and 500 output tokens costs:

Now reduce input to 1,200 tokens and output to 300 tokens. The cost becomes $0.0012 + $0.0015 = $0.0027 per request, or $27 for 10,000 requests. That is an $18 saving, or 40%, assuming unchanged rates and request volume.

Measure usage before optimizing

Run 20–50 representative requests and record the model, task, token usage, latency, and result quality. OpenAI-style responses commonly report prompt_tokens, completion_tokens, and total_tokens in usage. Anthropic-style responses use fields such as input_tokens and output_tokens, with additional cache fields where applicable. Check the actual response format your endpoint returns.

For streaming requests, ensure your client captures usage when supported. Treat tokenizer estimates as forecasts and provider-reported usage as the billing reference. Cached tokens may be a subset of another count or a separate category; follow the endpoint's accounting rules rather than blindly adding every field.

Four practical ways to spend less

Choose a low-cost API without sacrificing model quality

59API offers low-cost, pay-as-you-go access to native, official-quality Claude and GPT models without downgraded substitutes. It is compatible with Claude Code, Codex, and OpenAI SDKs; its API base URL is https://api.59api.com.

Compare current per-model rates, check caching support, and benchmark your real workload. Its referral rebate can provide additional savings under the applicable terms. Consider signing up for 59API and testing a small batch before moving production traffic.

Preços · Docs

Pronto para começar?

Conecte Claude e GPT em minutos pelos menores preços, sem cortes. Cadastre-se e obtenha sua chave API.

Cadastro grátis