How to control where the model stops using stop
The stop
parameter lets you define one or more strings that tell the model to stop generating further tokens when it encounters them.
- The stop sequence(s) will not appear in the returned text.
stop
is a hard stop — the model will not generate anything past the stop string.- You can use
stop
to:- Format structured outputs
- Avoid responses that run too long
- Segment multi-part answers
How it works:
- You can pass:
- A single string
- Or a list of up to 4 strings
- The model will stop generating as soon as any stop string is matched.