abi/screenshot-to-code · critical · Exception
OpenAI API key not found
Error message
OpenAI API key not found
What it means
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.
Source
Thrown at backend/evals/core.py:46
eval_session_id: str | None,
input_file: str | None,
) -> str:
async def send_message(
_: str,
__: str | None,
___: int,
____: dict[str, Any] | None = None,
_____: str | None = None,
) -> None:
# Evals do not stream tool/assistant messages to a frontend.
return None
if model in ANTHROPIC_MODELS and not ANTHROPIC_API_KEY:
raise Exception("Anthropic API key not found")
if model in GEMINI_MODELS and not GEMINI_API_KEY:
raise Exception("Gemini API key not found")
if model in OPENAI_MODELS and not OPENAI_API_KEY:
raise Exception("OpenAI API key not found")
print(f"[EVALS] Using agent runner for model: {model.value}")
recorder = AgentRunRecorder(
generation_id=(
f"gen_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{uuid.uuid4().hex[:8]}"
),
variant_index=0,
entry_point="eval",
stack=str(stack),
input_mode=input_mode,
generation_type="create",
eval_session=eval_session_id,
eval_set=eval_set,
input_file=input_file,
)
runner = Agent(
send_message=send_message,View on GitHub (pinned to d026163f58)
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.
Example fix
# backend/.env OPENAI_API_KEY=sk-...
Defensive patterns
Strategy: validation
Validate before calling
import os
if model in OPENAI_MODELS and not os.environ.get("OPENAI_API_KEY"):
raise SystemExit("OPENAI_API_KEY not set; cannot run evals on OpenAI models") Try / catch
try:
await run_eval(...)
except Exception as e:
if "API key not found" in str(e):
abort_run("Configure OPENAI_API_KEY and restart the eval worker") Prevention
- 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.
When it happens
Trigger: Starting an eval run with an OpenAI model while OPENAI_API_KEY is unset in the eval-hosting process.
Common situations: 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).
Related errors
- OpenAI API key is missing.
- Anthropic API key not found
- Gemini API key not found
- Anthropic API key is missing.
- Gemini API key is missing.
AI-assisted analysis of abi/screenshot-to-code@d026163f58 (2026-08-14).
Data as JSON: /api/errors/3da92545b57f5762.
Report an issue: GitHub.