technology

How Does ChatGPT Actually Work? The Architecture Behind AI That Responds in Seconds

TL;DR: When you type a prompt into ChatGPT or Gemini, your text travels from your device to a GPU cluster in a data centre, gets broken into tokens, passes through a transformer neural network with billions of parameters, and comes back as a stream of predicted words — one token at a time, roughly 50 per second. The entire round trip takes 1–3 seconds for the first word, then streams continuously. Serving this at scale to over a billion users requires thousands of GPUs, edge networks, KV caches, and sophisticated load balancing.

What happens when you press Enter on a ChatGPT prompt?

Your prompt goes on a journey of roughly 8 steps — from your keyboard to a GPU cluster and back to your screen — in under 2 seconds. Here is exactly what happens at each stage.

How Your Prompt Becomes a Response 1 Your device Prompt text 2 Edge / CDN TLS, routing 3 Load balancer Pick best GPU 4 Tokenizer "Hello" → [15339] 5 Prefill phase Process all tokens Build KV cache 6 Decode phase One token at a time ~50 tokens/sec 7 Server-Sent Events (SSE) stream Tokens flow back as they're generated — no waiting for full response 8 Your screen Words appear live Total round trip: ~1–3 seconds for first token, then continuous streaming

Step 1 — You type a prompt on your phone or computer. It is plain text at this point.

Step 2 — The request hits an edge network (a CDN server geographically close to you). This handles TLS encryption, rate limiting, and routes you to the nearest available data centre.

Step 3 — A load balancer picks the right GPU cluster. Not every server can run every model. The load balancer finds a GPU cluster that is running the model you requested (GPT-4o, Gemini Pro, Claude, etc.), has capacity, and has the lowest latency.

Step 4 — Your text is tokenized. The model does not read words — it reads tokens. The word “Hello” becomes token ID 15339. The sentence “How does compound interest work?” becomes roughly 7 tokens. GPT-4’s tokenizer (tiktoken) breaks text into subword units — common words are single tokens, rare words are split into pieces.

Step 5 — Prefill phase. All your input tokens are processed in parallel through the transformer neural network. This is the computationally expensive part. The model builds a “KV cache” — a stored representation of your entire prompt that it will reference when generating each response token. This is why there is a noticeable pause before the first word appears.

Step 6 — Decode phase. Now the model generates one token at a time, each time predicting “what is the most likely next word given everything so far?” It appends each new token to the KV cache and predicts the next one. This autoregressive loop runs at roughly 30–80 tokens per second.

Step 7 — Streaming via SSE. Each generated token is sent to your device immediately via Server-Sent Events (SSE) — a lightweight streaming protocol. You do not wait for the full response to be generated. This is why you see words appearing one at a time.

Step 8 — Your screen renders the words as they arrive, giving the impression of the AI “typing” in real time.

What is a transformer and why does it matter?

The transformer is the neural network architecture behind every major LLM — GPT, Gemini, Claude, Llama, and Mistral all use it. Invented by Google researchers in 2017 (the paper was titled “Attention Is All You Need”), it replaced older architectures that processed text sequentially.

The key innovation is the attention mechanism. When the model processes your prompt, every token “looks at” every other token and calculates how relevant each one is to the current prediction. When you ask “What is the capital of France?”, the attention mechanism ensures the model strongly connects “capital” with “France” — even if they are far apart in a longer prompt.

A modern LLM like GPT-4 has roughly 1.8 trillion parameters (estimated — OpenAI has not confirmed). These parameters are numbers that were adjusted during training on trillions of tokens of text. Each parameter is a tiny weight that influences how the model processes a specific pattern. The model does not “store” facts like a database — it stores statistical relationships between concepts.

How does an LLM scale to a billion users?

Both ChatGPT and Gemini have crossed one billion users. Serving a model with hundreds of billions of parameters to that many people simultaneously requires infrastructure that would have been unthinkable a decade ago.

GPU and TPU clusters

OpenAI runs ChatGPT primarily on NVIDIA A100 and H100 GPUs hosted in Microsoft Azure data centres. Google runs Gemini on custom TPU (Tensor Processing Unit) v5 chips in Google Cloud. A single large model cannot fit in one GPU’s memory — the parameters are split across multiple GPUs using:

  • Tensor parallelism — different parts of each layer run on different GPUs simultaneously
  • Pipeline parallelism — different layers of the model run on different GPUs in sequence
  • Data parallelism — the same model runs on many GPU sets, each handling different user requests

KV cache and memory management

The KV cache (key-value cache) stores intermediate representations of processed tokens so the model does not recompute them. For a long conversation, this cache grows to gigabytes per user session. Managing this memory efficiently — evicting old sessions, sharing caches for common prefixes — is one of the hardest engineering challenges in LLM serving.

Batching and scheduling

Rather than processing one request at a time, GPU clusters batch multiple user requests together. Continuous batching (also called in-flight batching) lets the system add new requests to a running batch without waiting for all current requests to finish. This dramatically improves GPU utilisation from roughly 30% to over 80%.

Edge networks and global routing

When you use ChatGPT from Mumbai, your request does not go to a data centre in Iowa. Edge servers in your region handle the TLS connection and route you to the nearest inference cluster. If that cluster is at capacity, you are routed to the next closest one. This is why response times can vary — a busy evening in the US might route some requests to European data centres.

Why does it sometimes feel slow or fast?

The speed of an AI response depends on several factors:

FactorEffect on speed
Prompt lengthLonger prompts = longer prefill phase = more delay before first token
Response lengthMore tokens to generate = longer total response time
Model sizeGPT-4 is slower than GPT-4o mini because it has more parameters to compute
Server loadPeak hours mean more users sharing the same GPU clusters
Your locationCloser to a data centre = lower network latency
Streaming vs. batchStreaming (SSE) shows words immediately; some API calls wait for the full response

The “typing” speed you see — roughly one word per frame — is the decode phase in action. Each token is generated, sent, and rendered in about 15–30 milliseconds.

How much does all of this cost?

Running AI at this scale is extraordinarily expensive. Here are the estimated numbers:

  • Training GPT-4: estimated $100 million+ (one-time cost for a training run)
  • Training Gemini Ultra: estimated $150–200 million
  • Daily inference cost for ChatGPT: estimated $2–8 million per day (for hundreds of millions of daily queries)
  • Cost per query: roughly $0.01–$0.07 for a GPT-4 class response, $0.001 for a smaller model
  • NVIDIA H100 GPU: roughly $30,000–$40,000 per chip
  • A single GPU cluster: thousands of H100s = hundreds of millions of dollars in hardware

This is why free tiers have rate limits, why API pricing exists, and why smaller models (GPT-4o mini, Gemini Flash, Haiku) are offered as cheaper alternatives — they use fewer GPUs per query.

What is the difference between ChatGPT, Gemini, and Claude?

All three are transformer-based LLMs, but they differ in implementation:

ChatGPT (OpenAI)Gemini (Google)Claude (Anthropic)
Compute hardwareNVIDIA GPUs (Azure)Google TPUs (Cloud)NVIDIA GPUs (AWS/GCP)
MultimodalAdded via modulesNatively trainedAdded via modules
Context window128K tokens (GPT-4o)2M tokens (Gemini 1.5)200K tokens (Claude)
Users1B+1B+Not disclosed
Training approachRLHFRLHF + constitutionalRLHF + constitutional AI

The architectural differences are subtle — all use attention mechanisms, all tokenize input, all generate text autoregressively. The real differences are in training data, safety tuning, and infrastructure choices.

What does this mean for the future?

The current architecture — massive GPU clusters running trillion-parameter models — is hitting physical limits. GPU power draw for a single data centre can exceed the electricity consumption of a small city. Several approaches are being explored:

  • Smaller, more efficient models (distillation, pruning, quantisation) that deliver 90% of the quality at 10% of the cost
  • Mixture-of-experts (MoE) architectures where only a fraction of the model activates per query, reducing compute by 4–8x
  • On-device inference — running smaller models directly on your phone’s neural processing unit, eliminating the round trip entirely
  • Custom silicon — Google’s TPUs, Amazon’s Trainium, and Microsoft’s Maia chips are all designed specifically for AI workloads, aiming to break NVIDIA’s near-monopoly

The speed and quality you experience today is the result of thousands of engineers optimising every layer of this stack — from the attention algorithm itself to the physical layout of transistors on a chip.

Frequently asked questions

How fast does ChatGPT generate a response?

ChatGPT generates roughly 30 to 80 tokens per second (about 25 to 60 words per second), though this varies by model size and server load. The first token typically appears within 0.5 to 2 seconds — the initial delay is the 'prefill' phase where the model processes your entire prompt at once. After that, tokens stream one at a time.

How many GPUs does it take to run ChatGPT?

OpenAI has not disclosed exact numbers, but estimates from infrastructure analysts suggest ChatGPT requires tens of thousands of NVIDIA A100 and H100 GPUs spread across multiple data centres. A single inference request for GPT-4 class models uses a cluster of GPUs working in parallel via tensor parallelism and pipeline parallelism.

Does ChatGPT understand what it is saying?

No — not in the way humans understand language. ChatGPT predicts the most likely next token based on patterns learned during training. It has no beliefs, no memory between sessions (unless given a memory feature), and no internal model of truth. It produces text that is statistically likely to be coherent and relevant, but it can confidently generate incorrect information.

What is the difference between ChatGPT and Gemini architecturally?

Both are transformer-based large language models, but they differ in training data, model size, and serving infrastructure. ChatGPT runs on OpenAI's infrastructure using NVIDIA GPUs in Microsoft Azure data centres. Gemini runs on Google's TPU (Tensor Processing Unit) clusters in Google Cloud. Gemini is also natively multimodal — trained on text, images, audio, and video together — while GPT-4 added multimodal capabilities as separate modules.

How much does it cost to run ChatGPT per query?

Estimates vary, but running a single GPT-4 class query costs roughly $0.01 to $0.07 depending on prompt length and response length. At hundreds of millions of queries per day, OpenAI's daily inference costs are estimated at $2 to $8 million. This is why API pricing exists — the compute cost per query is real and significant.

Priya Sharma — Technology Writer

Priya covers software, apps, and developer tools — turning technical concepts into guides anyone can follow. She writes the kind of docs she wishes existed when she was learning.