[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"glossary-max-tokens::en":3,"gloss-cluster-max-tokens::en":26,"gloss-next-max-tokens::en":9},{"slug":4,"category":5,"name":6,"definition":7,"meta_desc":8,"faq":9,"schema_markup":9,"related":10},"max-tokens","prompt-eng","Max Tokens","Max tokens is a request parameter that limits how many tokens a model may generate in its response. It is a hard ceiling rather than a target: the model does not aim for the number, it simply stops when it reaches it. Its purpose is control — over cost, over latency, and over the worst case where a model would otherwise keep generating far beyond anything useful.\n\nThe parameter earns its place because generation length is not reliably predictable. A prompt that normally produces a short answer can, on an unusual input, produce something enormously long, and without a ceiling that becomes a slow request and a large bill. In a multi-step agent the effect compounds, since each step's output becomes the next step's input, so an unbounded response can inflate the cost of everything downstream.\n\nThe characteristic failure is truncation. When the limit is reached mid-sentence, the response simply ends, and the caller receives something that looks like a complete answer until read closely. Structured output suffers most: a truncated JSON object is invalid rather than short, and code that assumes a parse will succeed fails in a way that looks like a model error rather than a configuration one. Handling this properly means checking the finish reason the provider returns, not merely the presence of a response.\n\nSetting the value well is a matter of knowing the distribution rather than picking a round number. Look at the actual length of good responses for the task, allow reasonable headroom above the longest legitimate one, and treat truncation events as a signal to investigate rather than as noise. A limit that truncates one response in a hundred is quietly damaging quality; a limit that never truncates anything may not be providing protection at all.\n\nMax tokens is a ceiling, not a way to ask for brevity. Instructing the model in the prompt to answer in a certain length, or to produce a specific structure, is what actually shortens output; the parameter merely prevents the pathological case. Using it as a length control produces answers that are cut off rather than concise, which is worse for the reader and no cheaper than a well-instructed short answer.\n\nOne more interaction matters for reasoning-heavy models: tokens spent thinking may count towards the same budget as the visible answer, so a limit tuned for a short reply can leave no room for the response itself. Where a provider distinguishes the two, budget them separately; where it does not, set the ceiling against total output and verify with real cases rather than assumption.","Max tokens caps how long a model reply may be. It is a safety valve against runaway generation, and a common cause of answers that stop in the middle of a sentence.",null,[11,14,17,20,23],{"slug":12,"name":13},"output-formatting","Output Formatting",{"slug":15,"name":16},"parameter","Parameter",{"slug":18,"name":19},"stop-sequence","Stop Sequence",{"slug":21,"name":22},"streaming-generation","Streaming Generation",{"slug":24,"name":25},"token-budget","Token Budget",[27,31,35,38,42,45,48,51,54,57,60,63],{"slug":28,"category":5,"name":29,"updated_at":30},"analogical-prompting","Analogical Prompting","2026-09-08T21:32:35+00:00",{"slug":32,"category":5,"name":33,"updated_at":34},"automatic-prompt-optimization","Automatic Prompt Optimization","2026-09-08T21:32:36+00:00",{"slug":36,"category":5,"name":37,"updated_at":34},"chain-of-density","Chain of Density (CoD)",{"slug":39,"category":5,"name":40,"updated_at":41},"chain-of-thought-prompting","Chain-of-Thought Prompting","2026-09-08T21:32:34+00:00",{"slug":43,"category":5,"name":44,"updated_at":30},"chain-of-verification","Chain-of-Verification",{"slug":46,"category":5,"name":47,"updated_at":41},"chunking","Chunking",{"slug":49,"category":5,"name":50,"updated_at":41},"constrained-decoding","Constrained Decoding",{"slug":52,"category":5,"name":53,"updated_at":41},"context-stuffing","Context Stuffing",{"slug":55,"category":5,"name":56,"updated_at":41},"delimiter","Delimiter",{"slug":58,"category":5,"name":59,"updated_at":30},"directional-stimulus-prompting","Directional Stimulus Prompting",{"slug":61,"category":5,"name":62,"updated_at":30},"emotion-prompting","Emotion Prompting",{"slug":64,"category":5,"name":65,"updated_at":41},"few-shot-prompting","Few-Shot Prompting"]