File inputs using Base64-encoded files not working

Ali Beyram 15 Reputation points
2025-04-23T03:48:46.8666667+00:00

I am trying to use the the file inputs to upload a PDF but I am getting the following error message

The server had an error processing your request. Sorry about that! You can retry your request, or contact us through our help center at [email protected] if you keep seeing this error. ....

I tried the email but it is only available for internal Microsoft employees.

here is simple code to reproduce it


import base64
import os

from openai import AzureOpenAI


client = AzureOpenAI(
    api_version="2025-03-01-preview",
    azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
    api_key=os.getenv("AZURE_OPENAI_API_KEY"),
)

with open("example.pdf", "rb") as f:
    data = f.read()

base64_string = base64.b64encode(data).decode("utf-8")

response = client.responses.create(
    model="gpt-4.1-mini",
    input=[
        {
            "role": "user",
            "content": [
                {
                    "type": "input_file",
                    "filename": "example.pdf",
                    "file_data": f"data:application/pdf;base64,{base64_string}",
                },
                {
                    "type": "input_text",
                    "text": "what is document about?",
                },
            ],
        },
    ],
)
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,950 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.