Suddenly getting `APIStatusError: Error code: 431` when trying to pass image to gpt-4o

Marc RP 0 Reputation points
2024-11-01T10:57:27.56+00:00

Hi,

I suspect I am hitting some kind of rate limit. This simple example worked perfectly the first few times I run it, but after some time (I was iterating on other parts of my code) I start to get this error message whenever I try to include and image in the content

APIStatusError: Error code: 431

even though nothing about the environment has changed. I have reproduced this simple example:

def gpt4o_url(client, image_url: str, prompt: str = "What is in the image?"): 
""" Gpt-4o model using image url """ 
response = client.chat.completions.create( 
model=os.environ.get("AZURE_OPENAI_GPT4O_DEPLOYMENT")
, messages=[ { "role": "system", "content": "You are a helpful assistant to analyse images.", }, { "role": "user", "content": [ 
{"type": "text", "text": prompt}
, {"type": "image_url", "image_url": {"url": image_url}}, ], }, ]
, max_tokens=2000, temperature=0.0, )
return response


image_url = "https://github.com/retkowsky/images/blob/master/jo.png?raw=true"

result = gpt4o_url(client, image_url, "Analyse this image")

print(result.choices[0].message.content)

The code will only run if I comment out the image attachment part

# , {"type": "image_url", "image_url": {"url": image_url}}

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,193 questions
{count} votes

1 answer

Sort by: Most helpful
  1. lionel martis 0 Reputation points
    2024-11-01T23:19:53.62+00:00

    Seems like Microsoft APIM is causing the problem. This issue had previously occurred in May and then did a hot fix in all regions. Facing the same problem again

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.