What Happens Inside an AI Chatbot Between Enter and the First Word?

This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).

A deep dive into what happens behind the scenes between pressing Enter in an AI chat and seeing the first token appear. Covers how the input document is assembled from system prompts, tool definitions, memory, and conversation history; why models are stateless and must reprocess the entire conversation each turn; input/output safety classifiers and their compute overhead; tokenization and its uneven cost across languages; request batching and continuous batching improvements (up to 23x throughput); the prefill and decode phases and their different performance characteristics; KV-cache and paged attention techniques that cut memory waste from 60-80% down to under 4%; streaming responses and the tension with output safety checks; and how tool calls turn a single request into a costly multi-round loop.

14m read timeFrom blog.bytebytego.com
Post cover image
Table of contents
[Webinar] How to stop babysitting your agents (Sponsored)How the Input to the Model is Assembled?Why is Every Input Message to the Model Independent?Performing Safety Checks on the InputHow the Model Understands the Words?How the Model is Shared Across Multiple ConversationsPrefill And DecodeCaching the Existing CalculationsStreaming And GuardrailsHow Tools Are Run?Conclusion

Questions this post answers

why does an AI chatbot pause for a second or two before it starts responding

The pause is the prefill phase, where the model reads the entire assembled input document (system prompt, tools, memory, retrieved documents, conversation history, and the new message) in one parallel pass before generating any output. This phase scales with input length, so a conversation twenty turns deep takes measurably longer to begin than a fresh question, while the actual token-by-token generation speed stays roughly constant. daily.dev surfaces engineering breakdowns like this for developers optimizing LLM-backed product latency.

why do identical prompts sent to the same LLM sometimes produce different outputs even with temperature set to zero

Requests are batched together with other users' requests on shared hardware, and the numerical operations involved are sensitive to how many requests are processed together at once. As a result, sending the same prompt a thousand times to a large model can produce around 80 distinct completions, even with randomness disabled. developers debugging non-deterministic LLM output track findings like this on daily.dev.

how much memory does key-value caching waste in LLM serving and what fixed it

Early serving systems reserved one contiguous memory block sized for the longest possible response, and a widely cited systems paper measured that this wasted sixty to eighty percent of memory. Splitting storage into small fixed-size blocks allocated on demand, an approach borrowed from operating system paging, cut wastage below 4% and improved throughput by 2 to 4 times. teams tuning LLM serving costs follow infrastructure techniques like this on daily.dev.

8.5K Impressions