{"record":{"id":"40980ec184daf7fc","repo":"heygen-com/hyperframes","slug":"neither-google-api-key-nor-gemini-api-key-is-set","errorCode":null,"errorMessage":"Neither GOOGLE_API_KEY nor GEMINI_API_KEY is set.","messagePattern":"Neither GOOGLE_API_KEY nor GEMINI_API_KEY is set\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"skills/media-use/audio/scripts/lyria-recipe.py","lineNumber":52,"sourceCode":"    p.add_argument(\"--negative-prompt\", default=None, help=\"Styles to exclude (optional).\")\n    p.add_argument(\"--bpm\", type=int, default=110)\n    p.add_argument(\"--brightness\", type=float, default=0.8, help=\"0-1, higher = brighter mood.\")\n    p.add_argument(\"--density\", type=float, default=0.5, help=\"0-1, higher = fuller mix.\")\n    p.add_argument(\n        \"--scale\",\n        default=\"MAJOR\",\n        help=\"MAJOR / MINOR / PENTATONIC / etc. — see google.genai.types.Scale. Pass empty string for none.\",\n    )\n    return p.parse_args()\n\n\nasync def generate_bgm(args: argparse.Namespace) -> dict:\n    from google import genai\n    from google.genai import types\n\n    api_key = os.environ.get(\"GOOGLE_API_KEY\") or os.environ.get(\"GEMINI_API_KEY\") or \"\"\n    if not api_key:\n        raise RuntimeError(\"Neither GOOGLE_API_KEY nor GEMINI_API_KEY is set.\")\n\n    client = genai.Client(\n        api_key=api_key,\n        http_options={\"api_version\": \"v1alpha\"},\n    )\n\n    out_path = Path(args.output)\n    out_path.parent.mkdir(parents=True, exist_ok=True)\n\n    target_bytes = int(args.duration * SAMPLE_RATE * CHANNELS * SAMPLE_WIDTH)\n\n    cfg: dict = {\"bpm\": args.bpm, \"temperature\": 1.0}\n    if args.density is not None:\n        cfg[\"density\"] = args.density\n    if args.brightness is not None:\n        cfg[\"brightness\"] = args.brightness\n    if args.scale:\n        scale_enum = getattr(types.Scale, args.scale, None)","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/heygen-com/hyperframes/blob/c2996c8626135db5253519359d8a063d3bafad8d/skills/media-use/audio/scripts/lyria-recipe.py#L34-L70","documentation":"Thrown by generate_bgm() in the Lyria background music recipe script when neither the GOOGLE_API_KEY nor GEMINI_API_KEY environment variable is set. The script uses the Google GenAI client to call Lyria music generation, which requires an API key for authentication. Without it, the client cannot be constructed.","triggerScenarios":"The script is run (python lyria-recipe.py ...) without either environment variable exported. The code reads os.environ.get('GOOGLE_API_KEY') or os.environ.get('GEMINI_API_KEY') and if both return empty/falsy, raises RuntimeError before constructing the genai.Client.","commonSituations":"Developer forgot to export the key in their shell. The key is in a .env file that wasn't loaded (script doesn't use python-dotenv). CI runner doesn't have the secret injected. The key was renamed from GEMINI_API_KEY to GOOGLE_API_KEY and only the old name is set.","solutions":["Export the key: export GOOGLE_API_KEY=your-key-here (or GEMINI_API_KEY).","Add the key to your shell profile (~/.bashrc / ~/.zshrc) for persistence.","In CI, add the secret as an environment variable in the pipeline config.","If using a .env file, load it before running: set -a; source .env; set +a or use python-dotenv."],"exampleFix":"# before\npython lyria-recipe.py --output bgm.wav\n# RuntimeError: Neither GOOGLE_API_KEY nor GEMINI_API_KEY is set.\n\n# after\nexport GOOGLE_API_KEY=$(cat /run/secrets/gemini-key)\npython lyria-recipe.py --output bgm.wav","handlingStrategy":"validation","validationCode":"import os\n\napi_key = os.environ.get('GOOGLE_API_KEY') or os.environ.get('GEMINI_API_KEY')\nif not api_key:\n    raise RuntimeError(\n        'Set GOOGLE_API_KEY or GEMINI_API_KEY: export GOOGLE_API_KEY=...'\n    )","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Export the key in your shell profile or CI secrets.","Use python-dotenv to load .env files automatically.","Check for the key at script entry and print a helpful message before the genai import."],"tags":["api-key","environment","gemini","lyria","audio","auth","python"],"backgroundTag":null,"analyzedSha":"c2996c8626135db5253519359d8a063d3bafad8d","analyzedAt":"2026-08-12T22:18:56.877Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}