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
Suddenly getting `APIStatusError: Error code: 431` when trying to pass image to gpt-4o
Marc RP
0
Reputation points
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}}