google-cloud-platformapi-keygoogle-cloud-vertex-aigoogle-geminispring-ai

Why should I get credentialsUri when I have got a api-key?


When I follow this tuition try to acess gemini, I got a error:

Your default credentials were not found. To set up Application Default Credentials for your environment, see https://cloud.google.com/docs/authentication/external/set-up-adc.

And I did not run these command because I had a api-key

gcloud config set project PROJECT_ID &&
gcloud auth application-default login ACCOUNT

From the gemini api-key page, the api-key is the only param

curl \
  -H 'Content-Type: application/json' \
  -d '{"contents":[{"parts":[{"text":"Write a story about a magic backpack"}]}]}' \
  -X POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=YOUR_API_KEY'

I want to known did the spring-ai use oauth2 instead of api-key to interact with gemini? Could I replace credentialsUri with api-key in some ways?

Can anyone give me a explanation? thx!


Solution

  • The issue you are having is that there are two different systems. Which is confusing and I cant tell you why google did it this way.

    Fist you need to understand from the underling AI model standpoint "gemini-pro" is just an ai model.

    There are however two different APIs / systems which access it.

    Vertex AI

    Is the google cloud based version for lack of a better term. It is not free to use and to use it everything is stored on your Google Cloud account. There for it requires a service account to access it.

    Gemini API

    Is the system behind Google AI studio. Currently and up until May 02, 2024 see pricing Gemini Api is free to use. Gemini API does not require Oauth2 unless you are tuning models. It runs all off of an api key which you must create on Google AI studio.

    anwser

    So yes the spring example us using Vertex so is most likely running off of a service account.

    Your default credentials were not found

    With google cloud you when you sign into your cloud environment via the cli it sets the env var that the Vertex code is looking for.

    See: Set up Application Default Credentials