{"record":{"id":"3da92545b57f5762","repo":"abi/screenshot-to-code","slug":"openai-api-key-not-found","errorCode":null,"errorMessage":"OpenAI API key not found","messagePattern":"OpenAI API key not found","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"backend/evals/core.py","lineNumber":46,"sourceCode":"    eval_session_id: str | None,\n    input_file: str | None,\n) -> str:\n    async def send_message(\n        _: str,\n        __: str | None,\n        ___: int,\n        ____: dict[str, Any] | None = None,\n        _____: str | None = None,\n    ) -> None:\n        # Evals do not stream tool/assistant messages to a frontend.\n        return None\n\n    if model in ANTHROPIC_MODELS and not ANTHROPIC_API_KEY:\n        raise Exception(\"Anthropic API key not found\")\n    if model in GEMINI_MODELS and not GEMINI_API_KEY:\n        raise Exception(\"Gemini API key not found\")\n    if model in OPENAI_MODELS and not OPENAI_API_KEY:\n        raise Exception(\"OpenAI API key not found\")\n\n    print(f\"[EVALS] Using agent runner for model: {model.value}\")\n\n    recorder = AgentRunRecorder(\n        generation_id=(\n            f\"gen_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{uuid.uuid4().hex[:8]}\"\n        ),\n        variant_index=0,\n        entry_point=\"eval\",\n        stack=str(stack),\n        input_mode=input_mode,\n        generation_type=\"create\",\n        eval_session=eval_session_id,\n        eval_set=eval_set,\n        input_file=input_file,\n    )\n    runner = Agent(\n        send_message=send_message,","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/abi/screenshot-to-code/blob/d026163f586dfa8c5c10d28c36edd59a9d3b0e88/backend/evals/core.py#L28-L64","documentation":"Exception raised by the eval runner core when model is in OPENAI_MODELS and the module-level OPENAI_API_KEY is empty. It fires before the AgentRunRecorder is created, so no partial run record is left behind.","triggerScenarios":"Starting an eval run with an OpenAI model while OPENAI_API_KEY is unset in the eval-hosting process.","commonSituations":"backend/.env missing the OpenAI key, eval worker started in a different shell/environment, or the key only configured in the browser UI (evals core reads env only).","solutions":["Set OPENAI_API_KEY in the environment of the eval process and restart it.","Note this path does NOT read the in-app Settings key — env/.env is the only source here.","Or select an Anthropic/Gemini model matching an available key."],"exampleFix":"# backend/.env\nOPENAI_API_KEY=sk-...","handlingStrategy":"validation","validationCode":"import os\nif model in OPENAI_MODELS and not os.environ.get(\"OPENAI_API_KEY\"):\n    raise SystemExit(\"OPENAI_API_KEY not set; cannot run evals on OpenAI models\")","typeGuard":null,"tryCatchPattern":"try:\n    await run_eval(...)\nexcept Exception as e:\n    if \"API key not found\" in str(e):\n        abort_run(\"Configure OPENAI_API_KEY and restart the eval worker\")","preventionTips":["Note evals read env only — keys entered in the browser Settings do not satisfy this path.","Add env validation to eval-worker startup so misconfiguration is caught before sessions start."],"tags":["api-key","openai","evals","config"],"backgroundTag":null,"analyzedSha":"d026163f586dfa8c5c10d28c36edd59a9d3b0e88","analyzedAt":"2026-08-14T22:02:06.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}