abi/screenshot-to-code · critical · Exception

Gemini API key is missing.

Error message

Gemini API key is missing.

What it means

Raised by create_provider_session when the selected model is in GEMINI_MODELS but gemini_api_key (explicit arg) and the GEMINI_API_KEY env var are both empty. Note this same key also gates the extract_assets tool and the asset-extraction benchmark, so a missing Gemini key disables more than just Gemini chat models.

Source

Thrown at backend/agent/providers/factory.py:69

            recorder=recorder,
        )

    if model in ANTHROPIC_MODELS:
        if not anthropic_api_key:
            raise Exception("Anthropic API key is missing.")

        client = AsyncAnthropic(api_key=anthropic_api_key)
        return AnthropicProviderSession(
            client=client,
            model=model,
            prompt_messages=prompt_messages,
            tools=serialize_anthropic_tools(canonical_tools),
            recorder=recorder,
        )

    if model in GEMINI_MODELS:
        if not gemini_api_key:
            raise Exception("Gemini API key is missing.")

        client = genai.Client(api_key=gemini_api_key)
        return GeminiProviderSession(
            client=client,
            model=model,
            prompt_messages=prompt_messages,
            tools=serialize_gemini_tools(canonical_tools),
            recorder=recorder,
        )

    raise ValueError(f"Unsupported model: {model.value}")

View on GitHub (pinned to d026163f58)

Solutions

  1. Set GEMINI_API_KEY in backend/.env (Google AI Studio key) and restart the backend.
  2. Or provide it through the Settings dialog.
  3. Double-check the exact name is GEMINI_API_KEY, not GOOGLE_API_KEY.
  4. Select a model family that matches an existing key.

Example fix

# backend/.env
GEMINI_API_KEY=AIza...
Defensive patterns

Strategy: validation

Validate before calling

import os
if model in GEMINI_MODELS and not os.environ.get("GEMINI_API_KEY"):
    raise SystemExit("Set GEMINI_API_KEY in backend/.env before using Gemini models")

Try / catch

try:
    session = create_provider_session(model=model, ...)
except Exception as e:
    if "API key is missing" in str(e):
        return {"error": "missing_key", "provider": "gemini"}

Prevention

When it happens

Trigger: Generation requested with a Gemini model while GEMINI_API_KEY is unset, or asset extraction requested without the key (tool is silently not advertised instead).

Common situations: Only OPENAI/ANTHROPIC keys configured but a Gemini model selected in the UI; .env edited after server start without restart; key name typo (GOOGLE_API_KEY vs GEMINI_API_KEY).

Related errors


AI-assisted analysis of abi/screenshot-to-code@d026163f58 (2026-08-14). Data as JSON: /api/errors/5c5a57bb6ed6f6f3. Report an issue: GitHub.