continuedev/continue · warning

Failed to fetch Gemini models: ${response.status}

Error message

Failed to fetch Gemini models: ${response.status}

What it means

Thrown by fetchGeminiModels when the Google Generative Language models endpoint returns non-OK. The API key is passed as a URL query parameter, so an invalid/missing key typically yields 400/403, while network or quota issues yield other statuses.

Source

Thrown at core/llm/fetchModels.ts:185

    name: m.display_name ?? m.id,
    modelId: m.id,
    icon: "anthropic.png",
    contextLength: m.max_input_tokens,
    maxTokens: m.max_tokens,
    supportsTools: true,
  }));
}

async function fetchGeminiModels(
  apiKey?: string,
  apiBase?: string,
): Promise<FetchedModel[]> {
  const base = apiBase || "https://generativelanguage.googleapis.com/v1beta/";
  const url = new URL("models", base);
  url.searchParams.set("key", apiKey ?? "");
  const response = await fetch(url);
  if (!response.ok) {
    throw new Error(`Failed to fetch Gemini models: ${response.status}`);
  }
  const data = await response.json();
  return (data.models ?? [])
    .filter((m: any) => {
      const id: string = m.name?.replace("models/", "") ?? "";
      const methods: string[] = m.supportedGenerationMethods ?? [];
      return (
        !id.startsWith("gemini-2.0") &&
        !id.startsWith("gemma-") && // Gemma models are supported through Ollama, not the Gemini API
        !id.startsWith("nano-banana") &&
        !id.startsWith("lyria") &&
        methods.includes("generateContent") &&
        !methods.includes("embedContent") &&
        !methods.includes("predict") &&
        !methods.includes("predictLongRunning") &&
        !methods.includes("bidiGenerateContent") &&
        !id.includes("tts") &&
        !id.includes("image") &&

View on GitHub (pinned to 5522c6f44c)

Solutions

  1. Verify the API key is set, non-empty, and valid (test the same URL with curl)
  2. Strip whitespace/newlines from the key before use
  3. If apiBase is customized, confirm it points to a Gemini-compatible endpoint that accepts the 'key' query param
  4. Retry on 5xx/429 with backoff and check quota in Google AI Studio

Example fix

# before
apiKey=" sk-...\n"  # stray whitespace
# after
apiKey="sk-...".trim()
Defensive patterns

Strategy: try-catch

Validate before calling

const u = new URL('models', base); u.searchParams.set('key', apiKey.trim()); const r = await fetch(u); if (!r.ok) throw new Error(`Gemini list failed: ${r.status}`);

Try / catch

catch (e) { if (e.message.includes('Failed to fetch Gemini models')) { checkKeyAndQuota(); } else throw e; }

Prevention

When it happens

Trigger: Missing or malformed Gemini API key (key= empty or invalid), quota exceeded, or a custom apiBase that is wrong/unreachable.

Common situations: GEMINI_API_KEY unset or pasted with whitespace/newlines; using a proxy base URL that doesn't accept key-as-query-param; free-tier quota exhausted.

Related errors


AI-assisted analysis of continuedev/continue@5522c6f44c (2026-08-27). Data as JSON: /api/errors/7f1bf99476d680cb. Report an issue: GitHub.