Azure / Azure/azure-sdk-for-python

Azure OpenAI giving 500 internal error for wrong input messages instead BadRequestError: Error code: 400

Aperta
#40,812 8 commenti 0 reazioni 1 assegnatario Rivendicata da @trrwilson Vedi su GitHub
customer-reported needs-team-attention OpenAI question Service Service Attention
Lingua principale
Python
Stelle
5.6k
Fork
3.4k
Merge medio
2g 2h
PR unite (30g)
213

Descrizione

- **Package Name**: openai
- **Package Version**: 1.76.2
- **Operating System**: Windows
- **Python Version**: 3.11.9

**Describe the bug**

When using chat completions api passing messages as `messages.append({'role': 'user', 'content': 'your query here'})` gives

```
InternalServerError: Error code: 500 - {'error': {'message': 'The server had an error processing your request. Sorry about that! You can retry your request, or contact us through an Azure support request at: https://go.microsoft.com/fwlink/?linkid=2213926 if you keep seeing this error. (Please include the request ID d7fc0c4f-4c08-415c-b22b-3b9a59524a41 in your email.)', 'type': 'server_error', 'param': None, 'code': None}}
```
But the expected behaviors should be client error

```
BadRequestError: Error code: 400 -
```

**To Reproduce**
Steps to reproduce the behavior:

Below is the code to reproduce the issue.

```python
from openai import AzureOpenAI

client = AzureOpenAI(
api_version="2025-03-01-preview",
azure_endpoint="endpoint",
api_key="key",
)

my_messages = [{"role":"system","content":"your instruction here"}]

response = client.chat.completions.create(model="gpt-4.1-mini",messages = my_messages.append({'role': 'user', 'content': 'your query here'}))
```

**Expected behavior**

The expected error should be client error.

`BadRequestError: Error code: 400 -`

**Screenshots**

![](https://i.imgur.com/r5TQwCt.png)

**Additional context**
Add any other context about the problem here.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.