Max tokens
The hard ceiling on how many tokens the model may write back. It limits the response, but does not ask the model to use them all.
See it
What it is
Max tokens is the hard ceiling on how many output tokens a model may generate for one request. Providers give the setting different names, including `max_tokens`, `max_output_tokens`, and `max_new_tokens`, but the job is the same: stop once the response spends its allowance. It is a cap, not a requested length, so a model can finish much earlier.
Set it high enough for the longest valid answer and low enough to bound latency and output cost. Extraction and classification calls can use a tight cap; code, long summaries, and multi-step reports need room. The allowance must also fit inside whatever space remains in the context window after the input.
Gotcha: hitting the cap can leave a sentence, code block, or JSON object half-written. Do not treat capped output as a successful response just because some text arrived. Check the API's completion status, which says so explicitly (`finish_reason: 'length'` in Chat Completions, `incomplete_details.reason` in the Responses API), surface the truncation, and either retry with a larger budget or ask for a smaller result.
Ask AI for it
Put a hard output budget on this OpenAI Responses API call with `max_output_tokens: 600`. Keep that value in named configuration, reserve the same 600 tokens when checking the model's context window, and inspect the response status before parsing the text. If generation stops because the output budget was reached, mark the result incomplete and retry once with a narrower prompt or a larger configured cap; never send partial JSON to downstream code. Log requested and used output tokens for every call.