Token Billing Explained: Estimate API Costs in 10 Minutes
AI API costs become predictable once you separate input tokens, output tokens, and the number of requests your application actually makes. This quick-start guide shows you how to build a useful estimate, verify it against usage data, and avoid common billing surprises when using Claude or GPT through 59API.
1. Understand what counts as a token
A token is a chunk of text processed by a model, not necessarily a complete word. For English prose, one token is roughly four characters, but code, JSON, other languages, and unusual identifiers can tokenize differently. Use that shortcut for early planning, not final budgeting.
- Input tokens: Instructions, the user message, conversation history, retrieved documents, tool definitions, and tool results sent to the model.
- Output tokens: Tokens generated by the model. Some models also bill reasoning tokens under model-specific rules.
- Other categories: Cache writes, cache reads, images, audio, and certain tools may have separate pricing or accounting rules.
A long conversation can get progressively more expensive because earlier messages are often submitted again with each new request. A large context window is a capacity limit, not a free token allowance.
2. Find the actual rates before calculating
Check the current price for the exact model identifier you plan to call. Record its input rate, output rate, billing unit, and any cache-specific charges. Do not assume all Claude or GPT variants cost the same, or that a relay charges the model vendor’s published price.
59API offers low-cost, pay-as-you-go access to native, official-quality Claude and GPT models without downgrading them. Positioned among the cheapest relays, it is worth comparing for workloads where token volume dominates operating costs. Use its current listed rates—not an old screenshot or a vendor-only calculator—for your estimate.
3. Calculate a baseline with this formula
Request cost = (input tokens ÷ 1,000,000 × input price) + (output tokens ÷ 1,000,000 × output price). This formula assumes rates quoted per million tokens and no separately priced categories.
For a hypothetical model charging $1 per million input tokens and $5 per million output tokens, a request containing 12,000 input tokens and generating 2,000 output tokens costs:
- Input: 12,000 ÷ 1,000,000 × $1 = $0.012.
- Output: 2,000 ÷ 1,000,000 × $5 = $0.010.
- Total: $0.022 per request, or $220 for 10,000 similar requests.
These are illustrative rates, not a 59API price quote. If caching applies, split input into the relevant uncached, cache-write, and cache-read categories rather than counting the same tokens twice.
4. Measure a representative sample
Run 20–50 realistic requests before projecting monthly spend. Include short questions, large documents, and multi-turn sessions. Inspect each response’s usage fields: OpenAI-style responses commonly expose prompt_tokens and completion_tokens, while Claude-style responses use input_tokens and output_tokens. Cache and reasoning details vary by model and endpoint.
Log the model identifier, usage categories, request count, and calculated cost. For streaming, confirm whether your integration returns usage and whether you must explicitly request it. Missing usage should not be treated as zero usage.
5. Budget for workflows, not just messages
One user action may trigger planning, tool calls, follow-up requests, and retries. Budget for all model calls in that workflow. If measurement shows 15% additional spend beyond your $220 baseline, the revised estimate is $253. Treat that percentage as a measured assumption, not a universal rule.
- Cap output: Set the endpoint’s supported output-token limit.
- Trim context: Remove irrelevant history and retrieve only useful passages.
- Route by difficulty: Test cheaper models for routine work.
- Control retries: Use bounded retries and application-level spending alerts.
6. Connect 59API and verify one request
Start with https://api.59api.com and follow 59API’s integration instructions for the required endpoint path, authentication, and model name. It supports Claude Code, Codex, and OpenAI SDK-based integrations. Send one small request, inspect its usage, and reconcile the charge with the listed rate before increasing traffic.
When you are ready to test your budget, sign up for 59API and start with a small pay-as-you-go workload. Its referral rebate can provide additional value; check the current terms separately from your core token-cost calculation.
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