Parameters that change the output
By the end: You can choose settings deliberately instead of copying them from an example.
- Temperature, and what it can and cannot do
- max_tokens as a ceiling, not an instruction
- Why temperature zero is not reproducible
- System prompts
New to the messages api? Using a language model means sending it a request over the internet and getting a reply back. The request is a list of messages, each labelled with who said it — standing instructions, the person, or the model's own earlier replies. The response is one more message. That exchange is the entire interface, and the model keeps nothing afterwards: it has no memory of the request you sent a second ago. Why it matters
Alongside your messages you can send a few settings that change how the model writes: how adventurous it is allowed to be, how long the reply may run, and what standing instructions it should follow throughout. This section is about what each one really does, so that you set them deliberately rather than copying them out of an example. The two most often misused are temperature, which does not make a model more accurate, and the length ceiling, which cuts a reply off rather than asking for a shorter one.
Temperature#
At each step the model has a probability for every possible next token. Temperature changes how sharply it favours the likely ones. Low temperature makes it pick the most probable token almost every time. High temperature flattens the distribution so less likely tokens get a chance.
- 0 to 0.3: extraction, classification, anything you will parse, anything you will evaluate.
- 0.7 to 1.0: writing, brainstorming, anywhere variety is the point.
- Above about 1.5: usually degrades into nonsense.
Temperature cannot create variety that is not there
Ask a model to name a colour and it will say blue at temperature 0 and still say blue at temperature 2, because the distribution is overwhelmingly peaked on one answer. High temperature only produces variety where the model was genuinely uncertain. This surprises people who expect the setting to force creativity.
"Name one colour." t=0.0 -> Blue, Blue, Blue
"Name one colour." t=2.0 -> Blue, Blue, Blue
"Name any animal." t=0.0 -> Elephant, Lion, Lion, ElephantTemperature 0 is not deterministic#
People assume temperature 0 means the same input always gives the same output. On a hosted API it does not. Requests are batched together on GPUs, floating point addition is not perfectly associative, and which other requests share your batch changes the result slightly. Different hardware and expert routing add more variation.
This matters most when you write evals. An exact-match assertion on generated text will flake, get marked as unreliable, and eventually be deleted. Assert on structure and properties instead, or run repeatedly and check a pass rate.
max_tokens#
This caps the length of the reply. It does not tell the model to be brief. The model writes as though it had unlimited room and generation is cut off when the cap is reached, usually mid-sentence.
# Wrong way to get a short answer
client.chat(messages, max_tokens=50)
# Right way
messages = [
{"role": "system", "content": "Answer in at most two sentences."},
...
]Still set max_tokens, as a safety net against a runaway response. Set it comfortably above what you expect, and check stop_reason to find out whether you hit it.
System prompts#
The system message sets standing instructions for the whole conversation: the role, the format, the tone, what to do when unsure. Keep it stable, because a stable prefix is what makes prompt caching work later.
SYSTEM = """You extract invoice data.
Return only JSON matching the schema you are given.
If a field is not present in the text, use null rather than guessing.
Never invent a number."""Where people go wrong
Copying temperature settings from a tutorial. A temperature of 0.7 on an extraction task is why your JSON parses 95 percent of the time instead of always.
If this comes up in an interview
What does temperature do?
It scales the probability distribution before a token is sampled. Low values concentrate probability on the most likely token, high values spread it out. It can only produce variety where the model was already uncertain.
Is temperature 0 deterministic?
Not on a hosted API. Batched GPU execution, non-associative floating point addition, expert routing and varying hardware all introduce small differences. This is why exact-match eval assertions on generated text flake.
Then they push further
If you need the same output for the same input, what do you do?
Cache results keyed by the exact input and settings, and design so small variations do not matter, for example by validating the output rather than comparing it to a stored string.
What gets marked up. Marked up for knowing hosted inference varies even at temperature 0, because of batching and floating point effects, and for designing around that rather than relying on it.
How do you make a model give shorter answers?
Ask for it in the prompt. max_tokens is a hard cut-off that truncates mid-sentence rather than an instruction to be concise. Keep max_tokens as a safety limit and check stop_reason to detect when it fires.
What belongs in the system prompt rather than the user message?
Anything constant across the conversation: role, output format, tone, and the rule for what to do when information is missing. Keeping it stable also lets prompt caching apply to it.
Build this: Run the same prompt ten times at temperature 0 and ten times at 1.5, and compare the outputs. Then try a prompt with one obvious answer and confirm that temperature barely changes it.
Watch it explained
This is one section of The Messages API, 6 hours across 3 sections. Read it in full to get the whole topic in order.
Stop 4 of 50 on the AI Engineer route
0 of 50 topics done · 0h behind you, 603h to go
What you have marked done is stored in this browser only. It does not reach a server, and clearing site data will clear it.