#PDF URL not working with AI SDK V5 streamText with OpenRouter

5 messages · Page 1 of 1 (latest)

umbral cosmos
#

PDF URLs are failing when using streamText() with the OpenRouter provider.

Errors observed:

  • For large files (~30 MB):

    File is too large: 30240707 bytes
    
  • For smaller files (most of the time):

    "errorText": "{"code":400,"message":"Provider returned error","type":null,"param":null}"
    

Code setup:

const result = streamText({
  model: openrouter('google/gemini-2.5-flash'),
  messages: [{
    role: 'user',
    content: [
      { type: 'text', text: 'What is in this file?' },
      { type: 'file', data: 'https://...pdf', mimeType: 'application/pdf' }
    ]
  }]
});

This same setup works perfectly with the Google AI SDK directly.
Even for smaller PDFs it takes so much time to respond. It is working fine if we provide the base64 url but not with direct public or presigned urls hosted in cloudflare R2

fallow turtleBOT
#

I'm an AI assistant - my answers may be incorrect and I cannot see screenshots. Please verify information with the OpenRouter docs.

To help debug this issue, I need more information:

  • What is the exact error message or stack trace for the "Provider returned error" (the full HTTP response, including any subfields)?
  • What is the exact public or presigned PDF URL format you are sending (obfuscate sensitive parts, but show the structure)?
  • Have you tried specifying a PDF plugin engine (eg. "pdf-text" or "mistral-ocr") in your OpenRouter API request?

These details will help pinpoint whether this is a file accessibility, parsing, or provider compatibility issue.

-# This is an automated response powered by Answer HQ. Use !mute to stop the bot from responding.

The author you are looking for could not be found.

umbral cosmos
#

Yes I tried the PDF plugin it's not working same error.
Also the error message is same what I have mentioned above.

fallow turtleBOT
#

Thank you for the details. Here are a few key points and troubleshooting steps based on the documentation:


1. File Size Limitation:
The error

File is too large: 30240707 bytes

means your PDF exceeds the allowed upload size for OpenRouter. You must use PDFs smaller than the current size limit. The docs state:
"For large files (~30 MB): File is too large..."
So try uploading a PDF well below this size, ideally under 20 MB for reliability.

2. "Provider returned error" on Small PDFs:
This may occur if your public or presigned URL is not fully accessible to OpenRouter’s servers, or if the format is not accepted. OpenRouter requires the file to be:

  • Publicly accessible (no tokens, no authentication)
  • Direct link to the file (the link must let anyone download it without credentials)

"For publicly accessible PDFs, you can send the URL directly without needing to download and encode the file"
Check that your Cloudflare R2 URLs are truly public and not expiring or IP-locked. Test by opening the link in an incognito window.

3. Required Payload Structure:
For a PDF via URL, your message content should look like:

{
  "role": "user",
  "content": [
    { "type": "text", "text": "What are the main points in this document?" },
    {
      "type": "file",
      "file": {
        "filename": "document.pdf",
        "file_data": "https://full-public-url/document.pdf"
      }
    }
  ]
}

"PDFs can be sent as direct URLs or base64-encoded data URLs in the messages array, via the file content type. This feature works on any model on OpenRouter."
PDF Inputs | OpenRouter Docs


Recommendations:

  • Ensure PDFs are <20 MB
  • URLs must be **fully public and direct...
#

...**

  • Use the plugins parameter if the model does not natively handle files:
    "plugins": [
      {
        "id": "file-parser",
        "pdf": { "engine": "pdf-text" } // or "mistral-ocr", or "native"
      }
    ]
    
    PDF Plugin Configuration

If you have verified the above and still see the "Provider returned error" for small, public files, contact [email protected] for further assistance.
PDF Inputs | OpenRouter Docs

-# This is an automated response powered by Answer HQ. Use !mute to stop the bot from responding.