OpenAIStop

@Serializable(with = OpenAIStopSerializer::class)
sealed interface OpenAIStop

Stop sequences for an OpenAI chat completion request.

The API accepts either a single string or an array of up to 4 strings. The model stops generating further tokens when a sequence is encountered, and the returned text does not contain the stop sequence.

Not supported by the latest reasoning models (o3, o4-mini and newer).

See also

Samples

// Single sequence.
val stopString = OpenAIStop.OpenAIString("###")
// Multiple sequences.
val stopList = OpenAIStop.OpenAIList(listOf("\n\n", "###"))

Inheritors

Types

Link copied to clipboard
data class OpenAIList(val values: List<String>) : OpenAIStop

Multiple stop sequences (up to 4).

Link copied to clipboard
data class OpenAIString(val value: String) : OpenAIStop

A single stop sequence.