AppsGuidesAI DictionarySmall FixesOn RecordAboutFollow the lab

Stop sequences

Also called stop parameter

A stop sequence is a piece of text you choose, like "END", that makes an AI stop writing the moment it would produce it.

In plain words

An AI model writes one small piece of text at a time and keeps going until something tells it to stop. Usually the model decides itself: it writes a special "I'm done" marker it learned in training.

A stop sequence lets you set the finish line. When you call a model through an API, you can pass one or more bits of text, such as "END" or a blank line. The moment the model writes one, generation stops, and you get everything before it.

Developers use this to keep answers to one item, to stop a model from writing the next question in a quiz, or to cut off a script before the AI starts speaking for the other character. It saves time and money, because the model does not write text you would throw away.

Everyday example

Dictating to a typist

You tell a typist: "Type what I say, and stop the moment I say 'full stop, new page'." They don't type those words. They just stop and hand you the sheet. A stop sequence works the same way: the model writes until it reaches your chosen words, and the reply ends just before them.

Where the example breaks: A typist understands what you meant. A model only matches the exact characters, so "END" will not catch "End" or "the end", and a stop sequence that also appears in normal text can cut a good answer short.

Go deeper

How it actually works

A model can stop for three common reasons: it finished naturally, it hit a stop sequence, or it hit the length limit you set.

  1. The model's own stop

    During training, every example ends with a special end-of-text token. The model learns to write that token when an answer looks complete. This is its natural stop.

  2. Your stop sequences

    You pass a list of strings with the request. As text is generated, the system checks the output for any of them. Matching is exact and case-sensitive. At the first match it stops and returns the text before it.

  3. The length limit

    A maximum number of output tokens is a hard ceiling. If the model reaches it, the reply is cut off mid-thought. The response tells you which kind of stop happened, so your code can react.

  4. Where it fits today

    Stop sequences matter most when a model simply continues a document, as older completion models did. Chat models normally end their own turn, and structured output fixes the shape of a reply, so today stop sequences are mostly a tool for trimming or splitting text.

OpenAI
Up to 4 stop sequences. The returned text does not include the stop sequence. Not supported on some reasoning models (as of November 2026)
Anthropic
Parameter stop_sequences. A match returns stop_reason "stop_sequence" and names which one fired
Google Gemini
Parameter stopSequences. Case-sensitive, and the reply is cut where the string first appears
Not the same as
Stop words in search, which are common words like "the" that some systems ignore

Questions people ask

Is the stop sequence included in the output?

Usually not. OpenAI's documentation says the returned text will not contain the stop sequence. Anthropic's API reports which stop sequence was matched in a separate field, so you can tell why the reply ended.

What is the difference between a stop sequence and max tokens?

Max tokens is a length ceiling: the model stops after that many tokens, even mid-sentence. A stop sequence is a content trigger: the model stops when specific text appears. Many apps set both.

Is a stop sequence the same as a stop token?

Close, but not quite. A stop token usually means the model's built-in end-of-text marker, which it learned in pre-training. A stop sequence is text you choose, which can be many tokens long.

Why did my AI response get cut off?

Usually because it hit the max tokens limit, or one of your stop sequences appeared earlier than you expected. Check the stop or finish reason in the response, then raise the limit or pick a rarer stop sequence.

Was this clear?

1 is confusing, 5 is crystal clear. One tap, no account needed.

Spotted something wrong, or know a better example? Suggest a change

Further reading