Azure / Azure/azure-sdk-for-python
Azure OpenAI giving 500 internal error for wrong input messages instead BadRequestError: Error code: 400
- 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**

**Additional context**
Add any other context about the problem here.
Contributor guide
Assessment
This issue has not been assessed yet.