59API

← Back to all guides

Token Billing Explained: Estimate AI API Costs

Pricing · EN · 2026-10-01

Token billing can look confusing at first, but most AI API costs follow a simple pattern: you pay for the tokens sent to the model, the tokens generated in response, and sometimes cached tokens or other provider-specific usage categories. Understanding those components lets you compare models and set a realistic budget before deploying an application.

1. Understand what a token is

A token is a small unit of text processed by a language model. A token may be a whole short word, part of a longer word, punctuation, or whitespace. Token counts are not the same as character or word counts. As a rough English estimate, four characters often equal about one token, but code, JSON, non-English text, long numbers, and unusual formatting can use substantially more.

Your input usually includes more than the latest user message. It can include the system prompt, conversation history, tool definitions, retrieved documents, and instructions from an SDK or coding assistant. In Claude Code or Codex, the total context may therefore be much larger than the visible question.

2. Separate input and output billing

Most model price sheets list separate rates for input tokens and output tokens, usually per million tokens. Input tokens cover the request. Output tokens cover the generated answer. Output rates are often higher because generation requires more computation.

Use this formula:

Total cost = (input tokens ÷ 1,000,000 × input rate) + (output tokens ÷ 1,000,000 × output rate)

If a provider lists cached-input pricing, calculate cached tokens separately using that rate. Do not assume that setting a high output limit means you will pay for the full limit. A maximum output setting is a ceiling; billing normally reflects the tokens actually generated, subject to the provider's rules.

3. Make a first estimate

Suppose one request contains 12,000 input tokens and produces 2,000 output tokens. For an illustration only, assume an input rate of $3 per million tokens and an output rate of $15 per million tokens:

Replace the example rates with the current rates for your selected model. Prices can differ between Claude Opus, Sonnet, Haiku, Fable, GPT models, and any cached-token category. Always confirm the active model and rate in your relay dashboard or documentation.

4. Measure real token usage

For a reliable estimate, send representative requests and inspect the usage data returned by the API or shown in your account dashboard. Record input tokens, output tokens, model name, and whether caching was used. Run several samples: a short request, a typical request, and a worst-case request with long history or tool output.

For OpenAI-compatible applications, usage is commonly exposed in fields such as prompt tokens and completion tokens, although exact field names can vary. Claude integrations may report input and output usage differently. Count tool results and attached text as part of the request context, and remember that streaming changes delivery format, not the underlying token calculation.

5. Estimate monthly spending

Multiply the cost of one request by expected usage:

Monthly cost = requests per day × days per month × average cost per request

For example, 500 requests per day at $0.066 each for 30 days would be approximately $990. Add a safety margin of 20% to 30% for unusually long conversations, retries, and traffic growth. Separately estimate background jobs, embeddings, moderation, and other APIs if your application uses them.

6. Reduce the bill without reducing quality

7. Use 59API for flexible model access

59API is a practical low-cost relay for developers who want pay-as-you-go access to native Claude models, including Opus, Sonnet, Haiku, and Fable, as well as GPT models. It uses the base URL https://api.59api.com, works with Claude Code and Codex, and is compatible with OpenAI SDK-based applications. Because you can choose the model per workload and avoid committing to a fixed plan, it is easier to control token costs. 59API also offers a referral rebate, which can further reduce effective spending. Check the current model rates and usage display before deploying, then sign up if the pricing and compatibility fit your project.

Pricing · Docs

Ready to get started?

Connect Claude & GPT in minutes at the lowest prices — full-power, never downgraded. Sign up to get your API key.

Sign up free