{"record":{"id":"8f907ff0d8d2b5e2","repo":"abi/screenshot-to-code","slug":"anthropic-api-key-is-missing","errorCode":null,"errorMessage":"Anthropic API key is missing.","messagePattern":"Anthropic API key is missing\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"backend/agent/providers/factory.py","lineNumber":56,"sourceCode":"        screenshot_enabled=is_screenshot_preview_available(),\n    )\n\n    if model in OPENAI_MODELS:\n        if not openai_api_key:\n            raise Exception(\"OpenAI API key is missing.\")\n\n        client = AsyncOpenAI(api_key=openai_api_key, base_url=openai_base_url)\n        return OpenAIProviderSession(\n            client=client,\n            model=model,\n            prompt_messages=prompt_messages,\n            tools=serialize_openai_tools(canonical_tools),\n            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,","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/abi/screenshot-to-code/blob/d026163f586dfa8c5c10d28c36edd59a9d3b0e88/backend/agent/providers/factory.py#L38-L74","documentation":"Raised by create_provider_session when the selected model is in ANTHROPIC_MODELS but anthropic_api_key (explicit arg) and the ANTHROPIC_API_KEY env var are both empty. Fail-fast guard before the AsyncAnthropic client is built; same pattern as the OpenAI/Gemini guards in the same factory.","triggerScenarios":"Generation requested with a Claude-family model while ANTHROPIC_API_KEY is unset in both the process environment and the request parameters.","commonSituations":"backend/.env missing or not loaded (load_dotenv path wrong), server started before the key was added, key provided only for a different provider, or CI environment without secrets.","solutions":["Set ANTHROPIC_API_KEY in backend/.env and restart uvicorn.","Or supply the key via the in-app Settings dialog.","Confirm the env var reaches the process (printenv ANTHROPIC_API_KEY in the server's shell).","Pick a model matching a key you already have."],"exampleFix":"# backend/.env\nANTHROPIC_API_KEY=sk-ant-...","handlingStrategy":"validation","validationCode":"import os\nif model in ANTHROPIC_MODELS and not os.environ.get(\"ANTHROPIC_API_KEY\"):\n    raise SystemExit(\"Set ANTHROPIC_API_KEY in backend/.env before using Claude 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\": \"anthropic\"}","preventionTips":["Keep all provider keys in backend/.env even if you mainly use one provider.","Verify env propagation into the service process (systemd/containers often drop vars).","Add a health endpoint reporting configured providers."],"tags":["api-key","anthropic","config","auth"],"backgroundTag":null,"analyzedSha":"d026163f586dfa8c5c10d28c36edd59a9d3b0e88","analyzedAt":"2026-08-14T22:02:06.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}