# Base64 file not going through api

**URL:** <https://community.openai.com/t/base64-file-not-going-through-api/1144263>\
**Category:** API\
**Created:** [March 16, 2025, 6:12am UTC](https://community.openai.com/t/base64-file-not-going-through-api/1144263 "2025-03-16T06:12:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dev\_D](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/dev_d/32/511823_2.png) [@Dev\_D](https://community.openai.com/u/Dev_D)\
**Post date:** [March 16, 2025, 6:12am UTC](https://community.openai.com/t/base64-file-not-going-through-api/1144263/1 "2025-03-16T06:12:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [March 16, 2025, 11:29am UTC](https://community.openai.com/t/base64-file-not-going-through-api/1144263/2 "2025-03-16T11:29:26Z")

</div>

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`

```auto
{
  "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`

```auto
{
  "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.

```auto
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._

 ![The image shows a section of documentation outlining parameters for a "file" object, including required and optional fields like "file_data," "file_id," "file_name," and "type." (Captioned by AI)](https://us1.discourse-cdn.com/openai1/original/4X/8/0/8/808f57083cfda6c6c1565246157ce719eb2d9b13.png)

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

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

---

<div class="post-metadata">

**Author:** ![Dev\_D](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/dev_d/32/511823_2.png) [@Dev\_D](https://community.openai.com/u/Dev_D)\
**Post date:** [March 17, 2025, 12:01pm UTC](https://community.openai.com/t/base64-file-not-going-through-api/1144263/3 "2025-03-17T12:01:50Z")

</div>

> [@\_j](#):
>
> `"file_data": "data:application/pdf;base64,JVBERi0xLjUNJeLjz9MNCjEgMCB..."`

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

---

<div class="post-metadata">

**Author:** ![risafj](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/risafj/32/626894_2.png) [@risafj](https://community.openai.com/u/risafj)\
**Post date:** [May 8, 2025, 10:00am UTC](https://community.openai.com/t/base64-file-not-going-through-api/1144263/4 "2025-05-08T10:00:17Z")

</div>

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?

```auto
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
  }
}

```

---

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [May 8, 2025, 10:44am UTC](https://community.openai.com/t/base64-file-not-going-through-api/1144263/5 "2025-05-08T10:44:16Z")

</div>

> [@\_j](#):
>
> JSON RESTful stuff

> [@risafj](#):
>
> Has this solution stopped working?

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.

```python
"""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)

```

---

<div class="post-metadata">

**Author:** ![risafj](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/risafj/32/626894_2.png) [@risafj](https://community.openai.com/u/risafj)\
**Post date:** [May 9, 2025, 6:41am UTC](https://community.openai.com/t/base64-file-not-going-through-api/1144263/6 "2025-05-09T06:41:00Z")

</div>

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