openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

Unsupported content type: 'multipart/form-data'

Open aaditya-p-vaisesika opened this issue 1 year ago • 5 comments

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • [x] This is an issue with the Python library

Describe the bug

This error has been occurring from today. Not sure what happened, but no change in code from my end. This error does not occur everytime, but it does occur frequently. Not sure why that's the case. Even if all the inputs are same, it works half of the times and does not the other.

Error code: 400 - {'error': {'message': "Unsupported content type: 'multipart/form-data'. This API method only accepts 'application/json' requests, but you specified the header 'Content-Type: multipart/form-data'. Please try again with a supported content type.", 'type': 'invalid_request_error', 'param': None, 'code': 'unsupported_content_type'}}

Please let me know if you need any more information to debug this. Thank You

To Reproduce

from openai import AsyncAzureOpenAI

client = AsyncAzureOpenAI(
        azure_endpoint=endpoint,
        api_key=api_key,
        api_version="2025-04-01-preview",
        azure_deployment=deployment_name,
)

try:

    response = await client.images.edit(
            model="gpt-image-1",
            image=images,
            prompt=prompt,
            n=1,
            quality=quality,
            # input_fidelity="high",
    )

Code snippets


OS

linux

Python version

3.11.4

Library version

2.2.0

aaditya-p-vaisesika avatar Nov 12 '25 03:11 aaditya-p-vaisesika

This looks like an SDK-side serialisation issue rather than an API problem.

The images.edit() method in openai==2.2.0 occasionally sends requests as multipart/form-data instead of the required application/json, which causes the 400 error you’re seeing.

In the meantime, you can:

  • Downgrade to openai==2.1.0, or
  • Send the image as a base64-encoded string to force JSON serialisation.

kushvinth avatar Nov 12 '25 05:11 kushvinth

It can only be form-data right now, and it works with the OpenAI client, so maybe there's something specific to Azure or the deployment configuration?

karpetrosyan avatar Nov 12 '25 08:11 karpetrosyan

Downgrading the version definitely helps. But if you can point me in the right direction with respect to this issue that would be of big help.

aaditya-p-vaisesika avatar Nov 12 '25 13:11 aaditya-p-vaisesika

PTAL

kushvinth avatar Apr 19 '26 08:04 kushvinth

Thanks for reporting this! Azure’s image-edit endpoint requires multipart form data, and our local checks confirmed the SDK builds the expected requests. Please verify the endpoint and deployment, then contact Azure support with timestamps and request IDs for failing calls. We’re closing this here, but can reopen if a sanitized request capture shows incorrect SDK behavior.

marcuswood-oai avatar Sep 10 '26 21:09 marcuswood-oai