GeminiError.com

Gemini API

Fix Gemini API 401 and 403 errors.

A 401 or 403 means the request reached Google, but the credentials, project, API enablement, key restrictions, endpoint or permissions were not accepted.

Auth checklist

Check credentials before changing code.

API key

  1. Confirm the key is present in the runtime environment.
  2. Create a fresh key if rotation or copy-paste mistakes are possible.
  3. Check HTTP referrer, IP or app restrictions.
  4. Never paste API keys into public logs or support tickets.

Project and API

  1. Confirm the Google Cloud project is the intended one.
  2. Enable the correct Gemini or Vertex AI API for that project.
  3. Check billing and project permissions.
  4. Verify service account or user role access if applicable.

Request

  1. Check endpoint, region and model name.
  2. Confirm the credential type matches the endpoint.
  3. Log the response body and status without exposing secrets.
  4. Test the same prompt in AI Studio to isolate app code.