Base64 file not going through api

I am trying to follow this steps given in api documentations File Inputs page (Cant include link)

My Code:
{
“uri”: “/v1/chat/completions”,
“method”: “POST”,
“headers”: {
“Authorization”: “sanitized”,
“Content-Type”: “application/json”
},
“body”: {
“model”: “gpt-4o”,
“messages”: [
{
“role”: “user”,
“content”: [
{
“type”: “file”,
“file”: {
“file_name”: “Client.pdf”,
“file_data”: “Base64String”
}
},
{
“type”: “text”,
“text”: “Give me a summary of the pdf.”
}
]
}
]
}
}

It throws in the error:
{
“error”: {
“message”: “Missing required parameter: ‘messages[1].content[0].file.file_id’.”,
“type”: “invalid_request_error”,
“param”: “messages[1].content[0].file.file_id”,
“code”: “missing_required_parameter”
}

Like i am copying the format but it doesn’t work.
Please help

I have removed the link as it wont allow it

Here is a request body successfully fulfilled by the API Prompts Playground, including base64 of a PDF as file content part.

Chat Completions

POST https://api.openai.com/v1/chat/completions

{
  "messages":[
    {
      "role":"user",
      "content":[
        {
          "type":"text",
          "text":"Summarize PDF"
        },
        {
          "type":"file",
          "file":{
            "file_data":"data:application/pdf;base64,JVBERi0xLjUNJeLjz9MN...",
            "filename":"competion-sidebar.pdf"
          }
        }
      ]
    }
  ],
  "temperature":1,
  "max_completion_tokens":2048,
  "top_p":0.05,
  "model":"gpt-4o",
  "response_format":{
    "type":"text"
  },
  "stream":true,
  "stream_options":{
    "include_usage":true
  }
}

Responses

POST https://api.openai.com/v1/responses

{
  "model": "gpt-4o",
  "input": [
    {
      "role": "user",
      "content": [
        {
          "type": "input_text",
          "text": "Summarize PDF"
        },
        {
          "type": "input_file",
          "filename": "competion-sidebar.pdf",
          "file_data": "data:application/pdf;base64,JVBERi0xLjUNJeLjz9MNCjEgMCB..."
        }
      ]
    }
  ],
  "tools": [],
  "text": {
    "format": {
      "type": "text"
    }
  },
  "temperature": 1,
  "top_p": 0.05,
  "reasoning": {},
  "stream": true,
  "max_output_tokens": 2048,
  "store": true
}

Headers filtered down to developer-provided, including a
OpenAI-Beta: responses=v1 header likely used before release.

Content-Type: application/json
Authorization: Bearer (sessiontoken)
OpenAI-Organization: org-1234
OpenAI-Project: proj_1234
OpenAI-Beta: responses=v1

Analysis

Your payload keys are incorrect when compared:

  • Change file_name → filename.
  • Prefix your file_data with data:application/pdf;base64,.

The API reference seems to be in error if the Playground is recommended or the only working key, using a data URL.

Make these two corrections and your inline base64 upload should succeed.

(nothing is a “link” when you use the forum’s preformatted text formatting)

Thank you very much, I was able to get the pdf working.

I am having the same issue, where I have an error when I use a base64-encoded file in the responses request. Has this solution stopped working?

curl "https://api.openai.com/v1/responses" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer {token}" \
    -d '{
        "model": "gpt-4.1",
        "input": [
            {
                "role": "user",
                "content": [
                    {
                        "type": "input_file",
                        "filename": "resume.pdf",
                        "file_data": "data:application/pdf;base64,'$BASE64_CONTENT'"
                    },
                    {
                        "type": "input_text",
                        "text": "Read my resume"
                    }
                ]
            }
        ]
    }'

{
  "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 help.openai.com if you keep seeing this error. (Please include the request ID req_XX in your email.)",
    "type": "server_error",
    "param": null,
    "code": null
  }
}

PDF input is still functional with the parameters showing.

You can upgrade your curling to a programming language. Here’s Python scripting for the Responses endpoint, and a template-like API call body using the base64 encoded PDF file specified.

"""httpx responses RESTful API call using pdf file user input"""
import base64
import httpx
import os

PDF_FILENAME = "test1.pdf"

with open(PDF_FILENAME, "rb") as f:
    file_data = base64.b64encode(f.read()).decode()

payload = {
    "model": "gpt-4o",
    "input": [
        {
            "role": "user",
            "content": [
                {"type": "input_text", "text": "Summarize PDF"},
                {
                    "type": "input_file",
                    "filename": PDF_FILENAME,
                    "file_data": f"data:application/pdf;base64,{file_data}"
                }
            ]
        }
    ],
    "tools": [],
    "text": {"format": {"type": "text"}},
    "temperature": 1,
    "top_p": 0.05,
    "stream": False,
    "max_output_tokens": 2048,
    "store": False
}

response = httpx.post(
    "https://api.openai.com/v1/responses",
    json=payload,
    headers={
        "Authorization": f"Bearer {os.environ['OPENAI_API_KEY']}",
        "OpenAI-Beta": "responses=v1"  # undocumented
    },
    timeout=60
)
response.raise_for_status()

assistant_texts = [
    content["text"]
    for output in response.json().get("output", [])
    for content in output.get("content", [])
    if content.get("type") == "output_text" and "text" in content
]

print(assistant_texts)

You’re right, thanks! It was an issue with curl truncating the base64 string.