// Groq as a remote backend -- OpenAI-compatible chat completions on // LPU hardware, notable mainly for raw speed (observed far faster // token generation than either local Ollama or Gemini's free tier) and // a generous free quota (30 req/min, 1000/day at time of writing). import { createOpenAiCompatBackend } from "./openaiCompatBackend.js"; import type { ChatBackend } from "./chatBackend.js"; function apiKey(): string { const key = process.env.GROQ_API_KEY; if (!key) throw new Error("Groq backend needs an API key: set GROQ_API_KEY in your environment or app/.env. Get a free key at https://console.groq.com/keys -- never paste the key itself into chat."); return key; } export function createGroqBackend(model: string): ChatBackend { // Resolved eagerly, not passed as a lazy callback -- callers (zz // work/--assist) call this before resolveCliBackendMode/ // enterFullscreen, specifically so a missing key fails fast as a // plain CLI error instead of surfacing deep inside a TUI session on // the first draft attempt (confirmed live: that's exactly what used // to happen). const key = apiKey(); return createOpenAiCompatBackend({ name: `groq:${model}`, url: "https://api.groq.com/openai/v1/chat/completions", model, apiKey: () => key, }); }