4 stop word request fails with bad request

Hi,

I have started to receive bad request yesterday which was was working before. After debugging the issue. It seems to be related to the number of stop words. The bad request response occurs if you have 4 stop words. While less than 4 stop words works fine. This is regardless of what the actual words are. The API documentation suggest that 4 stops should be fine.

{‘error’: {‘message’: “‘$.stop’ is invalid. Please check the API reference: https://platform.openai.com/docs/api-reference.”, ‘type’: None, ‘param’: None, ‘code’: None}}

Example request that fails:
from openai import OpenAI

client = OpenAI()

stream = client.chat.completions.create(
    model="gpt-4-turbo",
    messages=[{"role": "user", "content": "Say this is a test"}],
    stop=["1", "2", "3", "4"],
    stream=True,
)
for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="")

This works:
from openai import OpenAI

client = OpenAI()

stream = client.chat.completions.create(
    model="gpt-4-turbo",
    messages=[{"role": "user", "content": "Say this is a test"}],
    stop=["1", "2", "3"],
    stream=True,
)
for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="")
2 Likes

Having the same issue. It stopped working all of a sudden. Thousands of requests have failed.

I have the same problem. Let’s see if they come up with a solution soon.

Likewise, this is a really bad bug to have in production with no warning.

1 Like

Happened to me too. Anything with four stop words is throwing a 400 error. Very bad in prod.

1 Like

It seems to be working now.