/groq-pack:groq-cost-tuningfrom groq-pack
Optimizes Groq API costs through model routing, token minimization, and usage monitoring. Includes pricing tables and code for routing classification to cheaper models.
Ships in groq-pack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Optimize Groq inference costs through smart model routing, token minimization, and caching. Groq pricing is already extremely competitive, but at high volume the savings from routing classification to 8B vs 70B are 12x per request.
| Model | Input | Output |
|---|---|---|
llama-3.1-8b-instant | ~$0.05 | ~$0.08 |
llama-3.3-70b-versatile | ~$0.59 | ~$0.79 |
llama-3.3-70b-specdec | ~$0.59 | ~$0.99 |
meta-llama/llama-4-scout-17b-16e-instruct | ~$0.11 | ~$0.34 |
whisper-large-v3-turbo | ~$0.04/hr | — |
Check current pricing at groq.com/pricing.
import Groq from "groq-sdk";
const groq = new Groq();
// Route to cheapest model that meets quality requirements
interface ModelConfig {
model: string;
inputCostPer1M: number;
outputCostPer1M: number;
}
const ROUTING: Record<string, ModelConfig> = {
classification: { model: "llama-3.1-8b-instant", inputCostPer1M: 0.05, outputCostPer1M: 0.08 },
extraction: { model: "llama-3.1-8b-instant", inputCostPer1M: 0.05, outputCostPer1M: 0.08 },
summarization: { model: "llama-3.1-8b-instant", inputCostPer1M: 0.05, outputCostPer1M: 0.08 },
reasoning: { model: "llama-3.3-70b-versatile", inputCostPer1M: 0.59, outputCostPer1M: 0.79 },
codeReview: { model: "llama-3.3-70b-versatile", inputCostPer1M: 0.59, outputCostPer1M: 0.79 },
chat: { model: "llama-3.3-70b-versatile", inputCostPer1M: 0.59, outputCostPer1M: 0.79 },
vision: { model: "meta-llama/llama-4-scout-17b-16e-instruct", inputCostPer1M: 0.11, outputCostPer1M: 0.34 },
};
function getModel(useCase: string): string {
return ROUTING[useCase]?.model || "llama-3.1-8b-instant";
}
// Classification on 8B: $0.05/M vs 70B: $0.59/M = 12x savings
// COST SAVINGS: Reduce system prompt tokens
// Groq charges for BOTH input and output tokens
// Verbose system prompt: ~200 tokens ($0.012 per 1000 calls on 70B)
const expensive = "You are a highly skilled AI assistant specializing in text classification. When given a piece of text, carefully analyze the sentiment, considering tone, word choice, connotation...";
// Concise system prompt: ~15 tokens ($0.001 per 1000 calls on 70B)
const cheap = "Classify sentiment: positive/negative/neutral. One word.";
// COST SAVINGS: Limit output tokens
async function cheapClassify(text: string): Promise<string> {
const result = await groq.chat.completions.create({
model: "llama-3.1-8b-instant",
messages: [
{ role: "system", content: "Reply with one word: positive, negative, or neutral." },
{ role: "user", content: text },
],
max_tokens: 3, // One word = 1-2 tokens
temperature: 0, // Deterministic = cacheable
});
return result.choices[0].message.content!.trim();
}
// Batch 10 items in one request instead of 10 separate requests
// Saves on per-request overhead and reduces RPM usage
async function batchClassify(items: string[]): Promise<string[]> {
const batchPrompt = items.map((item, i) => `${i + 1}. ${item}`).join("\n");
const result = await groq.chat.completions.create({
model: "llama-3.1-8b-instant",
messages: [
{
role: "system",
content: "Classify each numbered item as positive/negative/neutral. Reply with numbered results only.",
},
{ role: "user", content: batchPrompt },
],
max_tokens: items.length * 10,
temperature: 0,
});
// Parse numbered results
return result.choices[0].message.content!
.split("\n")
.map((line) => line.replace(/^\d+\.\s*/, "").trim())
.filter(Boolean);
}
// 10 items in 1 API call vs 10 API calls = ~90% reduction in overhead
import { createHash } from "crypto";
const cache = new Map<string, { result: string; ts: number }>();
const CACHE_TTL = 60 * 60_000; // 1 hour
async function cachedCompletion(
messages: any[],
model: string
): Promise<string> {
const key = createHash("md5")
.update(JSON.stringify({ messages, model }))
.digest("hex");
const cached = cache.get(key);
if (cached && Date.now() - cached.ts < CACHE_TTL) {
return cached.result; // Zero cost, zero latency
}
const response = await groq.chat.completions.create({
model,
messages,
temperature: 0, // Required for cache consistency
});
const result = response.choices[0].message.content!;
cache.set(key, { result, ts: Date.now() });
return result;
}
interface UsageRecord {
timestamp: string;
model: string;
promptTokens: number;
completionTokens: number;
estimatedCost: number;
}
const usageLog: UsageRecord[] = [];
function trackUsage(model: string, usage: any): void {
const config = Object.values(ROUTING).find((r) => r.model === model)
|| { inputCostPer1M: 0.10, outputCostPer1M: 0.10 };
usageLog.push({
timestamp: new Date().toISOString(),
model,
promptTokens: usage.prompt_tokens,
completionTokens: usage.completion_tokens,
estimatedCost:
(usage.prompt_tokens / 1_000_000) * config.inputCostPer1M +
(usage.completion_tokens / 1_000_000) * config.outputCostPer1M,
});
}
function dailyCostReport(): { totalCost: string; byModel: Record<string, string> } {
const totalCost = usageLog.reduce((sum, r) => sum + r.estimatedCost, 0);
const byModel: Record<string, number> = {};
for (const r of usageLog) {
byModel[r.model] = (byModel[r.model] || 0) + r.estimatedCost;
}
return {
totalCost: `$${totalCost.toFixed(4)}`,
byModel: Object.fromEntries(
Object.entries(byModel).map(([k, v]) => [k, `$${v.toFixed(4)}`])
),
};
}
In Groq Console > Organization > Billing:
Check your limits at console.groq.com/settings/limits.
Processing 100,000 customer messages:
| Strategy | Model | Est. Cost |
|---|---|---|
| Naive (70B, verbose prompts) | 70b-versatile | ~$60 |
| Smart routing (8B for classification) | 8b-instant | ~$5 |
| + Caching (50% hit rate) | 8b-instant | ~$2.50 |
| + Batching (10 per request) | 8b-instant | ~$2.00 |
| Issue | Cause | Solution |
|---|---|---|
| Costs higher than expected | 70B for simple tasks | Route classification/extraction to 8B |
| Spending cap hit | Budget exhausted | Increase cap or reduce volume |
| Cache not effective | Unique prompts | Normalize prompts before caching |
| Rate limits causing retries | RPM cap hit | Batch requests, spread across time |
For architecture patterns, see groq-reference-architecture.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub flight505/skill-forge --plugin groq-pack24 skills in this plugin
/groq-ci-integrationConfigure Groq CI/CD integration with GitHub Actions, testing, and model validation.
Use when setting up automated testing, configuring CI pipelines,
or integrating Groq tests into your build process.
Trigger with phrases like "groq CI", "groq GitHub Actions",
"groq automated tests", "CI groq".
/groq-common-errorsDiagnose and fix Groq API errors with real error codes and solutions.
Use when encountering Groq errors, debugging failed requests,
or troubleshooting integration issues.
Trigger with phrases like "groq error", "fix groq",
"groq not working", "debug groq", "groq 429".
/groq-core-workflow-aExecute Groq primary workflow: chat completions with tool use and JSON mode.
Use when implementing chat interfaces, function calling, structured output,
or building AI features with Groq's fast inference.
Trigger with phrases like "groq chat completion", "groq tool use",
"groq function calling", "groq JSON mode".
/groq-core-workflow-bExecute Groq secondary workflows: audio transcription (Whisper), vision,
text-to-speech, and batch model evaluation.
Trigger with phrases like "groq whisper", "groq transcription",
"groq audio", "groq vision", "groq TTS", "groq speech".
/groq-data-handlingImplement prompt sanitization, PII redaction, response filtering, and
usage tracking for Groq API integrations.
Trigger with phrases like "groq data", "groq PII",
"groq GDPR", "groq data retention", "groq privacy", "groq compliance".
/groq-debug-bundleCollect Groq debug evidence for support tickets and troubleshooting.
Use when encountering persistent issues, preparing support tickets,
or collecting diagnostic information for Groq problems.
Trigger with phrases like "groq debug", "groq support bundle",
"collect groq logs", "groq diagnostic".
Other plugins' skills for the same job