{"record":{"id":"8122dac5c6091157","repo":"nexu-io/open-design","slug":"openai-api-key-is-not-set","errorCode":null,"errorMessage":"OPENAI_API_KEY is not set","messagePattern":"OPENAI_API_KEY is not set","errorType":"exception","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"skills/hatch-pet/scripts/generate_pet_images.py","lineNumber":238,"sourceCode":"        if not path.is_file():\n            raise SystemExit(f\"input image for job {job.get('id')} not found: {path}\")\n        paths.append(path)\n    return paths\n\n\ndef main() -> None:\n    parser = argparse.ArgumentParser(description=__doc__)\n    parser.add_argument(\"--run-dir\", required=True)\n    parser.add_argument(\"--model\", default=\"gpt-image-2\")\n    parser.add_argument(\"--size\", default=\"1024x1024\")\n    parser.add_argument(\"--states\", default=\"all\")\n    parser.add_argument(\"--job-id\", action=\"append\", default=[])\n    parser.add_argument(\"--skip-base\", action=\"store_true\")\n    args = parser.parse_args()\n\n    api_key = os.environ.get(\"OPENAI_API_KEY\")\n    if not api_key:\n        raise SystemExit(\"OPENAI_API_KEY is not set\")\n\n    run_dir = Path(args.run_dir).expanduser().resolve()\n    manifest_path = run_dir / \"imagegen-jobs.json\"\n    manifest = load_manifest(run_dir)\n    jobs = select_jobs(\n        manifest,\n        states=parse_states(args.states),\n        skip_base=args.skip_base,\n        job_ids=args.job_id,\n    )\n    raw_dir = run_dir / \"raw\"\n\n    completed = []\n    for job in jobs:\n        job_id = str(job.get(\"id\"))\n        prompt_raw = job.get(\"prompt_file\")\n        output_raw = job.get(\"output_path\")\n        if not isinstance(prompt_raw, str) or not isinstance(output_raw, str):","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/skills/hatch-pet/scripts/generate_pet_images.py#L220-L256","documentation":"Raised by main() before any API call: the OPENAI_API_KEY environment variable is unset or empty. The script reads the key once from os.environ and refuses to proceed without it because every image request needs a Bearer token.","triggerScenarios":"Launching generate_pet_images.py in a shell that did not export OPENAI_API_KEY, exported it as an empty string, or in a container/CI job that did not receive the secret.","commonSituations":"Forgot to source the .env file; ran the script in a new terminal without exporting the key; CI secret name typo; running as a different user that lacks the env var.","solutions":["Export the key in the same shell: export OPENAI_API_KEY=sk-... then rerun.","For repeated runs, put the export in your shell rc or a sourced .env file (do not commit it).","In CI, set the OPENAI_API_KEY secret on the job environment.","Verify with: echo \"${OPENAI_API_KEY:+set}\" prints set."],"exampleFix":"// before\npython skills/hatch-pet/scripts/generate_pet_images.py --run-dir ./out\n# SystemExit: OPENAI_API_KEY is not set\n\n// after\nexport OPENAI_API_KEY=\"$(cat ~/.openai_key)\"\npython skills/hatch-pet/scripts/generate_pet_images.py --run-dir ./out","handlingStrategy":"validation","validationCode":"import os\n\napi_key = os.environ.get(\"OPENAI_API_KEY\")\nif not api_key:\n    raise SystemExit(\"OPENAI_API_KEY is not set; export it or set it in the CI secret\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Export OPENAI_API_KEY in the same shell session before running the script.","Store the key in a sourced .env file or your shell rc; never commit it.","In CI, expose the key as a job secret named OPENAI_API_KEY."],"tags":["environment","secrets","openai-api","system-exit"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}