Can't use OAuth because upload file endpoint requires API key

Please make the https://generativelanguage.googleapis.com/upload/v1beta/files endpoint work with OAuth instead of only API key.
The documentation does not explain it well because other endpoints of the Gemini API work with the OAuth access token passed as a header.
However the file upload endpoint returns 403 Bad request errors. I then went in to the GenAI Python SDK to see if OAuth was possibly integrated differently but upon testing upload_file with my OAuth credentials loaded I received:

ValueError: Invalid operation: Uploading to the File API requires an API key. Please provide a valid API key.

I then tried passing both API key and Oauth to see what would happen and received:

ValueError: client_options.api_key and credentials are mutually exclusive

So if developers want to build an app that inferences on videos that are large or cannot be listed as public Youtube videos, we have to use an API key which means we can’t get the benefits of using OAuth for the other endpoints.
Basically forces developers who want to build an app using the great large video inferencing part of the Gemini API into creating some sort of centralized API key management server rather than allowing users to access APIs with their own OAuth access tokens.

Hi @Evan_Lesmez , Welcome to the forum.

I understand the difficulty you are encountering with integrating OAuth into the file upload endpoint. At the moment, file upload endpoint only supports API key authentication. One alternative you could try is uploading the video files to a GCS bucket and then passing the file URI inside the generate_content method for video inferencing.

Meanwhile, I will escalate this to the engineering team to explore any potential solutions or workarounds that might enable OAuth support for file upload.

Thanks..

1 Like

Thanks for the reference to the GCS bucket option. If this is possible why is it not included in the Gemini API documentation Explore vision capabilities with the Gemini API  |  Google AI for Developers ?

@Evan_Lesmez I think the use of gsutil paths (from files stored on GCS buckets) for inference is only possible with the Vertex API (aiplatform.googleapis.com service), which the link from @GUNAND_MAYANGLAMBAM redirects to. And not the Gemini API you’ve linked (which uses the generativelanguage.googleapis.com service).

I’ve also been trying to find a way to infer with GCS stored files using the Gemini API, but with no success. @GUNAND_MAYANGLAMBAM could you please confirm if this is indeed not possible? Or point to the right documentation/cookbook for suitable examples if it is? Thanks!