LearnThatStack Ace your next interview
LLM APIs & Integration · question
Question 5 of 52

How is LLM API usage billed, and what exactly is a token?

beginner
← All LLM APIs & Integration questions
Re-explain

Billing is per token, not per request or per seat. Providers price input and output separately, per million tokens. Input is what you send: the system prompt, the chat history and the new user message. Output is what the model writes, including tool-call arguments, and it usually costs several times more than input.

A token is a piece of text from the model's vocabulary, usually a subword chunk, not a whole word or a character. English prose averages roughly 4 characters per token. Code, JSON and non-English text pack fewer characters into each token, so they cost more.

"tokenization" -> ["token", "ization"]    2 tokens

Each provider uses its own tokenizer, so the same text counts differently across models. Even one provider's count can shift: Claude 4.7 and later produce about 30 percent more tokens for the same text than earlier Claude models.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for LLM APIs & Integration One question at a time. Answer out loud, get graded, see what you missed.
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

  • Why does output usually cost several times more per token than input? The model reads the whole input in one parallel pass but writes output one token at a time, each a separate forward pass, so output ties up the GPU longer.
  • In a multi-turn chat, why does the cost per turn keep climbing even when messages stay short? The API is stateless, so every turn resends the system prompt and full history as input. Name a fix like prompt caching or trimming history.
  • How would you count tokens accurately before sending a request? Use the provider's token-counting endpoint or tokenizer for that exact model. The 4-characters rule drifts on code, JSON and non-English text.
  • After a model upgrade, the bill rose with the same traffic and prompts. What would you check first? Compare token counts per request, since a new tokenizer can split the same text into more tokens. Then check output length and the new per-token prices.
  • Which fields in the API response would you use to compute the real cost of a request? The usage object's input and output token counts, plus cache read and write counts, each multiplied by its own rate. Don't estimate cost from the text.

What you can say

  1. You pay per token, not per request or per seat, with separate prices for input and output quoted per million tokens.
  2. Input is everything you send, so the system prompt, the chat history and the new user message all count.
  3. Output is what the model writes, tool-call arguments included, and it usually costs several times more than input.
  4. A token is a chunk from the model's vocabulary, usually part of a word, so 'tokenization' becomes 'token' plus 'ization'.
  5. English prose averages about four characters per token, but code, JSON and non-English text fit fewer characters in each token, so they cost more.
  6. Tokenizers also differ by provider and version. Claude 4.7 and later count about 30 percent more tokens for the same text, so old estimates don't carry over.

Weak answers to avoid

  • Says a token is a word Tokens are usually subword chunks, so word counts underestimate cost. Say subword, give the rough 4-characters rule for English, and note that code costs more.
  • Forgets the history is billed again each turn Input covers the system prompt and full chat history on every call, not only the new message. Missing it makes cost estimates for long chats far too low.
  • Treats input and output as one price Output usually costs several times more, so long responses or big tool-call arguments can dominate the bill. Name both rates and say which one you'd watch.
  • Assumes one token count works across models Each provider has its own tokenizer, and counts shift between versions too. Say you count with the target model's tokenizer, not a generic estimate.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the LLM APIs & Integration cheatsheet.

← Back to all LLM APIs & Integration questions
Pro · $10/mo

45 of 52 LLM APIs & Integration answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime