← Glossary / 45 of 100

n. / Models and tokens

Max tokens

Definition

Max tokens is a setting that caps how many tokens a model may generate in one reply. If the reply hits the cap, it stops mid-sentence and the call reports a length stop reason.

In more detail

It protects you from runaway cost and long waits, but a cap set too low truncates answers and can break structured output, leaving invalid JSON. Watch for runs that end because of length, since they are a common hidden cause of bad outputs and failed parsing.

Example

A summarizer is capped at 200 tokens. A long article produces a reply cut off mid-sentence, and the trace shows the stop reason "length".

Definitions are the start.

Open a real trace and watch these terms move.