"""Configuration and Groq client initialization. - Loads environment variables via python-dotenv. - Exposes a single `get_groq_client()` helper. Never hardcode secrets. Put `GROQ_API_KEY` in `.env`. """ from __future__ import annotations import os from functools import lru_cache from dotenv import load_dotenv from groq import Groq @lru_cache(maxsize=1) def get_groq_client() -> Groq: """Create and cache a Groq client. Raises: RuntimeError: if GROQ_API_KEY is missing. """ # Load .env (if present) once per process. load_dotenv() api_key = os.getenv("GROQ_API_KEY") if not api_key: raise RuntimeError( "Missing GROQ_API_KEY. Create a .env file (see .env.example) and set GROQ_API_KEY." ) return Groq(api_key=api_key)