INNER CODE UNIT · Python
load_key
calmrocks/ai-engineer-notebooks · aien/__init__.py:17
def load_key():
"""Ensure GROQ_API_KEY is set in the environment.
In Colab, read it from Secrets (key icon, left sidebar). Running locally,
expect it as an environment variable. Raises a clear, actionable error
when it's missing rather than failing later inside the client.
"""
import os
try:
from google.colab import userdata # only importable inside Colab
except ImportError:
# Not in Colab — expect the key in the environment.
if not os.environ.get("GROQ_API_KEY"):
raise RuntimeError(
"GROQ_API_KEY is not set. Run `export GROQ_API_KEY=...` in your "
"shell before launching Jupyter, or set it in os.environ."
)