"Request contains an invalid argument" when use uploaded PDF

Hi team,
I’m trying to use and upload uri from a PDF (previosly uploaded by API to https://generativelanguage.googleapis.com/v1beta/files/) and always receive an 400 Error ( “code”: 400, “message”: “Request contains an invalid argument.”, “status”: “INVALID_ARGUMENT” ) when add the fileData to the request.

The request structure seems correct:
-if I send empty the fileUri field I receive a correct error (Invalid or unsupported file uri).
-If I send with the mimeType empyt also a correct error (Unable to submit request because it has a mimeType parameter with value application/json)
-If I inform them properly → Request contains an invalid argument

I’m using gemini-2.0-flash-exp

Any idea?

Thanks!

Hi @Dani_R , Welcome to the forum.

You probably used the wrong endpoint. Try using https://generativelanguage.googleapis.com/upload/v1beta/files.

Just prepare a Colab gist, you can also go through this.

Hope it helps…

Hi @GUNAND_MAYANGLAMBAM
Thanks for your help,
The endpoint seems correct and I receive the url for the uploaded file.
The issue it’s with the prompt request passing this fileUri.

I will try again

Thanks!

Hello @Dani_R,

I am experiencing the same issue. Were you able to resolve it? Could you offer assistance?

I await your response.

Thank you.

1 Like

Sorry @Diego_Retamal , I was not able to receive a correct response and I made the test finally in JS with the library @google/generative-ai and his methods

Hello @Dani_R, I resolved the issue. My mistake was in the initial file upload; I needed to first initiate the file with the appropriate Content-Length and Content-Type headers, followed by the upload of the file’s content.

Regards,

Hi,

I’m having the same problem here. Did you find a solution?

Thanks