abi/screenshot-to-code · error · SystemExit

Missing GEMINI_API_KEY

Error message

Missing GEMINI_API_KEY

What it means

SystemExit raised when GEMINI_API_KEY is absent from the environment after load_dotenv(Path('.env')). The benchmark calls Gemini directly (run_benchmark(api_key=...)), so unlike the agent factory there is no alternative provider; the key is mandatory before any work starts.

Source

Thrown at backend/evals/asset_extraction_benchmark.py:853

        "--iou-threshold",
        type=float,
        default=DEFAULT_IOU_THRESHOLD,
    )
    return parser.parse_args()


async def main() -> None:
    load_dotenv(Path(".env"))
    args = parse_args()
    if not args.live:
        raise SystemExit(
            "Live API calls are disabled by default. Re-run with --live to opt in."
        )
    if not 0 <= args.iou_threshold <= 1:
        raise SystemExit("--iou-threshold must be between 0 and 1")
    api_key = os.environ.get("GEMINI_API_KEY")
    if not api_key:
        raise SystemExit("Missing GEMINI_API_KEY")
    output_dir = args.output_dir or (
        DEFAULT_OUTPUT_ROOT / time.strftime("%Y%m%d_%H%M%S")
    )
    await run_benchmark(
        api_key=api_key,
        output_dir=output_dir,
        iou_threshold=args.iou_threshold,
    )


if __name__ == "__main__":
    asyncio.run(main())

View on GitHub (pinned to d026163f58)

Solutions

  1. Run the script from the directory containing .env (typically backend/), or export GEMINI_API_KEY in the shell.
  2. Add GEMINI_API_KEY to backend/.env if missing.

Example fix

# before (run from repo root)
python evals/asset_extraction_benchmark.py --live

# after
export GEMINI_API_KEY=AIza...
python evals/asset_extraction_benchmark.py --live
Defensive patterns

Strategy: validation

Validate before calling

api_key = os.environ.get("GEMINI_API_KEY")
if not api_key:
    sys.exit("Missing GEMINI_API_KEY — export it or add to backend/.env")

Prevention

When it happens

Trigger: Running the benchmark with --live but without GEMINI_API_KEY exported or present in backend/.env in the current working directory (load_dotenv uses the relative path '.env').

Common situations: Running the script from a directory other than backend/ so the relative .env is not found, or only having OpenAI/Anthropic keys configured.

Related errors


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