← Blog

How Does an LLM Work? A Developer's Explanation

2026-09-12 · 5 min read · SubToAPI Team

A large language model works by converting text into numbers, running those numbers through a network trained to predict what comes next, and repeating that prediction one piece at a time until it produces a full response. That's the mechanical answer. The more useful answer, if you're building software on top of one, is understanding why it behaves the way it does: why it sometimes hallucinates, why longer context costs more, why the same prompt can give different answers, and what's actually happening between your API call and the text you get back.

This article walks through the pipeline step by step, from raw text to generated output, with enough technical grounding to make architectural decisions in your own applications.

Step 1: Text becomes tokens

Models don't read words. They read tokens — chunks of text that might be a whole word, part of a word, or a punctuation mark. "Tokenization" is short for "programmable" no wait, let's not editorialize. A tokenizer splits "programmable" into pieces like program + mable, and common words like "the" usually stay as a single token.

This matters practically because:

Step 2: Tokens become vectors

Each token is mapped to a vector — a list of numbers, often several thousand dimensions long. This mapping is called an embedding, and it's learned during training so that tokens with similar meanings end up close together in that vector space. "Dog" and "puppy" sit nearer each other than "dog" and "spreadsheet."

At this point, the model isn't looking at words anymore. It's doing matrix math on high-dimensional numerical representations of meaning.

Step 3: Attention decides what matters

This is the core mechanism behind modern LLMs, introduced in the 2017 "Attention Is All You Need" paper and still the backbone of GPT, Claude, and every other major model family: the transformer architecture.

The key idea is self-attention: for every token in the input, the model calculates how relevant every other token is to it. When processing the word "it" in "the trophy didn't fit in the suitcase because it was too big," attention lets the model figure out that "it" refers to "trophy," not "suitcase," by weighing the relationships between all the tokens in the sentence simultaneously.

This happens across many layers (dozens in large models) and many parallel "attention heads" per layer, each specializing in different kinds of relationships — syntax, coreference, topic, tone. The output of all this stacked attention and feed-forward computation is, for each position in the sequence, a refined vector that encodes rich contextual meaning.

Step 4: Predicting the next token

At the final layer, the model converts its internal representation into a probability distribution over its entire vocabulary — tens of thousands of possible next tokens, each with a likelihood score. It picks one (more on how below), appends it to the sequence, and repeats the entire process to pick the next token.

This is why generation is sequential and why streaming responses feel natural: the model genuinely is producing one token at a time, not writing the full answer internally and revealing it gradually.

Two settings control how tokens get picked from that probability distribution:

This sampling step is also the direct cause of non-determinism — ask the same question twice at nonzero temperature and you can get different phrasing, even though the underlying weights never changed.

Training vs. inference: two very different phases

Everything above describes inference — using an already-trained model to generate output. Training is a separate, much more expensive phase where the model's weights (the billions of numbers controlling every calculation above) are adjusted by:

  1. Pretraining — predicting the next token across a massive text corpus, adjusting weights via backpropagation whenever the prediction is wrong.
  2. Fine-tuning — further training on curated examples of good responses.
  3. RLHF/RLAIF — using human or AI feedback to reward outputs that are helpful and penalize ones that are unsafe or low quality.

When you call an LLM API, none of this happens. The weights are frozen. You're only running inference — the forward pass through a fixed network. This is why the model has no persistent memory between separate API calls unless you explicitly resend the conversation history.

Why this matters when you're building with LLMs

Understanding this pipeline explains several things developers run into constantly:

If you're integrating an LLM into a product, the practical layer that matters is the API surface: authentication, streaming, structured tool calls, and usage tracking. SubToAPI turns your existing Claude access into that kind of clean HTTPS API — issue an sub_live_... key, send requests to /docs/messages, and get streaming responses via /docs/streaming or tool calls via /docs/tools without managing model infrastructure yourself. The /docs/quickstart guide covers the first request end to end, and you can start on a free trial at /signup.

questions

Does an LLM understand what it's writing, or just predict text? Mechanically, it predicts the next token based on learned statistical patterns. Whether that constitutes "understanding" is debated, but functionally, the model has no separate reasoning process outside of this prediction loop — sophisticated behavior emerges from it, not alongside it.

Why does the same prompt sometimes give different answers? Sampling settings like temperature introduce controlled randomness when picking the next token from a probability distribution. At temperature 0, output becomes far more consistent, though not always perfectly identical due to low-level numerical factors.

Why do LLMs have a maximum context length? Self-attention compares every token to every other token, so compute and memory costs grow quickly as input length increases. Context limits reflect the practical ceiling of what the model architecture and serving infrastructure can process efficiently.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →