"""Groq client stub - OpenAI-compatible /chat/completions.""" import os import requests BASE = os.getenv("GROQ_API_BASE", "https://api.groq.com/openai/v1") KEY = os.getenv("GROQ_API_KEY") def chat(messages, model="llama-3.1-8b-instant", stream=False, **kwargs): if not KEY: raise RuntimeError("GROQ_API_KEY not set") body = {"model": model, "messages": messages, "stream": stream, **kwargs} return requests.post( f"{BASE}/chat/completions", headers={"Authorization": f"Bearer {KEY}"}, json=body, timeout=60, stream=stream, ) def list_models(): if not KEY: raise RuntimeError("GROQ_API_KEY not set") return requests.get(f"{BASE}/models", headers={"Authorization": f"Bearer {KEY}"}, timeout=30).json()