Every AI model runs on tokens. Every API bill is a token bill. Every context window limit is a token limit. Every speed difference between models comes down to how many tokens they process per second. Tokens are the single most important concept in generative AI, and most people using AI daily have only a vague idea what they actually are. This is the guide that fixes that.The Bill That Made Me Stop and Actually Learn ThisI got an AWS Bedrock bill for $340 one month. I was running an AI agent that processed customer support tickets. I had estimated maybe $50.I had no idea what went wrong until I looked at the usage breakdown. The agent was reading the entire customer history, sometimes 200 emails, for every single ticket. Each email was roughly 500 tokens. 200 emails × 500 tokens = 100,000 tokens of input per ticket. At 1,000 tickets per day, that was 100 million tokens of input every single day.I did not understand tokens well enough to catch this before it happened.This article is the guide I needed before I built that agent. It covers everything, what tokens actually are, how every major AI provider uses them, what they cost in 2026, how to count them before you send them, and the strategies that cut token costs by 40–90% without hurting quality.Part 1: What Is a Token? (The Real Answer)Most explanations say something like "a token is approximately one word." That is close enough to be useful and wrong enough to cause problems.Here is the real answer.A token is the smallest unit of text that an AI model processes. Not a word. Not a character. A chunk of text that falls somewhere in between, and the exact boundaries are determined by a process called tokenisation that runs before the model ever sees your text.Let us look at exactly what happens when you send a sentence to an AI model.The Tokenisation Process Step by StepYou type:The quick brown fox jumped over the lazy dog.Before this reaches the model, a tokeniser splits it into chunks:["The", " quick", " brown", " fox", " jumped", " over", " the", " lazy", " dog", "."]That is 10 tokens. Notice a few things:"The" and "the" are different tokens, capitalisation mattersThe space before "quick" is part of the " quick" token, not separateThe period is its own tokenNow here is where it gets interesting. Common words become single tokens. Uncommon words get split into multiple tokens:"Python" → ["Python"] = 1 token"Pythonic" → ["Python", "ic"] = 2 tokens"antidisestablishmentarianism" → ["anti", "dis", "estab", "lishment", "arian", "ism"] = 6 tokensThe tokeniser has learned from a massive corpus of text that "Python" appears frequently enough to deserve its own token. "Pythonic" is rarer, so the model treats it as "Python" and "ic". "Antidisestablishmentarianism" is so rare that it gets broken into meaningful syllabic chunks.Numbers work differently:"2024" → ["2024"] = 1 token (common year)"17,394" → ["17", ",", "394"] = 3 tokens"0.000001" → ["0", ".", "000001"] = 3 tokensCode has its own patterns:"print(hello)" → ["print", "(", "hello", ")"] = 4 tokens"import numpy as np" → ["import", " numpy", " as", " np"] = 4 tokensAnd non-English text is often more expensive in tokens than English, because tokenisers are trained primarily on English text:"Hello" (English) → ["Hello"] = 1 token"Hola" (Spanish) → ["Hola"] = 1 token"こんにちは" (Japanese) → ["こ","ん","に","ち","は"] = 5 tokens"مرحبا" (Arabic) → ["م","ر","ح","ب","ا"] = 5 tokensThis is one reason AI services can be more expensive for users who write in non-Latin scripts — the same semantic content requires more tokens.The One Number You Need to RememberFor English text: 1,000 tokens ≈ 750 words ≈ 4,000 charactersOr inversely: 1 token ≈ 4 characters ≈ 0.75 wordsThis is an average. Technical content, code, and non-English text can cost significantly more per word. Casual English prose is close to this ratio.Part 2: Tokens Flow in Both Directions And the Price Is Not SymmetricWhen you use any AI API, there are always two flows of tokens:Input tokens (prompt tokens): everything you send to the model: your system prompt, the conversation history, any documents you include, any tool outputs, any images.Output tokens (completion tokens): everything the model writes back: its response, its reasoning, its tool calls.This distinction matters enormously for cost. Here is why:Output tokens are 3 to 6 times more expensive than input tokens across almost every AI provider.2026 Token Pricing The Complete PictureAs of August 2026, here is what the major providers charge per million tokens:ModelInput (per 1M tokens)Output (per 1M tokens)Output/Input ratioAmazon Nova Micro$0.035$0.144×DeepSeek V4 Flash$0.14$0.282×Llama 4 Maverick$0.15$0.604×Gemini 3.7 Flash$0.30$2.508×Claude Haiku 4.5$1.00$5.005×GPT-5.6 Luna$1.00$6.006×Claude Sonnet 5$2.00$10.005×Gemini 3.1 Pro$2.00$12.006×GPT-5.6 Sol$5.00$30.006×Claude Opus 5$5.00$25.005×Claude Fable 5$10.00$50.005×Source: aipricing.guru, verified August 15, 2026The cheapest capable production model (Amazon Nova Micro) costs $0.035 per million input tokens. The most expensive (Claude Fable 5) costs $10 per million input tokens, nearly 300 times more.What These Numbers Actually MeanLet me translate these prices into something concrete.A typical short user message might be 50 tokens. A typical AI response might be 200 tokens.At Claude Haiku 4.5 pricing ($1.00 input / $5.00 output per million):50 input tokens = $0.00005 = 1/20th of a cent200 output tokens = $0.001 = 1/10th of a centTotal per conversation turn: $0.00105, barely anythingBut now add a system prompt of 2,000 tokens and context history of 5,000 tokens:7,050 input tokens = $0.00705 per turnAt 1,000 turns per day = $7.05/day = $211.50/month, now noticeableAnd if your agent is reading 100,000 tokens of context per call:100,000 input tokens = $0.10 per callAt 1,000 calls per day = $100/day = $3,000/month, now a real budget lineThis is exactly what happened to my $340 bill. The agent was reading too much context per call. Once I understood tokens, the fix was obvious: instead of reading all 200 emails, read only the last 5 and retrieve others on demand.Why Output Costs So Much MoreThe pricing asymmetry is not arbitrary. Generating output is computationally more expensive than reading input.When reading input, the model processes tokens in parallel. Modern GPU architectures are extremely efficient at this, they can process many tokens simultaneously.When generating output, the model generates one token at a time. Each new token depends on all previous tokens, the entire context plus everything generated so far. This is inherently sequential. It cannot be fully parallelised. It is why generating a 1,000-token response takes measurably longer than reading a 1,000-token prompt.The economic consequence: if you want to reduce your AI bill, reducing output length is usually more effective per character than reducing input length, because output is more expensive.Part 3: Context Windows The Token Budget You Cannot ExceedEvery AI model has a context window, the maximum number of tokens it can process in a single call. Everything you send and everything the model generates has to fit within this limit.Context Windows in 2026ModelContext WindowWhat FitsGPT-3.5 (2023)4,096 tokens~3,000 wordsClaude 2.1 (2023)200,000 tokens~150,000 wordsClaude Opus 5200,000 tokensAn entire novelClaude Fable 51,000,000 tokensMultiple novelsGemini 3.1 Pro1,000,000 tokens~750,000 wordsNemotron 3.5 Lightning1,000,000 tokensA large codebaseThe expansion from 4,096 tokens in 2023 to 1,000,000 tokens in 2026, a 244× increase in three years, has completely changed what is possible with AI. You can now put an entire codebase in context. You can feed a model your entire customer database. You can include months of conversation history.But a critical insight: just because the context window is 1 million tokens does not mean you should use all of it. The cost scales linearly with tokens used. A 1 million-token context call costs 1,000× more than a 1,000-token context call, and the model quality actually degrades with very long contexts because relevant information gets harder to retrieve from a sea of noise.The Context Window Fills Up Here Is What HappensIn a long conversation or agentic session, the context window gradually fills:Turn 1: 500 tokens (system prompt + first message + first response) Turn 10: 5,000 tokens (everything above + 9 more exchanges) Turn 100: 50,000 tokens (full conversation history) Turn 500: Context window full, model starts losing early contextMost AI APIs handle context window overflow in one of two ways:Hard stop: returns an error when you exceed the limitTruncation: silently drops the oldest messagesUnderstanding this prevents a common bug: agents that seem to "forget" instructions they were given at the start of a session. They have not forgotten, those tokens have been pushed out of the context window.Part 4: The Hidden Token Costs Nobody Warns You AboutReasoning Tokens The Invisible MultiplierThis is the one that surprises people most.When you enable "extended thinking" on Claude, or use OpenAI's reasoning models in high-effort mode, the model generates thinking tokens, internal reasoning steps before it produces its answer.These thinking tokens are billed as output tokens. They can dwarf the final response.Your question: "Solve this complex problem..."[15 tokens]Model's thinking tokens (you pay for these): "Let me break this down step by step. First, consider..."[2,000 tokens of internal reasoning — BILLED]Model's actual answer to you:"The answer is 42."[15 tokens]Total output tokens billed: 2,015 (not 15)At Claude Opus 5 pricing ($25 per million output tokens):Without reasoning: 15 tokens = $0.000375With reasoning: 2,015 tokens = $0.050375That is 134× more expensive for the same question.When does reasoning justify the cost? For genuinely hard problems, complex mathematics, multi-step logical proofs, ambiguous code debugging, reasoning models produce dramatically better answers. For simple questions, "what's 2+2", reasoning tokens are pure waste.The rule: use reasoning for hard problems, standard mode for everything else. Build a classifier that routes questions to the appropriate mode. This alone can reduce costs by 10–20× in agentic systems that indiscriminately use reasoning mode.Multimodal Tokens Images, Audio, and VideoTokens are not just text anymore. When you send an image, video, or audio file to a multimodal model, it also gets converted to tokens.Image tokens:Most models convert images into patches, small square regions each of which becomes a token. The number of tokens depends on the image size:512 × 512 image → ~256 tokens1024 × 1024 image → ~1,024 tokens4K image → ~8,000 tokensThis has significant cost implications:python# A seemingly simple request:# "Here are 10 product photos. Write descriptions for each."# What it actually sends:# 10 images × ~500 tokens each = 5,000 image tokens# Plus your text prompt = ~50 tokens# Total input: ~5,050 tokens# At GPT-5.6 Sol pricing ($5 per million input):# 5,050 tokens = $0.025 per batch of 10 photos# At 10,000 batches/day = $250/dayPractical tip: resize images before sending to AI APIs. A 4K image and a 512×512 version of the same image often produce equally good results for most tasks, but the 4K version costs 30× more in tokens.Audio and video tokens:Audio is typically tokenised at a rate related to time:Approximately 25–30 audio tokens per second of audioA 60-second audio clip ≈ 1,500–1,800 tokensVideo compounds both:A 10-second video clip at 1 frame per second = 10 frames × ~500 tokens = 5,000 image tokens + audio tokensFor any application processing media, token counting at the media level is essential before the bills arrive.Cached Tokens: The Discount You Are Probably Not UsingMost AI providers offer prompt caching, a feature where tokens sent in previous requests are cached and re-used at a significant discount.At Anthropic (as of August 2026):Normal input tokens: full priceCached input tokens: 10% of the normal price (90% discount)At OpenAI:Cached prompt tokens: 50% discountAt Google Gemini:Context caching available for contexts over 32,000 tokens: up to 75% discountWhen Caching AppliesCaching helps when you have a fixed system prompt or large context that is the same across many requests, a customer service bot with a fixed 5,000-token instructions block, a code review tool that always loads the same repository structure, a document Q&A system with a fixed knowledge base.python# Without caching:# Every request sends 5,000 system prompt tokens at full price# 1,000 requests/day × 5,000 tokens × $1.00/million = $5.00/day# With caching:# First request: 5,000 tokens at full price = $0.005# Subsequent requests: 5,000 tokens at 10% price = $0.0005 each# 1,000 requests/day = $0.005 + (999 × $0.0005) = $0.505/day# Savings: 90%Enabling prompt caching on Anthropic requires one additional parameter in your API call:pythonimport anthropicimport osclient = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])response = client.messages.create( model="claude-opus-4-7-20250514", max_tokens=1000, system=[ { "type": "text", "text": """You are a customer support agent for TechCorp.[Your 5,000-token system prompt here — product documentation,policies, procedures, tone guidelines...]""", "cache_control": {"type": "ephemeral"} # THIS LINE enables caching } ], messages=[ {"role": "user", "content": "How do I reset my password?"} ])# First call: system prompt is cached (costs full price this once)# All subsequent calls: system prompt costs 10% of normal pricePart 5: How to Count Tokens Before You Send ThemNever send tokens to an API without knowing how many you are sending. Here is how to count:Using tiktoken (OpenAI's Tokeniser Works for Many Models)python# pip install tiktokenimport tiktokendef count_tokens_openai(text: str, model: str = "gpt-5.5-turbo") -> dict: """ Count tokens for OpenAI models. Also works as an approximation for other models — actual counts may vary by 10-20% """ encoding = tiktoken.encoding_for_model(model) tokens = encoding.encode(text) return { "token_count": len(tokens), "character_count": len(text), "word_count": len(text.split()), "tokens_per_word": round(len(tokens) / len(text.split()), 2), "tokens_per_character": round(len(tokens) / len(text), 2), "preview": tokens[:10] # First 10 token IDs }# Test ittext = "The quick brown fox jumped over the lazy dog."result = count_tokens_openai(text)print(result)# {# "token_count": 10,# "character_count": 46,# "word_count": 9,# "tokens_per_word": 1.11,# "tokens_per_character": 0.22# }# Test with codecode = """def fibonacci(n): if n