# Files API issue when sending pdf files to extract out info

**URL:** <https://community.openai.com/t/files-api-issue-when-sending-pdf-files-to-extract-out-info/1277567>\
**Category:** Bugs\
**Created:** [June 4, 2025, 3:38am UTC](https://community.openai.com/t/files-api-issue-when-sending-pdf-files-to-extract-out-info/1277567 "2025-06-04T03:38:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![imobile](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/imobile/32/637640_2.png) [@imobile](https://community.openai.com/u/imobile)\
**Post date:** [June 4, 2025, 3:38am UTC](https://community.openai.com/t/files-api-issue-when-sending-pdf-files-to-extract-out-info/1277567/1 "2025-06-04T03:38:03Z")

</div>

We’re trying to use Files API via javascript to extract some info.  
Here’s code to extract out info.

async analyzeCOI(files: { file: any; fileName: string }, prompt: string) {  
const uploadedFiles = ;  
try {  
// 1. Upload files to OpenAI  
for (const file of files) {  
const uploaded = await this.client.files.create({  
file: file.file,  
// purpose: “assistants”,  
purpose: “user\_data”,  
});  
uploadedFiles.push(uploaded);  
}  
const fileIds = uploadedFiles.map((f) =\> f.id);

````
  // 2. Build content array: all files + prompt
  // const filePromises = files.map(async (file) => {
  // const base64 = await fileToBase64(file.file);
  // return {
  // type: "file",
  // file: {
  // filename: file.fileName,
  // file_data: `${base64}`,
  // },
  // };
  // });

  const content = [
    // ...(await Promise.all(filePromises)),
    ...fileIds.map((id) => ({
      type: "file",
      file: {
        file_id: id,
      },
    })),
    {
      type: "text",
      text: prompt,
    },
  ];

  // 3. Call chat/completions API
  // add 1s delay
  await new Promise((resolve) => setTimeout(resolve, 3000));
  const completion = await this.client.chat.completions.create({
    // model: "gpt-4o",
    // model: "gpt-4.1",
    model: "gpt-4.5-preview",
    messages: [
      {
        role: "user",
        content,
        file_ids: fileIds,
      },
    ],
    // max_tokens: 2048,
  });

  // 4. Parse result
  const responseText = completion.choices?.[0]?.message?.content || "";

  // console.log("responseText: ", responseText);
  // 5. Try to extract insuranceData from AI result
  let insuranceData = [];
  const jsonMatch = responseText.match(/```json\n([\s\S]*?)\n```/);
  // console.log("jsonMatch: ", jsonMatch);

  if (jsonMatch?.[1]) {
    // console.log("jsonMatch[1]: ", jsonMatch[1]);
    insuranceData = await JSON.parse(jsonMatch[1]);
  } else {
    const match = responseText.match(/\[[\s\S]*\]|\{[\s\S]*\}/);
    insuranceData = await JSON.parse(match?.[0] || responseText);
  }

  return insuranceData;
} finally {
  // 6. Clean up: Delete uploaded files from OpenAI storage
  console.log("deleting files: ", uploadedFiles);
  // for (const uploaded of uploadedFiles) {
  // try {
  // await this.client.files.delete(uploaded.id);
  // } catch (e) {
  // console.error("Error deleting file: ", e);
  // }
  // }
}

````

}  
}

Sometimes we received message from

Request URL  
v1/chat/completions

Request Method: POST

{  
“id”: “chatcmpl-BeZ5uEV8tuim1I6BksjS26VfWYzku”,  
“object”: “chat.completion”,  
“created”: 1749007722,  
“model”: “gpt-4.5-preview-2025-02-27”,  
“choices”: [  
{  
“index”: 0,  
“message”: {  
“role”: “assistant”,  
“content”: “Please provide the document you would like me to analyze. Once I receive the document, I will analyze and return the extracted insurance details in the specified JSON format.”,  
“refusal”: null,  
“annotations”:   
},  
“finish\_reason”: “stop”  
}  
],  
“usage”: {  
“prompt\_tokens”: 503,  
“completion\_tokens”: 32,  
“total\_tokens”: 535,  
“prompt\_tokens\_details”: {  
“cached\_tokens”: 0,  
“audio\_tokens”: 0  
},  
“completion\_tokens\_details”: {  
“reasoning\_tokens”: 0,  
“audio\_tokens”: 0,  
“accepted\_prediction\_tokens”: 0,  
“rejected\_prediction\_tokens”: 0  
}  
},  
“service\_tier”: “default”,  
“system\_fingerprint”: null  
}

```
    "content": "Please provide the document you would like me to analyze. Once I receive the document, I will analyze and return the extracted insurance details in the specified JSON format.", is very puzzled to us. Clearly we have waited for 3sec to complete uploading the file attached. It doesn't always happen but happen often enough.

```

We’ve been struggling on this issue for a while. Anyone has any suggestions to work around this issue? Very appreciate any inputs.

---

<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:** [June 4, 2025, 7:00am UTC](https://community.openai.com/t/files-api-issue-when-sending-pdf-files-to-extract-out-info/1277567/2 "2025-06-04T07:00:40Z")

</div>

This has been an ongoing issue with the PDF file service.

## 100 tests

_Token usage shows files are not supplied to the AI_

* * *

I ran a slow loop of 100 calls using two small PDF files for vision only, uploaded each time, then a sleep. Then asking about them via chat completions, reversing the input files being uploaded each time (which for base64 instead of file\_id, exhibits another immediate problem of only the last PDF being seen).

I used both a random user parameter and a time() nonce in user message to break caching.

The input prompt usage collected for these tells the tale of the unreliability of the endpoint:

`>>>prompt_usages`  
`[1874, 1874, 62, 1874, 1874, 62, 1874, 62, 1874, 1874, 62, 62, 1874, 62, 1874, 1874, 62, 62, 1874, 1874, 62, 1874, 1874, 62, 62, 1874, 1874, 1874, 62, 1874, 1874, 62, 62, 1874, 62, 62, 1874, 1874, 62, 62, 62, 1874, 1874, 62, 62, 62, 62, 62, 62, 62, 62, 1874, 62, 62, 62, 1874, 1874, 62, 62, 1874, 62, 1874, 62, 62, 1874, 1874, 62, 1874, 1874, 62, 1874, 62, 1874, 62, 62, 1874, 1874, 1874, 62, 1874, 1874, 62, 1874, 62, 62, 1874, 62, 62, 62, 62, 1874, 1874, 1874, 1874, 1874, 62, 1874, 62, 62, 1874]`

```auto
>>>print(usage_counts)
Counter({62: 51, 1874: 49})

```

50% of the PDF calls to chat completions (and gpt-4.1-nano in this case but seen on all others) FAIL to provide the AI the PDF contents.

## The PDF input\_file feature is broken

This topic has been flagged to OpenAI:

> [@Files upload not working. Agent responds with "Please upload a file for me to analyze"](https://community.openai.com/t/files-upload-not-working-agent-responds-with-please-upload-a-file-for-me-to-analyze/1259129/13):
>
> I ran a loop, and got the same intermittent usage of PDFs. Uploaded File IDs: ['file-NoPEQiYGR6BjPPdynX6RvB', 'file-XkxYoEDc4LrtDYEpru3tvn'] 1. Filenames of PDFs received: - test1.pdf - test2.pdf 2. Document's website title (from test1.pdf): - "My Joke Website" 3. Costs of brand new GPT-4.1 AI model (from test2.pdf): - Input: $2.00 per 1M tokens - Cached input: $0.50 per 1M tokens - Output: $8.00 per 1M tokens ============= Uploaded File IDs: ['file-PQGbv5ecsMGmEev7R7JS13'…

---

<div class="post-metadata">

**Author:** ![jrstrope](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@jrstrope](https://community.openai.com/u/jrstrope)\
**Post date:** [June 4, 2025, 9:14pm UTC](https://community.openai.com/t/files-api-issue-when-sending-pdf-files-to-extract-out-info/1277567/3 "2025-06-04T21:14:22Z")

</div>

I’ve started testing the responses API with PDFs and I’m not seeing the same issue there. Perhaps too early to tell, but I’ve run around a dozen PDFs through it and I’m not seeing the same intermittent “No PDF file included” responses there.
