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_namefilename.
  • 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.