Post
What is an LLM
A large language model predicts the next token, over and over. What that means, what it gets you, and your first API call to one in Python.
An LLM (large language model) is a program that takes text in and produces text out. ChatGPT, Claude and Gemini are products built on top of LLMs. This is the first post of five AI series. The suggested reading order: the basics, then knowledge and RAG and tools and agents (in either order), then production, and finally adapting a model. The decision map shows which tool fits which problem, and the glossary explains any unfamiliar term.
The code follows the official Anthropic quickstart. It was not run for this post, so every output block below is example output: the structure matches the docs, but the text of a real answer will differ on every run.
What an LLM is
An LLM is a very large function. It was trained on a huge amount of text, and it learned one task: given the text so far, estimate which piece of text is likely to come next.
The pieces are called tokens. A token is usually a word or part of a word. The tokens and context window post covers them in detail; for now, think of a token as a small chunk of text.
Answering questions, translating, summarizing and writing code all come from that one skill. Nobody wrote a rule for translation; the model picked it up because translated text was in its training data.
How it generates text
The model does not write a whole answer at once. It runs a loop:
- It reads all the text so far.
- It produces a probability for every possible next token.
- One token is picked, usually a likely one.
- The token is appended to the text, and the loop starts again.
The loop stops when the model emits a special stop token, or when it reaches the token limit you set. Because a token is picked from a probability distribution, the same question can produce different answers. That is also the root of hallucinations: the model produces text that is likely, not text that was checked. Both are covered in a later post.
Your first call
To call a model you need an API key in the ANTHROPIC_API_KEY environment variable and the anthropic package (pip install anthropic). The SDK reads the key from the environment on its own.
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-opus-5-5",
max_tokens=1000,
messages=[{"role": "user", "content": "In one sentence, what is an LLM?"}],
)
for block in message.content:
if block.type == "text":
print(block.text)
The three parameters model, max_tokens and messages are required, according to the Messages API reference. max_tokens is a ceiling on the length of the answer, not a target. The response content is a list of blocks, so the code prints the text ones.
An LLM is a neural network trained on large amounts of text to predict the next
token, which lets it generate, summarize and translate language.
Model names change over time, so check the models overview for the current list before you copy the name above.
What comes back
The response is more than text. It also tells you why the model stopped and how many tokens the call used:
print(message.stop_reason)
print(message.usage.input_tokens, message.usage.output_tokens)
end_turn
17 31
stop_reason of end_turn means the model finished on its own. A value of max_tokens means the answer was cut at your limit. usage counts tokens in and out, and that is what you are billed for.
Where this series goes next
Knowing the loop explains most of what comes later: why the context window has a limit, why prompts matter, why a model can sound sure and be wrong, and why giving it tools or documents changes what it can do.