NexRelayNexRelay
Guides

Token cost calculator

How to estimate AI API token costs before a request runs

A token cost calculator helps developers estimate spend before sending requests.

The basic formula

Estimate input tokens, output tokens, cached reads, and per-model unit prices separately.

Why output caps matter

Output tokens are often the variable part of a request.

  • Estimate worst-case output
  • Use smaller caps for tests
  • Compare estimates with logs

Prepaid credit planning

Prepaid gateways make estimates easier because requests stop when balance or budgets are exhausted.

FAQ

Are token estimates exact?

No. Final billing should use completed request usage when available.

Why track cached tokens separately?

Cached reads often have a different cost profile.