groq-multi-env-setup

0
0
Source

Configure Groq across development, staging, and production environments. Use when setting up multi-environment deployments, configuring per-environment secrets, or implementing environment-specific Groq configurations. Trigger with phrases like "groq environments", "groq staging", "groq dev prod", "groq environment setup", "groq config by env".

Install

mkdir -p .claude/skills/groq-multi-env-setup && curl -L -o skill.zip "https://mcp.directory/api/skills/download/8566" && unzip -o skill.zip -d .claude/skills/groq-multi-env-setup && rm skill.zip

Installs to .claude/skills/groq-multi-env-setup

About this skill

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.

Environment Strategy

EnvironmentAPI Key SourceDefault ModelRetryLogging
Development.env.localllama-3.1-8b-instant1Verbose
StagingCI/CD secretsllama-3.3-70b-versatile3Standard
ProductionSecret managerllama-3.3-70b-versatile5Structured

Instructions

Step 1: Configuration Module

// config/groq.ts
import Groq from "groq-sdk";

interface GroqEnvConfig {
  apiKey: string;
  model: string;
  maxTokens: number;
  temperature: number;
  maxRetries: number;
  timeout: number;
  logRequests: boolean;
}

const configs: Record<string, GroqEnvConfig> = {
  development: {
    apiKey: process.env.GROQ_API_KEY || "",
    model: "llama-3.1-8b-instant",       // Cheapest, fastest for iteration
    maxTokens: 512,
    temperature: 0.7,
    maxRetries: 1,
    timeout: 15_000,
    logRequests: true,                     // Verbose in dev
  },
  staging: {
    apiKey: process.env.GROQ_API_KEY_STAGING || process.env.GROQ_API_KEY || "",
    model: "llama-3.3-70b-versatile",    // Match production model
    maxTokens: 2048,
    temperature: 0.3,
    maxRetries: 3,
    timeout: 30_000,
    logRequests: false,
  },
  production: {
    apiKey: process.env.GROQ_API_KEY_PROD || process.env.GROQ_API_KEY || "",
    model: "llama-3.3-70b-versatile",    // Quality model
    maxTokens: 2048,
    temperature: 0.3,
    maxRetries: 5,                        // More retries in prod
    timeout: 30_000,
    logRequests: false,
  },
};

function getEnv(): string {
  return process.env.NODE_ENV || "development";
}

export function getGroqConfig(): GroqEnvConfig {
  const env = getEnv();
  const config = configs[env] || configs.development;

  if (!config.apiKey) {
    throw new Error(
      `GROQ_API_KEY not set for ${env}. ` +
      (env === "development"
        ? "Copy .env.example to .env.local and add your key from console.groq.com/keys"
        : `Set GROQ_API_KEY_${env.toUpperCase()} in your secret manager`)
    );
  }

  return config;
}

let _client: Groq | null = null;

export function getGroqClient(): Groq {
  if (!_client) {
    const config = getGroqConfig();
    _client = new Groq({
      apiKey: config.apiKey,
      maxRetries: config.maxRetries,
      timeout: config.timeout,
    });
  }
  return _client;
}

Step 2: Environment-Aware Service

// services/groq-service.ts
import { getGroqClient, getGroqConfig } from "../config/groq";

export async function complete(
  messages: any[],
  options?: { model?: string; maxTokens?: number }
): Promise<string> {
  const groq = getGroqClient();
  const config = getGroqConfig();

  const model = options?.model || config.model;
  const maxTokens = options?.maxTokens || config.maxTokens;

  if (config.logRequests) {
    console.log(`[groq:${model}] ${messages.length} messages, max_tokens=${maxTokens}`);
  }

  try {
    const completion = await groq.chat.completions.create({
      model,
      messages,
      max_tokens: maxTokens,
      temperature: config.temperature,
    });

    if (config.logRequests) {
      const u = completion.usage!;
      console.log(`[groq:${model}] ${u.prompt_tokens}+${u.completion_tokens} tokens, ${((u as any).total_time * 1000).toFixed(0)}ms`);
    }

    return completion.choices[0].message.content || "";
  } catch (err: any) {
    if (err.status === 429) {
      const retryAfter = err.headers?.["retry-after"] || "?";
      console.error(`[groq:${model}] Rate limited. Retry after ${retryAfter}s`);
    }
    throw err;
  }
}

Step 3: Secret Management by Platform

set -euo pipefail

# === Development ===
# .env.local (git-ignored)
cat > .env.example << 'EOF'
# Get your API key at https://console.groq.com/keys
GROQ_API_KEY=gsk_your_dev_key_here
EOF

# === Staging (GitHub Actions) ===
gh secret set GROQ_API_KEY_STAGING --body "gsk_staging_key"

# === Production (Cloud Platforms) ===
# AWS Secrets Manager
aws secretsmanager create-secret \
  --name groq/prod/api-key \
  --secret-string "gsk_prod_key"

# GCP Secret Manager
echo -n "gsk_prod_key" | gcloud secrets create groq-api-key-prod --data-file=-

# HashiCorp Vault
vault kv put secret/groq/prod api_key="gsk_prod_key"

Step 4: Docker Compose Multi-Env

# docker-compose.yml
services:
  app-dev:
    build: .
    environment:
      - NODE_ENV=development
      - GROQ_API_KEY=${GROQ_API_KEY}
    profiles: ["dev"]

  app-staging:
    build: .
    environment:
      - NODE_ENV=staging
      - GROQ_API_KEY=${GROQ_API_KEY_STAGING}
    profiles: ["staging"]

  app-prod:
    build: .
    environment:
      - NODE_ENV=production
    secrets:
      - groq_api_key
    profiles: ["prod"]

secrets:
  groq_api_key:
    external: true

Step 5: Verify Environment Config

// scripts/verify-groq-env.ts
import { getGroqConfig, getGroqClient } from "../config/groq";

async function verify() {
  const config = getGroqConfig();
  console.log(`Environment: ${process.env.NODE_ENV || "development"}`);
  console.log(`Model: ${config.model}`);
  console.log(`Max retries: ${config.maxRetries}`);
  console.log(`API key prefix: ${config.apiKey.slice(0, 8)}...`);

  const groq = getGroqClient();
  const start = performance.now();
  const result = await groq.chat.completions.create({
    model: config.model,
    messages: [{ role: "user", content: "Reply: OK" }],
    max_tokens: 5,
    temperature: 0,
  });

  console.log(`Connection: OK (${Math.round(performance.now() - start)}ms)`);
  console.log(`Model response: ${result.choices[0].message.content}`);
}

verify().catch((err) => {
  console.error(`FAILED: ${err.message}`);
  process.exit(1);
});

Step 6: Rate Limit Awareness by Environment

set -euo pipefail
# Check current rate limits for your key
curl -si https://api.groq.com/openai/v1/chat/completions \
  -H "Authorization: Bearer $GROQ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"llama-3.1-8b-instant","messages":[{"role":"user","content":"ping"}],"max_tokens":1}' \
  2>/dev/null | grep -iE "^x-ratelimit"

Error Handling

IssueCauseSolution
GROQ_API_KEY not setMissing env varCheck .env.local (dev) or secret manager (prod)
Wrong model in envConfig mismatchVerify with verify-groq-env.ts script
Rate limited in devFree tier limitsUse llama-3.1-8b-instant with low max_tokens
Staging/prod key in devKey leak riskUse separate Groq organizations per environment

Resources

Next Steps

For deployment configuration, see groq-deploy-integration.

svg-icon-generator

jeremylongshore

Svg Icon Generator - Auto-activating skill for Visual Content. Triggers on: svg icon generator, svg icon generator Part of the Visual Content skill category.

8227

d2-diagram-creator

jeremylongshore

D2 Diagram Creator - Auto-activating skill for Visual Content. Triggers on: d2 diagram creator, d2 diagram creator Part of the Visual Content skill category.

4926

automating-mobile-app-testing

jeremylongshore

This skill enables automated testing of mobile applications on iOS and Android platforms using frameworks like Appium, Detox, XCUITest, and Espresso. It generates end-to-end tests, sets up page object models, and handles platform-specific elements. Use this skill when the user requests mobile app testing, test automation for iOS or Android, or needs assistance with setting up device farms and simulators. The skill is triggered by terms like "mobile testing", "appium", "detox", "xcuitest", "espresso", "android test", "ios test".

14217

performing-penetration-testing

jeremylongshore

This skill enables automated penetration testing of web applications. It uses the penetration-tester plugin to identify vulnerabilities, including OWASP Top 10 threats, and suggests exploitation techniques. Use this skill when the user requests a "penetration test", "pentest", "vulnerability assessment", or asks to "exploit" a web application. It provides comprehensive reporting on identified security flaws.

4615

designing-database-schemas

jeremylongshore

Design and visualize efficient database schemas, normalize data, map relationships, and generate ERD diagrams and SQL statements.

11514

analyzing-logs

jeremylongshore

Analyze application logs to detect performance issues, identify error patterns, and improve stability by extracting key insights.

11410

You might also like

flutter-development

aj-geddes

Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.

1,1421,171

drawio-diagrams-enhanced

jgtolentino

Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.

969933

ui-ux-pro-max

nextlevelbuilder

"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."

683829

godot

bfollington

This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.

691549

nano-banana-pro

garg-aayush

Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.

797540

pdf-to-markdown

aliceisjustplaying

Convert entire PDF documents to clean, structured Markdown for full context loading. Use this skill when the user wants to extract ALL text from a PDF into context (not grep/search), when discussing or analyzing PDF content in full, when the user mentions "load the whole PDF", "bring the PDF into context", "read the entire PDF", or when partial extraction/grepping would miss important context. This is the preferred method for PDF text extraction over page-by-page or grep approaches.

697374

Stay ahead of the MCP ecosystem

Get weekly updates on new skills and servers.