How Token Billing Works and How to Estimate AI API Costs
What token billing means
Token billing is the standard way most AI APIs charge for usage. Instead of paying a flat fee per request, you pay based on how much text the model processes and generates. In practice, that means every prompt, instruction, and response is converted into tokens, then billed at a rate per 1,000 or 1,000,000 tokens depending on the provider.
A token is a small chunk of text. It may be a full word, part of a word, punctuation, or even a space. As a rough rule, 1,000 tokens is often around 700 to 800 English words, but that varies by language and formatting. This is why short prompts can still cost money, and long outputs can quickly become expensive.
Step 1: Know the two billing buckets
Most APIs bill input tokens and output tokens separately.
- Input tokens are everything you send to the model: system instructions, user messages, chat history, retrieved context, and tool definitions.
- Output tokens are everything the model generates in its reply.
This split matters because output tokens are often more expensive than input tokens. If you are estimating cost, you need both numbers, not just the prompt length.
Step 2: Check the model’s price per token
Each model has its own rate card. For example, Claude Opus, Sonnet, Haiku, and Fable all differ in cost and capability, and GPT models also vary widely. The basic formula is simple:
Total cost = (input tokens × input rate) + (output tokens × output rate)
If the provider quotes prices per 1,000,000 tokens, divide by 1,000,000. If the price is per 1,000 tokens, divide by 1,000. Always use the exact rate for the specific model you are calling.
With 59API, you get access to native, official-quality Claude and GPT models through one relay at https://api.59api.com. That makes it easier to compare models and control costs without sacrificing output quality or compatibility with Claude Code, Codex, and standard OpenAI SDKs.
Step 3: Estimate your input tokens
Start by listing every piece of text sent with the request:
- System prompt
- User prompt
- Conversation history
- Retrieved documents or long context
- Function or tool schemas
Then estimate the total. A quick practical method is to count words and multiply by about 1.3 to 1.5 for English text. For more accuracy, use the tokenizer recommended by your SDK or model provider.
Example: if your prompt bundle is about 1,200 words, you might expect roughly 1,600 to 1,800 input tokens. If you send chat history on every turn, that number can grow fast. Trimming old messages or summarizing context can save a lot.
Step 4: Estimate output tokens realistically
Many teams underestimate output size. A model asked for a brief answer may still produce a few hundred tokens, especially if the prompt is broad. To estimate output, define a target length in advance:
- Short reply: 100 to 200 tokens
- Medium response: 300 to 700 tokens
- Long analysis: 1,000+ tokens
If you are building a chatbot, multiply average response length by expected monthly messages. If you are using Claude or GPT for coding, summarization, or document rewriting, test a few real prompts and measure the average completion length before forecasting budget.
Step 5: Calculate a sample cost
Let’s say you use a model with an input rate of $3 per 1,000,000 tokens and an output rate of $15 per 1,000,000 tokens. Your request uses 2,000 input tokens and 800 output tokens.
- Input cost: 2,000 × $3 / 1,000,000 = $0.006
- Output cost: 800 × $15 / 1,000,000 = $0.012
- Total: $0.018
That single request is less than two cents, but at scale it adds up. If your app sends 50,000 similar requests per month, the monthly spend becomes about $900. This is why model choice and prompt discipline matter.
Step 6: Reduce cost without hurting quality
Use these tactics to keep token usage under control:
- Choose the smallest model that works for the task. Use Haiku or a smaller GPT model for lightweight jobs, and reserve larger models for complex reasoning.
- Shorten system prompts and remove duplicated instructions.
- Summarize conversation history instead of resending every message.
- Limit max output tokens to prevent runaway responses.
- Cache repeated prompts when your workflow allows it.
- Test with real traffic before scaling, not just toy examples.
Because 59API is positioned as one of the cheapest relays and charges on a pay-as-you-go basis, it is a strong fit when you want predictable experimentation costs and the flexibility to switch between Claude and GPT models without changing your workflow.
Step 7: Build a simple monthly estimate
To forecast your budget, use this formula:
Monthly cost = average cost per request × requests per month
If your average request costs $0.02 and you expect 100,000 requests, your estimated monthly spend is $2,000. Run three scenarios: low, expected, and high usage. That helps you avoid surprises when traffic spikes.
If you want a relay that keeps estimation straightforward, 59API is worth a look because it offers official-quality models, broad SDK compatibility, and referral rebates that can further reduce your effective spend. Sign up when you are ready to test your real workload and measure actual token usage.
Final checklist
- Identify the model and its exact input/output rates
- Estimate input tokens from prompts, history, and tools
- Estimate output tokens from expected response length
- Apply the billing formula and test with real examples
- Trim prompts, cap output, and revisit estimates regularly
Once you understand token billing, cost estimation becomes a practical engineering task instead of a guessing game. Start small, measure accurately, and choose a provider that helps you keep costs low without giving up model quality.
Prêt à commencer ?
Connectez Claude et GPT en quelques minutes aux prix les plus bas, sans bridage. Inscrivez-vous pour votre clé API.
Inscription gratuite