{"record":{"id":"5c5a57bb6ed6f6f3","repo":"abi/screenshot-to-code","slug":"gemini-api-key-is-missing","errorCode":null,"errorMessage":"Gemini API key is missing.","messagePattern":"Gemini API key is missing\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"backend/agent/providers/factory.py","lineNumber":69,"sourceCode":"            recorder=recorder,\n        )\n\n    if model in ANTHROPIC_MODELS:\n        if not anthropic_api_key:\n            raise Exception(\"Anthropic API key is missing.\")\n\n        client = AsyncAnthropic(api_key=anthropic_api_key)\n        return AnthropicProviderSession(\n            client=client,\n            model=model,\n            prompt_messages=prompt_messages,\n            tools=serialize_anthropic_tools(canonical_tools),\n            recorder=recorder,\n        )\n\n    if model in GEMINI_MODELS:\n        if not gemini_api_key:\n            raise Exception(\"Gemini API key is missing.\")\n\n        client = genai.Client(api_key=gemini_api_key)\n        return GeminiProviderSession(\n            client=client,\n            model=model,\n            prompt_messages=prompt_messages,\n            tools=serialize_gemini_tools(canonical_tools),\n            recorder=recorder,\n        )\n\n    raise ValueError(f\"Unsupported model: {model.value}\")\n","sourceCodeStart":51,"sourceCodeEnd":81,"githubUrl":"https://github.com/abi/screenshot-to-code/blob/d026163f586dfa8c5c10d28c36edd59a9d3b0e88/backend/agent/providers/factory.py#L51-L81","documentation":"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.","triggerScenarios":"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).","commonSituations":"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).","solutions":["Set GEMINI_API_KEY in backend/.env (Google AI Studio key) and restart the backend.","Or provide it through the Settings dialog.","Double-check the exact name is GEMINI_API_KEY, not GOOGLE_API_KEY.","Select a model family that matches an existing key."],"exampleFix":"# backend/.env\nGEMINI_API_KEY=AIza...","handlingStrategy":"validation","validationCode":"import os\nif model in GEMINI_MODELS and not os.environ.get(\"GEMINI_API_KEY\"):\n    raise SystemExit(\"Set GEMINI_API_KEY in backend/.env before using Gemini models\")","typeGuard":null,"tryCatchPattern":"try:\n    session = create_provider_session(model=model, ...)\nexcept Exception as e:\n    if \"API key is missing\" in str(e):\n        return {\"error\": \"missing_key\", \"provider\": \"gemini\"}","preventionTips":["Use the exact name GEMINI_API_KEY (not GOOGLE_API_KEY).","Remember the same key gates extract_assets — set it even when chatting via other providers.","Restart the backend after key changes."],"tags":["api-key","gemini","config","auth"],"backgroundTag":null,"analyzedSha":"d026163f586dfa8c5c10d28c36edd59a9d3b0e88","analyzedAt":"2026-08-14T22:02:06.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}