Skip to main content
skill CX Codex

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

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add jeremylongshore/tons-of-skills-marketplace --skill groq-cost-tuning -a claude-code
Open on GitHub

What 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-code

2Manually: put the files in place

~/.claude/skills/groq-cost-tuning/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/groq-cost-tuning/

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

Similar skills

All skills for AI and ML →

From the same set139

The whole set →
ideogram-cost-tuning ideogram-cost-tuning controls prepaid Ideogram API consumption with admission ceilings, retry limits, and output tracking. Helps teams eliminate wasted spend on failed or duplicate runs. CX Codex +1 1installs coderabbit-cost-tuning The coderabbit-cost-tuning skill reviews CodeRabbit plans, seats, limits, and usage against current billing evidence. Use it to prepare cost scenarios before anyone approves a change. CX Codex +1 1installs firecrawl-cost-tuning firecrawl-cost-tuning traces where Firecrawl credits go and trims the bill through endpoint choice, format discipline, cache policy and spend limits, checked against quality. CX Codex +1 1installs retellai-cost-tuning retellai-cost-tuning optimizes voice agent and telephony expenses on Retell AI. Helps trim phone call budgets while preserving essential human-handoff triggers. CX Codex +1 1installs exa-cost-tuning Skill to control Exa API costs through endpoint selection, result limits, per-key budgets, and response cost tracking. Triggers on "Exa cost tuning", "review Exa cost tuning", or "fix Exa cost tuning". CX Codex +1 1installs setting-up-experiment-tracking setting-up-experiment-tracking configures MLflow or Weights & Biases for machine learning projects, installs packages, and writes code to log parameters, metrics, and artifacts. CX Codex +1 1installs openrouter-streaming-setup openrouter-streaming-setup — a skill for Claude Code, Codex, Cursor and other platforms that implements streaming responses from OpenRouter via Server-Sent Events. CX Codex +1 1installs evernote-core-workflow-a evernote-core-workflow-a — a skill for Claude Code and five other platforms that covers the primary Evernote workflow: note creation, notebook organisation, and tag management. Handles CRUD operations, ENML formatting, and notebook stacks. CX Codex +1 1installs

Project sponsors

Companies that keep this analytics open