heygen-com/hyperframes · error · RuntimeError
Neither GOOGLE_API_KEY nor GEMINI_API_KEY is set.
Error message
Neither GOOGLE_API_KEY nor GEMINI_API_KEY is set.
What it means
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.
Source
Thrown at skills/media-use/audio/scripts/lyria-recipe.py:52
p.add_argument("--negative-prompt", default=None, help="Styles to exclude (optional).")
p.add_argument("--bpm", type=int, default=110)
p.add_argument("--brightness", type=float, default=0.8, help="0-1, higher = brighter mood.")
p.add_argument("--density", type=float, default=0.5, help="0-1, higher = fuller mix.")
p.add_argument(
"--scale",
default="MAJOR",
help="MAJOR / MINOR / PENTATONIC / etc. — see google.genai.types.Scale. Pass empty string for none.",
)
return p.parse_args()
async def generate_bgm(args: argparse.Namespace) -> dict:
from google import genai
from google.genai import types
api_key = os.environ.get("GOOGLE_API_KEY") or os.environ.get("GEMINI_API_KEY") or ""
if not api_key:
raise RuntimeError("Neither GOOGLE_API_KEY nor GEMINI_API_KEY is set.")
client = genai.Client(
api_key=api_key,
http_options={"api_version": "v1alpha"},
)
out_path = Path(args.output)
out_path.parent.mkdir(parents=True, exist_ok=True)
target_bytes = int(args.duration * SAMPLE_RATE * CHANNELS * SAMPLE_WIDTH)
cfg: dict = {"bpm": args.bpm, "temperature": 1.0}
if args.density is not None:
cfg["density"] = args.density
if args.brightness is not None:
cfg["brightness"] = args.brightness
if args.scale:
scale_enum = getattr(types.Scale, args.scale, None)View on GitHub (pinned to c2996c8626)
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.
Example fix
# before python lyria-recipe.py --output bgm.wav # RuntimeError: Neither GOOGLE_API_KEY nor GEMINI_API_KEY is set. # after export GOOGLE_API_KEY=$(cat /run/secrets/gemini-key) python lyria-recipe.py --output bgm.wav
Defensive patterns
Strategy: validation
Validate before calling
import os
api_key = os.environ.get('GOOGLE_API_KEY') or os.environ.get('GEMINI_API_KEY')
if not api_key:
raise RuntimeError(
'Set GOOGLE_API_KEY or GEMINI_API_KEY: export GOOGLE_API_KEY=...'
) Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- NO_TOKEN
- CUDA execution provider not available. Use --device cpu or i
- ffmpeg and ffprobe are required. Install: ${getFFmpegInstall
- Audio file too large for headless analysis (${mb}MB > ${MAX_
- This FFmpeg build has neither libx264 nor VideoToolbox H.264
AI-assisted analysis of heygen-com/hyperframes@c2996c8626 (2026-08-12).
Data as JSON: /api/errors/40980ec184daf7fc.
Report an issue: GitHub.