Zero Labs
Industry News / AI

What Actually Happens When You Send a Prompt to Claude A Full Breakdown

Source · Towards AI By Muhammed Mukthar

From the publisher’s feed, collected in the ZeroLabs newsroom.

You type a message into Claude and a response appears in seconds. It feels instantaneous. But between the moment you hit Enter and the first word streaming back, a precise and surprisingly deep chain of operations fires across specialized hardware at scale. The global AI inference market was valued at USD 106.15 billion in 2025 and is projected to grow to USD 254.98 billion by 2030 (MarketsandMarkets, 2025). This article is about what’s happening inside that market — at the level of a single request you send.We’ll trace your prompt from raw text to streamed tokens, covering tokenization, the transformer attention mechanism, GPU execution, the prefill/decode split, and why energy costs vary so wildly across model families. No hand-waving. No black box.Key TakeawaysYour prompt is first converted to tokens (roughly 1 token per 0.75 words) before the model ever “reads” it.Inference splits into two phases: a fast parallel prefill, then a slower autoregressive decode that produces one token at a time.Claude 4.5 Haiku outputs up to 99.5 tokens/sec on Amazon Bedrock, with a time-to-first-token as low as 0.58s (Artificial Analysis, 2025).Reasoning models like o3 use up to 73x more energy than lightweight models due to hidden chain-of-thought tokens.FP8 quantization can cut inference latency 8.5% and boost throughput 33% versus FP16.What Is Tokenization and Why Does It Happen First?Before an LLM reads a single character of your prompt, it converts the raw text into tokens. According to Anyscale (2024), one token equals roughly 4 characters or 0.75 words in English, meaning a 750 word document maps to around 1,000 tokens. This step is non-negotiable: the model’s embedding layer only accepts numerical IDs, not strings. (Anyscale, 2024)How the Tokenizer Splits TextClaude uses a byte-pair encoding (BPE) tokenizer. It starts from individual characters and merges the most frequent adjacent pairs until it reaches a fixed vocabulary size typically 50,000 to 200,000 unique tokens. Common words like “the” become single tokens. Rare words like “tokenization” may split into two or three. Code is especially dense: a single Python function can balloon to 3x more tokens than equivalent plain prose.Why does this matter practically? Your API bill is priced per token. A prompt written with unnecessary verbosity can cost 40–60% more than a tight, precise equivalent. It’s not a minor concern when you’re running thousands of requests per day.From Token ID to Embedding VectorEach token ID is looked up in an embedding matrix a massive table where every vocabulary entry maps to a vector of several thousand floating-point numbers. For a 7B-parameter model, that embedding layer alone requires roughly 14 GB of GPU memory to serve (Anyscale, 2024). These vectors encode semantic relationships: tokens with similar meanings cluster nearby in this high-dimensional space.In English, one token equals approximately 4 characters or 0.75 words. A 750-word document is roughly 1,000 tokens, and a 7B-parameter model requires approximately 14 GB of GPU memory to serve those embeddings in full-precision. (Anyscale, 2024)Token output speed varies significantly by provider and model size. Haiku on Amazon Bedrock leads at 99.5 tokens/sec. Source: Artificial Analysis (2025).How Does the Attention Mechanism Actually Work?The transformer’s attention mechanism is the architectural core that makes LLMs dramatically more capable than older sequence models. It lets every token in your prompt directly query every other token, regardless of distance. FlashAttention 4 achieves 1,613 TFLOPs/s peak throughput on NVIDIA B200 GPUs at 71% hardware utilization, delivering up to a 2.7x speedup over earlier Triton-based kernels (Lambda AI, 2026). Speed this matters when you’re processing hundreds of thousands of tokens per second across thousands of users.Queries, Keys, and Values — Without the MathThink of each token as a person in a room. When a token wants to “understand” its context, it broadcasts a query: “what information do I need?” Every other token holds up a key a signal describing what it contains. If the query and key match well, the token collects that token’s value the actual information it carries. This happens in parallel across every token pair in the sequence, then across multiple “heads” simultaneously.Each attention head learns different relationship types during training. One head might specialize in tracking pronoun references. Another might link verbs to their subjects across long distances. Together, the heads give the model a rich, multidimensional view of your prompt’s structure.The KV Cache and Why It ExistsRecomputing attention for every previously generated token on each new decode step would be catastrophically slow. The key-value cache stores the computed K and V tensors for all prompt tokens after the prefill phase. During decode, only the newly generated token needs fresh computation. The cache is what makes streaming responses feel fast — but it also consumes significant GPU memory, especially for long contexts and large batch sizes.FlashAttention-4 achieves 1,613 TFLOPs/s peak throughput on NVIDIA B200 GPUs at 71% hardware utilization, delivering up to 2.7x speedup over Triton-based attention kernels. This directly reduces the compute cost of processing long-context prompts.Prefill vs. Decode: The Two Phases of LLM InferenceEvery inference request has two distinct phases, and they have very different performance characteristics. The prefill phase processes your entire prompt in one forward pass it’s compute-bound and benefits from parallelism. The decode phase generates one token at a time and is memory-bandwidth-bound. Claude 4.5 Haiku reaches a time to first token (TTFT) as low as 0.58 seconds on Google Vertex AI, reflecting fast prefill execution (Artificial Analysis, 2025).What Happens During PrefillDuring prefill, the model reads your entire prompt simultaneously. All tokens are processed in one large matrix multiplication — the GPU is doing massive parallel work. This phase fills the KV cache and determines your TTFT. Long prompts take longer here, but not as much longer as you might expect, because GPUs handle large matrix operations efficiently. A 4,000-token prompt doesn’t take 4x as long to prefill as a 1,000-token prompt.What Happens During DecodeAfter prefill, decode begins. The model samples one token, appends it to the context, and runs another forward pass to generate the next. This auto-regressive loop continues until an end-of-sequence token appears or a max token limit is hit. Each decode step touches the entire model’s weights that’s why memory bandwidth, not raw compute, is the bottleneck here. This is also why smaller models stream faster: they have fewer weight matrices to read from GPU memory per step.So when a response feels slow to complete but appeared quickly, you’re experiencing fast prefill and slower decode. When even the first word takes a moment, you’re hitting prefill latency usually caused by a very long context or a busy inference cluster.From GPU to Response: The Hardware LayerLLM inference runs on GPUs because of their massive parallelism. A single NVIDIA H100 contains 80 GB of HBM3 memory and can execute tens of thousands of threads simultaneously a fundamentally different architecture from the serial execution model of a CPU. FP8 quantization reduces LLM inference latency by 8.5% and improves throughput by 33% compared to FP16, while quantization broadly cuts operational inference costs by 60–70% (MLCommons / Introl Blog, 2025).Quantization and Precision Trade-offsModel weights are stored as floating-point numbers. Full precision (FP32) is accurate but memory-hungry. Most production inference uses BF16 or FP16. FP8 quantization goes further, halving the memory footprint again. The latency and throughput gains are real and well-documented. The trade-off is a small degradation in output quality on very precise numerical or logical tasks — usually acceptable for most production use cases.Batching and Continuous BatchingRunning a single request at a time wastes most of the GPU’s parallel capacity. Modern inference servers use continuous batching they pack multiple in-flight requests into the same forward pass, sharing GPU compute across all of them simultaneously. This is what makes serving millions of tokens per second economically viable. Without it, the cost per token would be 5–10x higher than current market rates.FP8 quantization reduces LLM inference latency by 8.5% and improves throughput by 33% compared to FP16. Across providers, quantization broadly cuts operational inference costs by 60–70%, which explains much of the dramatic price decline seen since 2022. (MLCommons / Introl Blog, 2025)Source: arXiv 2505.09598 (How Hungry is AI?) / Epoch AI, 2025Why Do Reasoning Models Use So Much More Energy?Standard LLMs generate one output token per decode step, visible to the user. Reasoning models like OpenAI o3 or Claude with extended thinking generate additional hidden tokens — an internal chain-of-though before producing a final answer. A 2025 arXiv study found that o3 consumes 39.2 Wh per long prompt, approximately 73 times more energy than GPT-4.1 nano, solely because of these internal tokens (arXiv: How Hungry is AI?, 2025).Those hidden reasoning tokens cost exactly the same compute as visible output tokens. They’re just filtered before the response streams to your screen. When you’re using a reasoning model and the response takes 30 seconds to arrive, the model has been generating thousands of internal tokens the entire time, running the full decode loop with every step.Does this mean reasoning models are wasteful? Not exactly. They often solve problems in fewer turns and with fewer follow-up corrections. For a complex debugging session, one well-reasoned response can replace five back-and-forth exchanges with a non-reasoning model. The energy cost is real, but so is the output quality difference on hard tasks.Reasoning-focused models such as OpenAI o3 consume 39.2 Wh per long prompt, approximately 73 times more energy than GPT-4.1 nano, due to extended internal chain-of-thought generation that runs through the full decode loop before any visible output is produced. (arXiv 2505.09598, 2025)How Have Inference Costs Changed Over Time?LLM inference cost has dropped faster than almost any commodity in tech history. As of 2025, GPT-4 class performance costs approximately $0.40 per million tokens, compared to $20 per million tokens in late 2022 — a roughly 50x reduction in under three years (Introl Blog, 2025). This isn’t just competition driving prices down. Hardware efficiency improvements, quantization, and better serving infrastructure all contributed.Source: Introl Blog — Inference Unit Economics (2025)What’s driving this? It’s a combination of factors working in parallel. Better hardware (H100s, then B200s) delivers more TFLOPs per dollar. Quantization reduces memory requirements. Software-level optimizations like continuous batching and prefix caching squeeze more utilization from each GPU. And competition between providers forces margin compression. The global LLM market is projected to grow from USD 7.77 billion in 2025 to USD 149.89 billion by 2035 at a 34.44% CAGR (Precedence Research, 2025), which means this cost curve will keep attracting new entrants.LLM inference costs have declined approximately 10x annually since 2022. GPT-4 equivalent performance now costs $0.40 per million tokens versus $20 in late 2022, a roughly 50x reduction. This trend is driven by hardware improvements, quantization, and competitive pricing pressure across providers. (Introl Blog, 2025)What Does Claude Actually Sample at the End?After the final transformer layer produces a distribution over the model’s vocabulary, the model doesn’t just pick the top token every time. Sampling parameters shape the output. Temperature scales the distributionlower values make the model more deterministic, higher values more creative and varied. Top-p (nucleus sampling) restricts sampling to the smallest set of tokens whose cumulative probability exceeds a threshold. These aren’t magic numbers: they’re direct controls over the shape of the probability curve.Why does this matter for prompt engineering? If you’re building a system prompt for a code generator, you almost certainly want low temperature and tight top-p settings. High confidence, low variance. If you’re generating creative marketing copy, a higher temperature produces more surprising and diverse outputs. Treating sampling parameters as an afterthought is one of the most common mistakes we see in production LLM integrations.The sampled token ID is then decoded back through the tokenizer’s vocabulary map to a text string, which streams back to your client. The entire loop forward pass, sample, decode — repeats until the model generates an end-of-sequence token or hits your max_tokens limit.Frequently Asked QuestionsWhat is tokenization and why does it matter when sending a prompt to an LLM?Tokenization splits your raw text into numeric token IDs before the model processes it. According to Anyscale (2024), one token equals roughly 4 characters or 0.75 words in English, so a 750-word document maps to around 1,000 tokens. This matters because your context window limit, API pricing, and generation speed are all measured in tokens — not words or characters. Writing concise prompts directly reduces cost and latency.How does the transformer attention mechanism decide which words in a prompt are most important?Attention computes a relevance score between every pair of tokens using learned query, key, and value matrices. Tokens with high pairwise scores share more information during the forward pass. The model runs this across multiple attention heads in parallel, each learning to track different relationship types syntax, coreference, factual associations. FlashAttention-4 (Lambda AI, 2026) optimizes this computation to 1,613 TFLOPs/s on NVIDIA B200 GPUs, making long-context processing feasible at scale.What is the difference between the prefill phase and the decode phase in LLM inference?Prefill processes your entire prompt in one parallel forward pass comput bound, and fast. It produces the KV cache and determines time-to-first-token. Decode generates the response one token at a time, auto-regressively, reading the KV cache and the full model weights on each step memory-bandwidth-bound, and slower per token. Claude 4.5 Haiku hits a time-to-first-token as low as 0.58 seconds (Artificial Analysis, 2025), reflecting highly optimized prefill execution.Why do reasoning models like o3 take longer and use more energy than standard LLMs?Reasoning models generate an internal chain-of-thought during the decode phase before producing visible output. Each hidden reasoning token costs the same compute as a visible output token. A 2025 arXiv study found OpenAI o3 consumes 39.2 Wh per long prompt — roughly 73 times more than GPT-4.1 nano. The payoff is substantially higher accuracy on complex reasoning tasks, but the energy and latency costs are real and should factor into model selection decisions.How does context window size affect what an LLM can understand and remember in a conversation?The context window is the total number of tokens the model can attend to at once, including your system prompt, conversation history, and attached documents. Anything outside this window is invisible to the model — it’s not “forgotten” in the human sense, it simply doesn’t exist in the current computation. Larger windows increase prefill cost linearly and KV cache memory quadratically with naive attention. Modern systems like FlashAttention-4 partially offset this, but context length still has a direct cost impact.The Full PictureEvery message you send to Claude kicks off a tightly orchestrated sequence: text becomes tokens, tokens become embedding vectors, transformer layers run multi-head attention across your full context, the prefill phase fills the KV cache, and the decode phase generates one token at a time until the response is complete. The hardware layer running this quantized, batched, accelerated by FlashAttention-4 kernels on B200 GPUs is what makes sub-second first-token latency and $0.40-per-million-token pricing simultaneously possible.Understanding this pipeline makes you a better builder. You’ll write tighter prompts because you know tokens cost money and latency. You’ll choose the right model for the task because you understand why reasoning models are 73x more expensive per query. And you’ll design your system architecture around prefill/decode trade-offs rather than treating inference as a black box. The AI inference market is heading toward $255 billion by 2030. The engineers who understand what’s actually happening inside that market will build the better products.What Actually Happens When You Send a Prompt to Claude A Full Breakdown was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.