Azure / Azure/azure-sdk-for-python

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

Open
#40,812 8 comments 0 reactions 1 assignee Claimed by @trrwilson View on GitHub
customer-reported needs-team-attention OpenAI question Service Service Attention
Dominant language
Python
Stars
5.6k
Forks
3.4k
Avg merge
1d 21h
Merged PRs (30d)
193

Description

- **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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.