Groq Multi-Environment Setup
Overview
Configure Groq API access across development, staging, and production with the right model, rate limit strategy, and secret management per environment. Key insight: use llama-3.1-8b-instant in development (cheapest, fastest), match production model in staging, and harden production with retries and fallbacks.
Prerequisites
- A Groq account with API keys from console.groq.com/keys — ideally a separate key (or organization) per environment.
- Node project with the
groq-sdk package installed (npm install groq-sdk).
NODE_ENV set per environment (development / staging / production).
- A secret store for staging/production keys: GitHub Actions secrets, AWS Secrets Manager, GCP Secret Manager, or HashiCorp Vault.
Environment Strategy
| Environment |
API Key Source |
Default Model |
Retry |
Logging |
| Development |
.env.local |
llama-3.1-8b-instant |
1 |
Verbose |
| Staging |
CI/CD secrets |
llama-3.3-70b-versatile |
3 |
Standard |
| Production |
Secret manager |
llama-3.3-70b-versatile |
5 |
Structured |
Instructions
The full, copy-paste implementation lives in the reference files — this section
is the map. Read the implementation walkthrough
for the code module, service wrapper, and verify script, and
secrets & deployment for per-platform
key management, Docker Compose profiles, and rate-limit inspection.
Build the config module (config/groq.ts). One configs record keyed by
environment resolves model, token budget, retries, timeout, and logging, then
validates that a key is present with an environment-specific error message.
The essential skeleton:
const configs: Record<string, GroqEnvConfig> = {
development: { model: "llama-3.1-8b-instant", maxRetries: 1, logRequests: true, /* ... */ },
staging: { model: "llama-3.3-70b-versatile", maxRetries: 3, logRequests: false, /* ... */ },
production: { model: "llama-3.3-70b-versatile", maxRetries: 5, logRequests: false, /* ... */ },
};
export function getGroqConfig(): GroqEnvConfig {
return configs[process.env.NODE_ENV || "development"] || configs.development;
}
See implementation.md § Step 1 for the full module including key validation and the memoized getGroqClient().
Wire an environment-aware service (services/groq-service.ts) that reads
the resolved config, logs only when logRequests is on, and surfaces the
retry-after header on 429. Full code in
implementation.md § Step 2.
Source secrets per platform. Dev reads a git-ignored .env.local; staging
uses CI/CD secrets; production pulls from a secret manager. Commands for
GitHub Actions, AWS, GCP, and Vault are in
secrets-and-deployment.md § Step 3.
Deploy with Docker Compose profiles so each environment injects its own
key (env var for dev/staging, external Docker secret for prod). See
secrets-and-deployment.md § Step 4.
Verify each environment with scripts/verify-groq-env.ts, which prints the
resolved model/retries and does a live round-trip. Full script in
implementation.md § Step 5.
Inspect rate limits per key via the x-ratelimit-* response headers — see
secrets-and-deployment.md § Step 6.
Output
After setup, each environment resolves its own Groq configuration and the verify
script confirms a live connection. Expected output from verify-groq-env.ts in
production:
Environment: production
Model: llama-3.3-70b-versatile
Max retries: 5
API key prefix: gsk_AbCd...
Connection: OK (312ms)
Model response: OK
You end with: a config/groq.ts that selects model/retries/logging by NODE_ENV, a service wrapper that logs verbosely only in dev, per-environment keys sourced from the right secret store, and Docker Compose profiles that never leak a production key into the process environment.
Error Handling
| Issue |
Cause |
Solution |
GROQ_API_KEY not set |
Missing env var |
Check .env.local (dev) or secret manager (prod) |
| Wrong model in env |
Config mismatch |
Verify with verify-groq-env.ts script |
| Rate limited in dev |
Free tier limits |
Use llama-3.1-8b-instant with low max_tokens |
| Staging/prod key in dev |
Key leak risk |
Use separate Groq organizations per environment |
Examples
Resolve the config for the current environment:
import { getGroqConfig } from "./config/groq";
const config = getGroqConfig(); // picks dev/staging/prod by NODE_ENV
console.log(config.model); // "llama-3.1-8b-instant" in dev
Complete a chat with the environment default model:
import { complete } from "./services/groq-service";
const answer = await complete([{ role: "user", content: "Summarize in one line." }]);
Verify production before a deploy:
NODE_ENV=production GROQ_API_KEY_PROD=gsk_... npx tsx scripts/verify-groq-env.ts
Full, runnable versions of every snippet are in
implementation.md and
secrets-and-deployment.md.
Resources
Next Steps
For deployment configuration, see the groq-deploy-integration skill, which builds on this environment strategy to wire CI/CD deploy pipelines and health checks.
Source: jeremylongshore/claude-code-plugins-plus-skills → plugins/saas-packs/groq-pack/skills/groq-multi-env-setup/SKILL.md
1---2name: groq-multi-env-setup3description: | Use when you need Groq to behave differently across dev, staging, and production — cheap fast models and verbose logs in dev, the production model and hardened retries everywhere else, with per-environment API keys. Configure environment-specific model selection, rate limits, and secrets. Trigger with phrases like "groq environments", "groq staging", "groq dev prod", "groq environment setup", "groq multi-env", "groq config by env".4---56# Groq Multi-Environment Setup78## Overview910Configure Groq API access across development, staging, and production with the right model, rate limit strategy, and secret management per environment. Key insight: use `llama-3.1-8b-instant` in development (cheapest, fastest), match production model in staging, and harden production with retries and fallbacks.1112## Prerequisites1314- A Groq account with API keys from [console.groq.com/keys](https://console.groq.com/keys) — ideally a separate key (or organization) per environment.15- Node project with the `groq-sdk` package installed (`npm install groq-sdk`).16- `NODE_ENV` set per environment (`development` / `staging` / `production`).17- A secret store for staging/production keys: GitHub Actions secrets, AWS Secrets Manager, GCP Secret Manager, or HashiCorp Vault.1819## Environment Strategy2021| Environment | API Key Source | Default Model | Retry | Logging |22|-------------|---------------|---------------|-------|---------|23| Development | `.env.local` | `llama-3.1-8b-instant` | 1 | Verbose |24| Staging | CI/CD secrets | `llama-3.3-70b-versatile` | 3 | Standard |25| Production | Secret manager | `llama-3.3-70b-versatile` | 5 | Structured |2627## Instructions2829The full, copy-paste implementation lives in the reference files — this section30is the map. Read [the implementation walkthrough](references/implementation.md)31for the code module, service wrapper, and verify script, and32[secrets & deployment](references/secrets-and-deployment.md) for per-platform33key management, Docker Compose profiles, and rate-limit inspection.34351. **Build the config module** (`config/groq.ts`). One `configs` record keyed by36 environment resolves model, token budget, retries, timeout, and logging, then37 validates that a key is present with an environment-specific error message.38 The essential skeleton:3940 ```typescript41 const configs: Record<string, GroqEnvConfig> = {42 development: { model: "llama-3.1-8b-instant", maxRetries: 1, logRequests: true, /* ... */ },43 staging: { model: "llama-3.3-70b-versatile", maxRetries: 3, logRequests: false, /* ... */ },44 production: { model: "llama-3.3-70b-versatile", maxRetries: 5, logRequests: false, /* ... */ },45 };46 export function getGroqConfig(): GroqEnvConfig {47 return configs[process.env.NODE_ENV || "development"] || configs.development;48 }49 ```5051 See [implementation.md § Step 1](references/implementation.md) for the full module including key validation and the memoized `getGroqClient()`.52532. **Wire an environment-aware service** (`services/groq-service.ts`) that reads54 the resolved config, logs only when `logRequests` is on, and surfaces the55 `retry-after` header on `429`. Full code in56 [implementation.md § Step 2](references/implementation.md).57583. **Source secrets per platform.** Dev reads a git-ignored `.env.local`; staging59 uses CI/CD secrets; production pulls from a secret manager. Commands for60 GitHub Actions, AWS, GCP, and Vault are in61 [secrets-and-deployment.md § Step 3](references/secrets-and-deployment.md).62634. **Deploy with Docker Compose profiles** so each environment injects its own64 key (env var for dev/staging, external Docker secret for prod). See65 [secrets-and-deployment.md § Step 4](references/secrets-and-deployment.md).66675. **Verify each environment** with `scripts/verify-groq-env.ts`, which prints the68 resolved model/retries and does a live round-trip. Full script in69 [implementation.md § Step 5](references/implementation.md).70716. **Inspect rate limits** per key via the `x-ratelimit-*` response headers — see72 [secrets-and-deployment.md § Step 6](references/secrets-and-deployment.md).7374## Output7576After setup, each environment resolves its own Groq configuration and the verify77script confirms a live connection. Expected output from `verify-groq-env.ts` in78production:7980```text81Environment: production82Model: llama-3.3-70b-versatile83Max retries: 584API key prefix: gsk_AbCd...85Connection: OK (312ms)86Model response: OK87```8889You end with: a `config/groq.ts` that selects model/retries/logging by `NODE_ENV`, a service wrapper that logs verbosely only in dev, per-environment keys sourced from the right secret store, and Docker Compose profiles that never leak a production key into the process environment.9091## Error Handling9293| Issue | Cause | Solution |94|-------|-------|----------|95| `GROQ_API_KEY not set` | Missing env var | Check .env.local (dev) or secret manager (prod) |96| Wrong model in env | Config mismatch | Verify with `verify-groq-env.ts` script |97| Rate limited in dev | Free tier limits | Use `llama-3.1-8b-instant` with low max_tokens |98| Staging/prod key in dev | Key leak risk | Use separate Groq organizations per environment |99100## Examples101102**Resolve the config for the current environment:**103104```typescript105import { getGroqConfig } from "./config/groq";106107const config = getGroqConfig(); // picks dev/staging/prod by NODE_ENV108console.log(config.model); // "llama-3.1-8b-instant" in dev109```110111**Complete a chat with the environment default model:**112113```typescript114import { complete } from "./services/groq-service";115116const answer = await complete([{ role: "user", content: "Summarize in one line." }]);117```118119**Verify production before a deploy:**120121```bash122NODE_ENV=production GROQ_API_KEY_PROD=gsk_... npx tsx scripts/verify-groq-env.ts123```124125Full, runnable versions of every snippet are in126[implementation.md](references/implementation.md) and127[secrets-and-deployment.md](references/secrets-and-deployment.md).128129## Resources130131- [Groq Console](https://console.groq.com)132- [Groq API Keys](https://console.groq.com/keys)133- [Groq Rate Limits](https://console.groq.com/docs/rate-limits)134- [Groq Spend Limits](https://console.groq.com/docs/spend-limits)135- [Implementation walkthrough](references/implementation.md) — config module, service, verify script136- [Secrets & deployment](references/secrets-and-deployment.md) — secret managers, Docker Compose, rate limits137138## Next Steps139140For deployment configuration, see the `groq-deploy-integration` skill, which builds on this environment strategy to wire CI/CD deploy pipelines and health checks.141142---143144**Source:** [`jeremylongshore/claude-code-plugins-plus-skills`](https://github.com/jeremylongshore/claude-code-plugins-plus-skills) → `plugins/saas-packs/groq-pack/skills/groq-multi-env-setup/SKILL.md`