#Agents SDK returning "400 input[*].content[1].file_data is invalid" when I try to send a PDF

1 messages · Page 1 of 1 (latest)

serene osprey
#

Hi there!

So, I'm trying to send a PDF url to my agent using the agents sdk for TypeScript and it returns this bad request error.
It works with images, but not with documents for some reason.

Here's an example of how my input object looks like:

serene osprey
#

UPDATE:

So, for anyone going through this same problem, I found a "dirty" solution:

It seems that the agent sdk provided in NPM doesnt support documents being sent as a URL.

When you send a string in the "file" property, it assumes it's a base64 encoded file and send it to the api.

So, I manually edited the node module dist file to include this:

if (typeof entry.file === 'string') {
if (/http|https/.test(entry.file)) {
fileEntry.file_url = entry.file;
} else {
fileEntry.file_data = entry.file;
}
}

And it worked!

I checked in the official github repository and this seems to be already patched there:

https://github.com/openai/openai-agents-js/blob/5413e4f8091691b590adab6df4e4e7b1767c1bc1/packages/agents-openai/src/openaiResponsesModel.ts#L264

Maybe the npm module is outdated? You could try to use the github version but I didn't do that because I was afraid that it could break something in my project

GitHub

A lightweight, powerful framework for multi-agent workflows and voice agents - openai/openai-agents-js