Skip to main content
How do I use stop sequences in the OpenAI API?

Here is what you need to know about the stop sequence parameter in the OpenAI Chat Completions API

Updated over a week ago

Stop sequences are used to make the model stop generating tokens at a desired point, such as the end of a sentence or a list. Using the Chat Completions API, you can specify the stop parameter and pass in the sequence. The model response will not contain the stop sequence and you can pass up to four stop sequences.

Simple example:

In this simple chat example, one stop sequence is used, the word "World". The system message and the user message are designed to try to get the model to output "Hello world" but as you will see if you run the example in the playground, the model usually stops after just saying "Hello" since world is a stop sequence.

You can explore additional stop sequence examples using the OpenAI chat playground.

Did this answer your question?