groq-cost-tuning — Claude Code skill: optimize Groq spending
groq-cost-tuning — a skill for reducing Groq API costs through model routing, token minimization, and usage tracking.
MIT 1 installs ★ 2,935 updated 2026-11-01
npx skills add jeremylongshore/tons-of-skills-marketplace --skill groq-cost-tuning -a claude-codeWhat groq-cost-tuning does
The skill applies six cost levers in order of impact. Routing yields the largest savings: classification and extraction go to llama-3.1-8b-instant (~$0.05 per million input tokens), reasoning and review to llama-3.3-70b-versatile (~$0.59), delivering a 12x difference on simple requests.
Next, it trims verbose prompts, batches multiple items into a single call, caches identical requests at temperature: 0, and logs token counts with estimated cost per call. Set a monthly budget, alerts at 50% and 80%, and auto-pause in the Groq console.
Output is a routing map, usage logs with cost per call, daily reports like { totalCost: "$2.0000", byModel: {...} }, and console spend controls. Requires GROQ_API_KEY, Node.js, and the groq-sdk package.
What it helps with
- pick the right Groq model for each task without overspending
- track API costs broken down by model and day
- reduce tokens per request while keeping quality
- cache identical requests at zero cost
- combine multiple items into one request to save overhead
Example prompts for the agent
- Optimize cost for classifying 300 messages, route to the 8B model, and show daily spend
- Build a batch classifier, cache results on matching prompts, log token counts and cost
- Compare cost to run the same 100 calls on 70B vs 8B, show savings by model
How to install groq-cost-tuning
1Skills CLI (Vercel)
npx skills add jeremylongshore/tons-of-skills-marketplace --skill groq-cost-tuning -a claude-code2Manually: put the files in place
~/.claude/skills/groq-cost-tuning/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/groq-cost-tuning/
1Skills CLI (Vercel)
npx skills add jeremylongshore/tons-of-skills-marketplace --skill groq-cost-tuning -a codex2Manually: put the files in place
.agents/skills/groq-cost-tuning/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add jeremylongshore/tons-of-skills-marketplace --skill groq-cost-tuning -a cursor2Manually: put the files in place
.cursor/skills/groq-cost-tuning/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install jeremylongshore/tons-of-skills-marketplace skills/.curated/groq-cost-tuning2Manually: put the files in place
.github/skills/groq-cost-tuning/SKILL.md1Skills CLI (Vercel)
npx skills add jeremylongshore/tons-of-skills-marketplace --skill groq-cost-tuning -a gemini-cli2Platform CLI
gemini skills install https://github.com/jeremylongshore/tons-of-skills-marketplace --path skills/.curated/groq-cost-tuningManually: put the files in place
.devin/skills/groq-cost-tuning/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add jeremylongshore/tons-of-skills-marketplace --skill groq-cost-tuning -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about groq-cost-tuning
How do I install groq-cost-tuning in Claude Code?
Run npx skills add jeremylongshore/tons-of-skills-marketplace --skill groq-cost-tuning -a claude-code, then open ~/.claude/skills/groq-cost-tuning/SKILL.md and follow the setup steps.
What does groq-cost-tuning do?
The skill cuts Groq costs by routing simple tasks to the cheaper 8B model and complex ones to 70B, caching repeated requests, and logging daily cost by model so you see spending before the bill arrives.
What do I need to run it?
You need a GROQ_API_KEY environment variable from your Groq account, Node.js, and the groq-sdk package; the client reads the key automatically when you call new Groq().
Source text
SKILL.md · MIT
--- name: groq-cost-tuning description: 'Optimize Groq costs through model routing, token management, and usage monitoring. Use when analyzing Groq billing, reducing API costs, or implementing usage monitoring and budget alerts. Trigger with phrases like "groq cost", "groq billing", "reduce groq costs", "groq pricing", "groq expensive", "groq budget". ' allowed-tools: Read, Grep version: 1.11.0 license: MIT author: Jeremy Longshore <[email protected]> tags: - saas - groq - api - monitoring - cost-optimization compatibility: Designed for Claude Code --- # Groq Cost Tuning ## Overview 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. ## Prerequisites - A Groq account with an API key exported as the `GROQ_API_KEY` environment variable — the `groq-sdk` client reads it automatically (`new Groq()`). - Node.js with the `groq-sdk` package installed (`npm install groq-sdk`). - Access to the [Groq Console](https://console.groq.com) to set spending caps and read the usage dashboard. ## Groq Pricing (per million tokens) | 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](https://groq.com/pricing). ## Instructions Apply these six levers in order. Each compounds on the last — routing alone is the biggest win (~12x), and caching plus batching halve the remainder. The lean skeleton below shows the routing core; the full code for every step lives in [references/implementation.md](references/implementation.md). 1. **Smart model routing** — map each use case to the cheapest model that meets its quality bar (classification/extraction/summarization → `llama-3.1-8b-instant`; reasoning/code review/chat → `llama-3.3-70b-versatile`; vision → `llama-4-scout`). 2. **Minimize tokens per request** — trim verbose system prompts and cap `max_tokens` so a one-word answer never bills for a paragraph. 3. **Batch to reduce overhead** — fold many items into one request; 10-in-1 cuts per-request overhead and RPM pressure ~90%. 4. **Cache deterministic requests** — at `temperature: 0`, hash identical prompts into a cache for zero-cost, zero-latency repeat hits. 5. **Usage tracking** — log token counts and estimated cost per call to catch spend regressions before the invoice. 6. **Spending limits in console** — set a monthly cap, alerts at 50%/80%, and auto-pause in Groq Console > Billing. ```typescript import Groq from "groq-sdk"; const groq = new Groq(); // reads GROQ_API_KEY const ROUTING = { classification: "llama-3.1-8b-instant", // ~$0.05/M reasoning: "llama-3.3-70b-versatile", // ~$0.59/M }; const getModel = (useCase: string) => ROUTING[useCase] || "llama-3.1-8b-instant"; // Classification on 8B vs 70B = 12x savings ``` See [references/implementation.md](references/implementation.md) for the complete routing table, token-minimization, batching, caching, usage-tracking, and console-limit code. ## Output Applying the workflow produces: - A **routing map** (`getModel(useCase)`) that resolves every call to the cheapest fit model. - A **usage log** of `UsageRecord` rows (timestamp, model, prompt/completion tokens, estimated cost) accumulated per call. - A **daily cost report** from `dailyCostReport()` returning `{ totalCost, byModel }`, e.g. `{ totalCost: "$2.0000", byModel: { "llama-3.1-8b-instant": "$2.0000" } }`. - **Console spending controls**: a monthly cap, 50%/80% alerts, and auto-pause. ## Examples Batch three items in a single call using the `batchClassify` helper from [references/implementation.md](references/implementation.md): ```typescript const labels = await batchClassify([ "Loved it, five stars", "Broke on day one", "It was fine, nothing special", ]); // -> ["positive", "negative", "neutral"] (1 API call instead of 3) ``` For the full 100,000-message cost walkthrough and a stacked routing + caching + tracking pipeline, see [references/examples.md](references/examples.md). ## Error Handling | 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 | ## Resources - [references/implementation.md](references/implementation.md) — full code for all six cost-tuning levers. - [references/examples.md](references/examples.md) — worked cost walkthroughs and a stacked pipeline. - [Groq Pricing](https://groq.com/pricing) - [Groq Spend Limits](https://console.groq.com/docs/spend-limits) - [Groq Usage Dashboard](https://console.groq.com/settings/usage) - For architecture patterns, see the `groq-reference-architecture` skill.
© Jeremy Longshore · MIT · jeremylongshore/tons-of-skills-marketplace