gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

API keys are not supported by this API - Expected OAuth2 access token or other authentication credentials that assert a principal

Open Explosion-Scratch opened this issue 1 year ago • 12 comments

What happened?

How do I configure the CLI so that it uses Vertex AI - I've been trying for a while. My account isn't in express mode so I created a service account but that doesn't work - when creating new credentials in the APIs and Services tab it just immediately creates and shows me the API key, whereas this guide says I should be able to create a key specifically routed through the service account

What did you expect to happen?

To be able to use google's Vertex AI - not sure why this has to be so hard to do

Client information

  • CLI Version: 0.1.10
  • Git Commit: N/A
  • Operating System: darwin v21.7.3
  • Sandbox Environment: no sandbox
  • Model Version: gemini-2.5-pro
  • Memory Usage: 75.0 MB

Login information

No response

Anything else we need to know?

No response

Explosion-Scratch avatar Jul 11 '25 22:07 Explosion-Scratch

Are you seeing an error when using the API key with Gemini CLI or are there issues creating the API key itself?

anj-s avatar Jul 11 '25 22:07 anj-s

Did you follow https://cloud.google.com/vertex-ai/generative-ai/docs/start/api-keys?usertype=existinguser#modify-iam-policy to disable the org policy iam.managed.disableServiceAccountApiKeyCreation? If it is correctly disabled then the subsequent steps show the option to create service account API key, otherwise it just creates a project API key.

gsquared94 avatar Jul 12 '25 00:07 gsquared94

Yes, but the options you edit the policy is grayed out. I am using a Google personal account not a work account or managed account

Explosion-Scratch avatar Jul 12 '25 16:07 Explosion-Scratch

+1, this is actually a hard blocker for personal accounts who want to go through Vertex API

youngmae avatar Jul 15 '25 17:07 youngmae

same issue here

omidahn avatar Jul 21 '25 18:07 omidahn

same issue here

bohui avatar Jul 22 '25 04:07 bohui

same issue here

aqua4 avatar Jul 28 '25 11:07 aqua4

same issue here

freddybihozagara avatar Aug 01 '25 07:08 freddybihozagara

same issue here

miebh avatar Aug 04 '25 08:08 miebh

According to this PR , remove the env variable GOOGLE_GENAI_USE_VERTEXAI (if you had set it), and set the following variables:

  1. GOOGLE_CLOUD_PROJECT
  2. GOOGLE_CLOUD_PROJECT

This fixed it for me

SatvikNema avatar Aug 11 '25 12:08 SatvikNema

  1. GOOGLE_CLOUD_PROJECT
  2. GOOGLE_CLOUD_PROJECT

It looks like you mean GOOGLE_CLOUD_LOCATION for the second one 😄

Explosion-Scratch avatar Aug 11 '25 18:08 Explosion-Scratch

Opened 6193 to update the docs.

  1. Unset GOOGLE_API_KEY, set GOOLE_CLOUD_LOCATION(say us-central1) and GOOGLE_CLOUD_PROJECT
  2. Environment:
    • Running locally: Be logged in to gcloud, or run gcloud auth application-default login. Or,
    • Running on a server: If you need to use a service account then download the service account private key json and set GOOGLE_APPLICATION_CREDENTIALS to that file path.
    • See https://cloud.google.com/iam/docs/migrate-from-service-account-keys#remediate-existing-workloads for other ways to authenticate with ADC.

gsquared94 avatar Aug 14 '25 02:08 gsquared94