Here is a simple Python example using a stop sequence with the OpenAI Responses API:
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model=“gpt-4.1-mini”,
input=“Write a short bedtime story in two sentences. End the story with the marker .”,
stop=[“END”]
)
print(response.output_text)
In this example, "END" is the stop sequence. When the model generates "END", the API stops producing more output, and the stop sequence itself is not included in response.output_text.
curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {My API Key}" \
-d '{
"model": "gpt-4.1-mini",
"input": "Write a short bedtime story in two sentences. End the story with the marker .",
"stop":["END"]
}'
and received the error response.
{
"error": {
"message": "Unknown parameter: 'stop'. Did you mean 'store'?",
"type": "invalid_request_error",
"param": "stop",
"code": "unknown_parameter"
}
So, it seems that the Responses API itself supports `stop` but not with REST API?
For API-specific questions, I generally suggest using developers.openai.com. Unfortunately, those docs also look incomplete here because they state that o-series reasoning models do not support stop sequences, which is not the full picture with regards to the gpt-5 family of models.