Error reference

Gemini API billing and quota errors

The answers Gemini API gives when an organization cannot pay for a request, and the ones that look similar but are not about money. For each: the status, the body, and what keyover does with it.

Rejections about money or the key

402Your prepayment credits are depleted

Moves to the next key: out of credit

Since 2026-09-18. Before that date the same failure was a 429.

{
  "error": {
    "code": 402,
    "message": "Your prepayment credits are depleted.",
    "status": "RESOURCE_EXHAUSTED"
  }
}

Documented by Gemini API: discuss.ai.google.dev. The body shows the fields the source establishes.

402Prepay credit balance is depleted (Interactions API)

Moves to the next key: out of credit

{
  "error": {
    "code": "payment_required"
  }
}

Documented by Gemini API: aistudio.google.com. The body shows the fields the source establishes.

400API key not valid. Please pass a valid API key

Moves to the next key: key not accepted

The generateContent form. Only the API_KEY_INVALID reason matches, never a plain 400.

{
  "error": {
    "code": 400,
    "message": "API key not valid. Please pass a valid API key.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "API_KEY_INVALID"
      }
    ]
  }
}

Reported in the field: discuss.ai.google.dev. The body shows the fields the source establishes.

401API key is missing, invalid or expired (Interactions API)

Moves to the next key: key not accepted

{
  "error": {
    "code": "authentication"
  }
}

Documented by Gemini API: aistudio.google.com. The body shows the fields the source establishes.

Answers that are not a reason to change key

429You have exceeded your daily quota

Stays with your SDK

A quota, free tier included, is not credit. The pool never moves a request for it.

{
  "error": {
    "code": "quota_exceeded"
  }
}

Documented by Gemini API: aistudio.google.com. The body shows the fields the source establishes.

400Billing is not enabled for the project

Stays with your SDK

A setup problem. Enable billing on the project.

{
  "error": {
    "code": "failed_precondition"
  }
}

Documented by Gemini API: aistudio.google.com. The body shows the fields the source establishes.

403Key lacks permission, or the project is restricted

Stays with your SDK

An access restriction. Never routed around.

{
  "error": {
    "code": "permission_denied"
  }
}

Documented by Gemini API: aistudio.google.com. The body shows the fields the source establishes.

Keep serving through it

Give the pool a second key that bills another organization you are authorized to use. When Gemini API refuses the first for one of the rejections above, the same request is sent again on the second, inside the same call. Your code gets a normal response, and an event tells you which organization needs attention.

import { createGoogleGenerativeAI } from "@ai-sdk/google"
import { createKeyPool, GEMINI } from "keyover"

const pool = createKeyPool({
  provider: GEMINI,
  keys: {
    primary: process.env.GEMINI_API_KEY,
    spare: process.env.GEMINI_API_KEY_SPARE,
  },
})

const google = createGoogleGenerativeAI(pool.clientOptions)

See it fail over in the playground, or read the README.