perplexity-rate-limits

Implement Perplexity rate limiting, backoff, and idempotency patterns.Use when handling rate limit errors, implementing retry logic,or optimizing API request throughput for Perplexity.Trigger with phrases like "perplexity rate limit", "perplexity throttling","perplexity 429", "perplexity retry", "perplexity backoff".

⭐920stars🔀111forks📁View on GitHub🕐Updated Jan 9, 2026

When & Why to Use This Skill

This Claude skill provides a robust framework for managing Perplexity API interactions by implementing essential reliability patterns. It automates the handling of 429 rate limit errors through exponential backoff with jitter, ensures request consistency with idempotency keys, and optimizes throughput using queue-based throttling. By integrating these patterns, developers can build more resilient AI applications that handle API constraints gracefully and prevent duplicate operations.

Use Cases

  • Automated Error Recovery: Seamlessly handle 429 (Too Many Requests) errors using exponential backoff to ensure high availability of Perplexity-powered features.
  • Safe Request Retries: Utilize idempotency keys to safely retry failed API calls without the risk of duplicate processing or redundant billing.
  • Throughput Optimization: Implement queue-based rate limiting and concurrency control to maximize API usage within specific tier limits (Free, Pro, or Enterprise).
  • Dynamic Rate Limit Monitoring: Real-time tracking of rate limit headers (X-RateLimit-Remaining, X-RateLimit-Reset) to proactively throttle requests before hitting hard limits.
nameperplexity-rate-limits
description|
allowed-toolsRead, Write, Edit
version1.0.0
licenseMIT
authorJeremy Longshore <jeremy@intentsolutions.io>

Perplexity Rate Limits

Overview

Handle Perplexity rate limits gracefully with exponential backoff and idempotency.

Prerequisites

  • Perplexity SDK installed
  • Understanding of async/await patterns
  • Access to rate limit headers

Instructions

Step 1: Understand Rate Limit Tiers

Tier Requests/min Requests/day Burst
Free 60 1,000 10
Pro 300 10,000 50
Enterprise 1,000 100,000 200

Step 2: Implement Exponential Backoff with Jitter

async function withExponentialBackoff<T>(
  operation: () => Promise<T>,
  config = { maxRetries: 5, baseDelayMs: 1000, maxDelayMs: 32000, jitterMs: 500 }
): Promise<T> {
  for (let attempt = 0; attempt <= config.maxRetries; attempt++) {
    try {
      return await operation();
    } catch (error: any) {
      if (attempt === config.maxRetries) throw error;
      const status = error.status || error.response?.status;
      if (status !== 429 && (status < 500 || status >= 600)) throw error;

      // Exponential delay with jitter to prevent thundering herd
      const exponentialDelay = config.baseDelayMs * Math.pow(2, attempt);
      const jitter = Math.random() * config.jitterMs;
      const delay = Math.min(exponentialDelay + jitter, config.maxDelayMs);

      console.log(`Rate limited. Retrying in ${delay.toFixed(0)}ms...`);
      await new Promise(r => setTimeout(r, delay));
    }
  }
  throw new Error('Unreachable');
}

Step 3: Add Idempotency Keys

import { v4 as uuidv4 } from 'uuid';
import crypto from 'crypto';

// Generate deterministic key from operation params (for safe retries)
function generateIdempotencyKey(operation: string, params: Record<string, any>): string {
  const data = JSON.stringify({ operation, params });
  return crypto.createHash('sha256').update(data).digest('hex');
}

async function idempotentRequest<T>(
  client: PerplexityClient,
  params: Record<string, any>,
  idempotencyKey?: string  // Pass existing key for retries
): Promise<T> {
  // Use provided key (for retries) or generate deterministic key from params
  const key = idempotencyKey || generateIdempotencyKey(params.method || 'POST', params);
  return client.request({
    ...params,
    headers: { 'Idempotency-Key': key, ...params.headers },
  });
}

Output

  • Reliable API calls with automatic retry
  • Idempotent requests preventing duplicates
  • Rate limit headers properly handled

Error Handling

Header Description Action
X-RateLimit-Limit Max requests Monitor usage
X-RateLimit-Remaining Remaining requests Throttle if low
X-RateLimit-Reset Reset timestamp Wait until reset
Retry-After Seconds to wait Honor this value

Examples

Queue-Based Rate Limiting

import PQueue from 'p-queue';

const queue = new PQueue({
  concurrency: 5,
  interval: 1000,
  intervalCap: 10,
});

async function queuedRequest<T>(operation: () => Promise<T>): Promise<T> {
  return queue.add(operation);
}

Monitor Rate Limit Usage

class RateLimitMonitor {
  private remaining: number = 60;
  private resetAt: Date = new Date();

  updateFromHeaders(headers: Headers) {
    this.remaining = parseInt(headers.get('X-RateLimit-Remaining') || '60');
    const resetTimestamp = headers.get('X-RateLimit-Reset');
    if (resetTimestamp) {
      this.resetAt = new Date(parseInt(resetTimestamp) * 1000);
    }
  }

  shouldThrottle(): boolean {
    // Only throttle if low remaining AND reset hasn't happened yet
    return this.remaining < 5 && new Date() < this.resetAt;
  }

  getWaitTime(): number {
    return Math.max(0, this.resetAt.getTime() - Date.now());
  }
}

Resources

Next Steps

For security configuration, see perplexity-security-basics.