DEV Community

Sameer Moin
Sameer Moin

Posted on

AI API Costs Are Surprising People — Here's How to Check First

The bill that surprises everyone eventually

You're building something with the OpenAI or Anthropic API.
It's working well. Then you check your usage dashboard and
the number is... not what you expected.

This happens to almost everyone who builds with AI APIs for
the first time. Not because the pricing is hidden - it's
published clearly - but because tokens are not an intuitive
unit of measurement, and the costs compound in ways that
aren't obvious until you're already past them.

What a token actually is

Tokens aren't words. They aren't characters. They're chunks
of text a model's tokenizer splits your input into, and the
exact split depends on the model.

Rough rules of thumb:

  • ~4 characters per token in English prose
  • ~0.75 words per token
  • Code tokenizes differently - often more tokens per line than equivalent prose
  • Non-English text can be significantly more tokens per word
  • Whitespace, punctuation, and formatting all count

The same sentence can be a different number of tokens
depending on which model you're using. This is normal and
expected.

Why input and output tokens are priced differently

Most people focus on input cost (your prompt) and forget
about output cost (the completion). This is a mistake because:

  • Output tokens are almost always more expensive than input
  • GPT-4o: input $2.50/1M, output $10.00/1M - 4x more expensive
  • Claude Opus 4: input $15/1M, output $75/1M - 5x more expensive
  • A long completion can cost more than the prompt that triggered it

The honest problem with token counters

Most AI token counters claim to give you an exact count for
any model. Most are lying, or at best, guessing.

Exact token counts are only possible when you have access to
the model's actual tokenizer. Today that means:

  • OpenAI - exact, because they publish their tokenizer (tiktoken) and it can run client-side
  • Anthropic (Claude) - estimated only, because they don't publish a portable client-side tokenizer
  • Google (Gemini) - estimated only, same reason

A tool that claims to give you an exact Claude token count
is giving you a confident approximation. That's fine as long
as it's honest about it. Most aren't.

What to check before a large API call

Three things worth knowing before you send:

  1. How many tokens is this prompt?
  2. How much of the model's context window does that use?
  3. What will this cost if the completion is X tokens long?

Show how each of these plays out differently across GPT-4o,
Claude Sonnet 4, and Gemini 2.5 Flash using the same prompt.

Practical situations where this matters

  • Sending a large codebase for review - will it fit in context?
  • Building a RAG system - how much does each retrieval cost at scale?
  • Comparing providers before committing to one for a high-volume task
  • Debugging a prompt that keeps getting truncated
  • Estimating monthly API costs before building a feature

Try it yourself

"I built a free token counter that handles all three major
providers, is upfront about which counts are exact vs.
estimated, and lets you add custom pricing if the built-in
table is out of date. No signup, runs entirely in your browser."

Free AI Token Counter & API Cost Calculator — ToolsFusion

Count tokens for GPT, Claude, and Gemini prompts and estimate API costs before you call. Free, no signup, runs entirely in your browser.

favicon thetoolsfusion.com

A few numbers worth knowing

Model Context Window Input (per 1M) Output (per 1M)
GPT-4o 128K tokens $2.50 $10.00
GPT-4o mini 128K tokens $0.15 $0.60
Claude Opus 4 200K tokens $15.00 $75.00
Claude Sonnet 4 200K tokens $3.00 $15.00
Gemini 2.5 Pro 1M tokens $1.25 $10.00
Gemini 2.5 Flash 1M tokens $0.075 $0.30

Prices change. Check the calculator for the most current
verified rates.

The bottom line

Knowing your token count before you send doesn't just save
money on individual calls. It changes how you think about
prompt design - you start making deliberate tradeoffs between
context richness and cost, which makes you a better AI
application builder.

Top comments (0)