Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Implement Langfuse rate limiting, batching, and backoff patterns. Use when handling rate limit errors, optimizing trace ingestion, or managing high-volume LLM observability workloads. Trigger with phrases like "langfuse rate limit", "langfuse throttling", "langfuse 429", "langfuse batching", "langfuse high volume".
.claude/skills/jeremylongshore-langfuse-rate-limits/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-06 | ✗→✓ | ▲ Improved | -11% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 37% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 38% | 0% |
| case-09 | ✗→✓ | ▲ Improved | 63% | 0% |
| case-11 | ✗→✓ | ▲ Improved | 11% | 0% |
Handle Langfuse API rate limits with optimized SDK batching, exponential backoff with jitter, concurrent request limiting, and configurable sampling for ultra-high-volume workloads.
The Langfuse SDK batches events internally before sending. Tuning batch settings is the first defense against rate limits.
typescript// v3 Legacy: Direct configuration import { Langfuse } from "langfuse"; const langfuse = new Langfuse({ flushAt: 50, // Events per batch (default: 15, max ~200) flushInterval: 10000, // Milliseconds between flushes (default: 10000) requestTimeout: 30000, // Timeout per batch request }); // v4+: Configure via OTel span processor import { LangfuseSpanProcessor } from "@langfuse/otel"; import { NodeSDK } from "@opentelemetry/sdk-node"; const processor = new LangfuseSpanProcessor({ exportIntervalMillis: 10000, // Flush interval maxExportBatchSize: 50, // Events per batch }); const sdk = new NodeSDK({ spanProcessors: [processor] }); sdk.start();
For custom API calls (scores, datasets, prompts) that hit rate limits:
typescriptasync function withRetry<T>( fn: () => Promise<T>, options: { maxRetries?: number; baseDelayMs?: number; maxDelayMs?: number } = {} ): Promise<T> { const { maxRetries = 5, baseDelayMs = 1000, maxDelayMs = 30000 } = options; for (let attempt = 0; attempt <= maxRetries; attempt++) { try { return await fn(); } catch (error: any) { const status = error?.status || error?.response?.status; // Only retry on rate limits (429) and server errors (5xx) if (attempt === maxRetries || (status && status < 429)) { throw error; } // Honor Retry-After header if present const retryAfter = error?.response?.headers?.["retry-after"]; let delay: number; if (retryAfter) { delay = parseInt(retryAfter, 10) * 1000; } else { // Exponential backoff with jitter delay = Math.min(baseDelayMs * Math.pow(2, attempt), maxDelayMs); delay += Math.random() * 500; // Jitter } console.warn(`Rate limited. Retry ${attempt + 1}/${maxRetries} in ${Math.round(delay)}ms`); await new Promise((r) => setTimeout(r, delay)); } } throw new Error("Unreachable"); } // Usage with Langfuse client operations const langfuse = new LangfuseClient(); await withRetry(() => langfuse.score.create({ traceId: "trace-123", name: "quality", value: 0.95, dataType: "NUMERIC", }) );
Use p-queue to cap concurrent Langfuse API calls:
typescriptimport PQueue from "p-queue"; import { LangfuseClient } from "@langfuse/client"; const langfuse = new LangfuseClient(); // Max 10 concurrent API calls, 50 per second const queue = new PQueue({ concurrency: 10, interval: 1000, intervalCap: 50, }); // Queue score submissions async function queueScore(params: { traceId: string; name: string; value: number; }) { return queue.add(() => langfuse.score.create({ ...params, dataType: "NUMERIC", }) ); } // Queue dataset item creation async function queueDatasetItem(datasetName: string, item: any) { return queue.add(() => langfuse.api.datasetItems.create({ datasetName, input: item.input, expectedOutput: item.expectedOutput, }) ); } // Monitor queue health setInterval(() => { console.log(`Queue: ${queue.pending} pending, ${queue.size} queued`); }, 10000);
When tracing volume exceeds rate limits, sample traces instead of dropping them:
typescriptimport { observe, updateActiveObservation, startActiveObservation } from "@langfuse/tracing"; class TraceSampler { private rate: number; private windowCounts: number[] = []; private windowMs = 60000; // 1 minute window private maxPerWindow: number; constructor(sampleRate: number, maxPerMinute: number) { this.rate = sampleRate; this.maxPerWindow = maxPerMinute; } shouldSample(tags?: string[]): boolean { // Always sample errors if (tags?.includes("error") || tags?.includes("critical")) { return true; } // Check window limit const now = Date.now(); this.windowCounts = this.windowCounts.filter((t) => t > now - this.windowMs); if (this.windowCounts.length >= this.maxPerWindow) { return false; } // Probabilistic sampling if (Math.random() > this.rate) { return false; } this.windowCounts.push(now); return true; } } // 10% sampling, max 1000 traces/minute const sampler = new TraceSampler(0.1, 1000); async function sampledOperation(name: string, fn: () => Promise<any>) { if (!sampler.shouldSample()) { return fn(); // Run without tracing } return startActiveObservation(name, async () => { updateActiveObservation({ metadata: { sampled: true } }); return fn(); }); }
| Tier | Traces/min | Batch Size | Strategy | |------|------------|------------|----------| | Hobby | ~500 | 15 | Default settings | | Pro | ~5,000 | 50 | Increase flushAt | | Team | ~10,000 | 100 | + Queue-based limiting | | Enterprise | Custom | Custom | + Sampling |
| Error | Response | Action | |-------|----------|--------| | 429 Too Many Requests | Retry-After: N | Backoff for N seconds | | 503 Service Unavailable | Server overloaded | Backoff 30s+ | | Flush timeout | Large batch | Reduce flushAt, increase requestTimeout | | Memory growth | Queue backup | Add maxSize to PQueue |
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→fail | 34,794 | 29,564 | -15% | 1 | 1 | 0% | 5,015 | 5,737 | +14% | 0 | 0 | — |
case-02 | fail→fail | 43,061 | 22,547 | -48% | 1 | 1 | 0% | 5,766 | 5,217 | -10% | 0 | 0 | — |
case-03 | pass→pass | 15,534 | 13,159 | -15% | 1 | 1 | 0% | 2,056 | 3,378 | +64% | 0 | 0 | — |
case-04 | pass→pass | 16,444 | 16,746 | +2% | 1 | 1 | 0% | 2,071 | 4,044 | +95% | 0 | 0 | — |
case-05 | pass→pass | 22,117 | 18,720 | -15% | 1 | 1 | 0% | 3,094 | 4,386 | +42% | 0 | 0 | — |
case-06 | fail→pass | 21,984 | 10,141 | -54% | 1 | 1 | 0% | 3,159 | 2,800 | -11% | 0 | 0 | — |
case-07 | fail→pass | 14,704 | 8,982 | -39% | 1 | 1 | 0% | 1,915 | 2,619 | +37% | 0 | 0 | — |
case-08 | fail→pass | 21,493 | 19,870 | -8% | 1 | 1 | 0% | 3,034 | 4,200 | +38% | 0 | 0 | — |
case-09 | fail→pass | 20,535 | 14,406 | -30% | 1 | 1 | 0% | 2,009 | 3,274 | +63% | 0 | 0 | — |
case-10 | pass→pass | 13,386 | 11,969 | -11% | 1 | 1 | 0% | 1,715 | 3,087 | +80% | 0 | 0 | — |
case-11 | fail→pass | 28,267 | 9,400 | -67% | 1 | 1 | 0% | 2,139 | 2,376 | +11% | 0 | 0 | — |
case-12 | pass→pass | 9,197 | 10,705 | +16% | 1 | 1 | 0% | 1,236 | 2,590 | +110% | 0 | 0 | — |
case-13 | pass→pass | 17,023 | 4,299 | -75% | 1 | 1 | 0% | 2,367 | 2,362 | -0% | 0 | 0 | — |
case-14 | fail→pass | 10,885 | 9,853 | -9% | 1 | 1 | 0% | 2,052 | 2,678 | +31% | 0 | 0 | — |
case-15 | fail→pass | 13,700 | 10,662 | -22% | 1 | 1 | 0% | 2,443 | 2,629 | +8% | 0 | 0 | — |
case-16 | fail→pass | 16,819 | 13,630 | -19% | 1 | 1 | 0% | 2,656 | 3,464 | +30% | 0 | 0 | — |
case-17 | fail→pass | 23,939 | 6,817 | -72% | 1 | 1 | 0% | 1,054 | 2,886 | +174% | 0 | 0 | — |
case-18 | pass→pass | 12,834 | 3,749 | -71% | 1 | 1 | 0% | 1,632 | 2,400 | +47% | 0 | 0 | — |
case-19 | fail→pass | 21,196 | 7,852 | -63% | 1 | 1 | 0% | 3,439 | 2,266 | -34% | 0 | 0 | — |
case-20 | pass→pass | 18,303 | 8,532 | -53% | 1 | 1 | 0% | 1,720 | 3,024 | +76% | 0 | 0 | — |
case-21 | fail→pass | 39,079 | 12,406 | -68% | 1 | 1 | 0% | 5,645 | 2,792 | -51% | 0 | 0 | — |
case-22 | pass→pass | 10,167 | 14,195 | +40% | 1 | 1 | 0% | 2,065 | 3,712 | +80% | 0 | 0 | — |
case-23 | pass→pass | 9,567 | 4,226 | -56% | 1 | 1 | 0% | 1,898 | 2,569 | +35% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted, and 22 counted toward the lift figure. The other 1 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of +48 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.