/groq-pack:groq-rate-limitsfrom groq-pack
Implements Groq rate limit handling with exponential backoff, request queuing, and header parsing for 429 responses.
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.
Handle Groq rate limits using the retry-after header, exponential backoff, and request queuing. Groq enforces limits at the organization level with both RPM (requests/minute) and TPM (tokens/minute) constraints -- hitting either one triggers a 429.
Groq rate limits vary by plan and model. Limits are applied simultaneously -- you must stay under both RPM and TPM.
| Constraint | Description |
|---|---|
| RPM | Requests per minute |
| RPD | Requests per day |
| TPM | Tokens per minute |
| TPD | Tokens per day |
Free tier limits are significantly lower than paid tier. Check your current limits at console.groq.com/settings/limits.
When Groq responds (even on success), it includes these headers:
| Header | Description |
|---|---|
x-ratelimit-limit-requests | Max requests in current window |
x-ratelimit-limit-tokens | Max tokens in current window |
x-ratelimit-remaining-requests | Requests remaining before limit |
x-ratelimit-remaining-tokens | Tokens remaining before limit |
x-ratelimit-reset-requests | Time until request limit resets |
x-ratelimit-reset-tokens | Time until token limit resets |
retry-after | Seconds to wait (only on 429 responses) |
import Groq from "groq-sdk";
interface RateLimitInfo {
limitRequests: number;
limitTokens: number;
remainingRequests: number;
remainingTokens: number;
resetRequestsMs: number;
resetTokensMs: number;
}
function parseRateLimitHeaders(headers: Record<string, string>): RateLimitInfo {
return {
limitRequests: parseInt(headers["x-ratelimit-limit-requests"] || "0"),
limitTokens: parseInt(headers["x-ratelimit-limit-tokens"] || "0"),
remainingRequests: parseInt(headers["x-ratelimit-remaining-requests"] || "0"),
remainingTokens: parseInt(headers["x-ratelimit-remaining-tokens"] || "0"),
resetRequestsMs: parseResetTime(headers["x-ratelimit-reset-requests"]),
resetTokensMs: parseResetTime(headers["x-ratelimit-reset-tokens"]),
};
}
function parseResetTime(value?: string): number {
if (!value) return 0;
// Groq returns reset times like "1.2s" or "120ms"
if (value.endsWith("ms")) return parseFloat(value);
if (value.endsWith("s")) return parseFloat(value) * 1000;
return parseFloat(value) * 1000;
}
async function withRateLimitRetry<T>(
operation: () => Promise<T>,
options = { maxRetries: 5, baseDelayMs: 1000, maxDelayMs: 60_000 }
): Promise<T> {
for (let attempt = 0; attempt <= options.maxRetries; attempt++) {
try {
return await operation();
} catch (err) {
if (attempt === options.maxRetries) throw err;
if (err instanceof Groq.APIError && err.status === 429) {
// Prefer retry-after header from Groq
const retryAfterSec = parseInt(err.headers?.["retry-after"] || "0");
let delayMs: number;
if (retryAfterSec > 0) {
delayMs = retryAfterSec * 1000;
} else {
// Exponential backoff with jitter
const exponential = options.baseDelayMs * Math.pow(2, attempt);
const jitter = Math.random() * 500;
delayMs = Math.min(exponential + jitter, options.maxDelayMs);
}
console.warn(`Rate limited (attempt ${attempt + 1}/${options.maxRetries}). Waiting ${(delayMs / 1000).toFixed(1)}s...`);
await new Promise((r) => setTimeout(r, delayMs));
continue;
}
// Non-rate-limit errors: only retry 5xx
if (err instanceof Groq.APIError && err.status >= 500) {
const delayMs = options.baseDelayMs * Math.pow(2, attempt);
await new Promise((r) => setTimeout(r, delayMs));
continue;
}
throw err; // 4xx (except 429) are not retryable
}
}
throw new Error("Unreachable");
}
import PQueue from "p-queue";
// Queue that respects Groq RPM limits
function createGroqQueue(requestsPerMinute: number) {
return new PQueue({
intervalCap: requestsPerMinute,
interval: 60_000, // 1 minute window
concurrency: 5, // Max parallel requests
});
}
const queue = createGroqQueue(30); // Free tier: 30 RPM
async function queuedCompletion(messages: any[], model: string) {
return queue.add(() =>
withRateLimitRetry(() =>
groq.chat.completions.create({ model, messages })
)
);
}
class RateLimitMonitor {
private remaining = { requests: Infinity, tokens: Infinity };
private resets = { requests: 0, tokens: 0 };
update(headers: Record<string, string>): void {
const info = parseRateLimitHeaders(headers);
this.remaining.requests = info.remainingRequests;
this.remaining.tokens = info.remainingTokens;
this.resets.requests = Date.now() + info.resetRequestsMs;
this.resets.tokens = Date.now() + info.resetTokensMs;
}
shouldThrottle(): boolean {
return this.remaining.requests < 3 || this.remaining.tokens < 500;
}
async waitIfNeeded(): Promise<void> {
if (!this.shouldThrottle()) return;
const waitMs = Math.max(
this.resets.requests - Date.now(),
this.resets.tokens - Date.now(),
0
);
if (waitMs > 0) {
console.log(`Throttling: waiting ${(waitMs / 1000).toFixed(1)}s for rate limit reset`);
await new Promise((r) => setTimeout(r, waitMs));
}
}
getStatus(): string {
return `Requests: ${this.remaining.requests} remaining | Tokens: ${this.remaining.tokens} remaining`;
}
}
// Different models have different limits -- route accordingly
async function smartModelSelect(
messages: any[],
preferredModel: string,
monitor: RateLimitMonitor
): Promise<string> {
// If rate limited on preferred model, try a different one
if (monitor.shouldThrottle()) {
const fallbacks: Record<string, string> = {
"llama-3.3-70b-versatile": "llama-3.1-8b-instant",
"llama-3.1-8b-instant": "llama-3.3-70b-versatile", // Different limit pool
};
const fallback = fallbacks[preferredModel];
if (fallback) {
console.log(`Switching from ${preferredModel} to ${fallback} (rate limit)`);
return fallback;
}
}
return preferredModel;
}
| Scenario | Symptom | Solution |
|---|---|---|
| Burst of requests | Many 429s in quick succession | Use queue with p-queue interval limiting |
| Large prompts burn TPM | 429 on tokens, not requests | Reduce max_tokens, compress prompts |
| Free tier too restrictive | Constant 429s | Upgrade to Developer plan at console.groq.com |
| Multiple services sharing key | Cascading 429s | Use separate API keys per service |
For security configuration, see groq-security-basics.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
24 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-cost-tuningOptimize 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".
/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".
npx claudepluginhub flight505/skill-forge --plugin groq-packOther plugins' skills for the same job