technology

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

You type a question into ChatGPT. Two seconds later, words start appearing on your screen. But in those two seconds, your text traveled to a data center, got chopped into tokens, ran through a neural network with hundreds of billions of parameters, and came back as predicted words streaming at ~50 per second. All of that — thousands of GPUs, edge networks, caching layers — just to answer your question.

Let’s trace exactly what happens.

The 8-step journey from your keyboard to the response

Your prompt takes roughly 8 steps from keyboard to screen in under 2 seconds.

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. Just 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 center.

Step 3 — A load balancer picks the right GPU cluster. Not every server runs every model. The balancer finds a cluster that’s running what you requested (GPT-4o, Gemini Pro, Claude, etc.), has capacity, and has the lowest latency for your location.

Step 4 — Your text gets tokenized. The model doesn’t read words — it reads tokens. “Hello” becomes token ID 15339. “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 get split.

Step 5 — Prefill phase. All your input tokens are processed in parallel through the transformer. This is the heavy lifting. The model builds a “KV cache” — a stored representation of your entire prompt that it’ll reference when generating each response token. That noticeable pause before the first word appears? That’s the prefill phase working.

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

Step 7 — Streaming via SSE. Each token gets sent to your device immediately via Server-Sent Events — a lightweight streaming protocol. You don’t wait for the full response. That’s why words appear one at a time, like the AI is “typing.”

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

Transformers — the architecture behind everything

Every major LLM — GPT, Gemini, Claude, Llama, Mistral — runs on the transformer architecture. Google researchers invented it in 2017 with a paper called “Attention Is All You Need” (one of the most cited papers in AI history). It replaced older architectures that processed text word by word, sequentially.

The breakthrough? The attention mechanism. When the model processes your prompt, every token “looks at” every other token and calculates relevance. Ask “What is the capital of France?” and the attention mechanism strongly connects “capital” with “France” — even if they’re separated by 500 words of context.

GPT-4 has roughly 1.8 trillion parameters (estimated — OpenAI hasn’t confirmed). These are numbers adjusted during training on trillions of tokens of text. Each one is a tiny weight that shapes how the model recognizes patterns. It doesn’t “store” facts like a database — it stores statistical relationships between concepts.

Scaling to a billion users

ChatGPT and Gemini both crossed one billion users. Serving a hundred-billion-parameter model to that many people simultaneously requires infrastructure that would’ve been science fiction ten years ago.

GPU and TPU clusters

OpenAI runs ChatGPT primarily on NVIDIA A100 and H100 GPUs hosted in Microsoft Azure. Google runs Gemini on custom TPU v5 chips in Google Cloud. A single large model can’t fit in one GPU’s memory — the parameters get 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 stores intermediate representations of processed tokens so the model doesn’t recompute them for every new token. In a long conversation, this cache grows to gigabytes per session. Managing this memory — evicting old sessions, sharing caches for common prefixes — is honestly one of the hardest engineering problems in LLM serving right now.

Batching and scheduling

GPU clusters don’t process one request at a time — they 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 ones to finish. This pushes GPU utilization from roughly 30% to over 80%.

Edge networks and global routing

When you use ChatGPT from Mumbai, your request doesn’t go to a data center in Iowa. Edge servers in your region handle the TLS connection and route you to the nearest inference cluster. If that cluster’s full, you get rerouted to the next one. That’s why response times vary — a busy evening in the US might push some requests to European data centers.

Why it’s sometimes fast and sometimes painfully slow

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 center = 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.

The insane cost of running this

Running AI at this scale burns money at a rate that’s hard to comprehend:

  • 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

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

ChatGPT vs Gemini vs Claude — what’s actually different?

All three are transformer-based LLMs. The differences are more subtle than the marketing suggests:

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.

Where this is heading

The current approach — massive GPU clusters running trillion-parameter models — is hitting physical limits. A single AI data center can draw more power than a small city. The industry’s betting on four paths forward:

  • Smaller, efficient models (distillation, pruning, quantization) that deliver 90% of the quality at 10% of the cost
  • Mixture-of-experts (MoE) — only a fraction of the model activates per query, cutting compute by 4–8x
  • On-device inference — running models directly on your phone’s neural chip, no round trip needed
  • Custom AI chips — Google’s TPUs, Amazon’s Trainium, Microsoft’s Maia are all designed to break NVIDIA’s near-monopoly on AI hardware

Every time you get a faster response or a smarter answer, that’s thousands of engineers optimizing every layer of this stack — from the attention algorithm down to transistor layout on a chip. It’s an extraordinary engineering achievement, even if you never see any of it.


Curious about the safety concerns around these models? Or why the companies building them are calling for a slowdown?

Advertisement

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 centers. 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 centers. 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.

SK
S. K. Singh — Co-founder & Editor

S. K. Singh co-founded KnowWiser and edits what it publishes. After a long career in sales leadership at multinational companies, he now writes about consumer technology and where tech meets money.