Independent community project. Not affiliated with or endorsed by Google.
ModelCraft modelcraft.dev
← All Fix Guides
critical ✓ Verified: 2026-11-26 gemini-cli 0.71.1 / gcloud 500+
auth google agygemini-cligemini-api

401 / 403 Permission Denied & OAuth / Project Mismatch

401 403 UNAUTHENTICATED PERMISSION_DENIED ACCESS_TOKEN_TYPE_UNSUPPORTED
Matching Symptoms
  • • CLI or IDE throws `403 Permission Denied` or `cloudaicompanion...denied` after switching accounts.
  • • `ACCESS_TOKEN_TYPE_UNSUPPORTED` when mixing Application Default Credentials with Consumer API endpoints.
  • • Workspace/Enterprise admin account fails without `GOOGLE_CLOUD_PROJECT` set.
Root Cause

Stale OAuth grant, mismatched `GOOGLE_CLOUD_PROJECT`, or mixing an AI Studio API key with Vertex/ADC OAuth credentials.

Step-by-Step Fix

  1. 1 Revoke the stale third-party/CLI app grant at https://myaccount.google.com/connections if switching Google accounts.
  2. 2 Clear local Gemini CLI / gcloud cached credentials (never print token contents).
  3. 3 Explicitly export GOOGLE_CLOUD_PROJECT when using Vertex AI or Workspace-managed seats.
  4. 4 Re-authenticate cleanly via gcloud auth application-default login or the built-in CLI login flow.

Copyable Commands

Set explicit Google Cloud Project ID (unix)
export GOOGLE_CLOUD_PROJECT="your-project-id"
Re-authenticate Application Default Credentials (all)
gcloud auth application-default login
Clear Gemini CLI OAuth cache (macOS/Linux) (unix)
rm -rf ~/.gemini/oauth_creds.json ~/.config/gemini-cli/auth*

Verify Fix

Verify
gcloud config get-value project && npx agycraft-mcp doctor