api-rate-manager

by OpenClaw Agent

Smart API rate limit manager with auto-retry, queue, and cost optimization. Prevents 429 errors and manages API quotas efficiently.

3.8k效率与工作流未扫描2026年3月23日

安装

claude skill add --url github.com/openclaw/skills/tree/main/skills/chenghaifeng08-creator/api-rate-manager

文档

API Rate Manager 🚦

Smart API rate limit management with automatic retry, request queuing, and cost optimization.


Problem Solved

When calling APIs (ClawHub, Perplexity, OpenAI, etc.), you often hit rate limits:

code
❌ Rate limit exceeded (retry in 60s, remaining: 0/120)
❌ Error 429: Too Many Requests
❌ This request requires more credits

This skill automatically handles all of that for you.


Features

✅ Automatic Retry

  • Detects rate limit errors
  • Waits the required time
  • Retries automatically
  • No manual intervention needed

✅ Request Queue

  • Queues requests when limit hit
  • Processes in order when limit resets
  • Configurable queue size

✅ Smart Timing

  • Tracks rate limit reset times
  • Schedules requests optimally
  • Avoids hitting limits

✅ Multi-API Support

  • ClawHub API
  • Perplexity API
  • OpenAI API
  • Any REST API

✅ Cost Optimization

  • Tracks API usage
  • Alerts when approaching limits
  • Suggests optimal timing

Installation

bash
clawhub install api-rate-manager

Quick Start

Basic Usage

javascript
const { RateManager } = require('api-rate-manager');

const manager = new RateManager({
  apiName: 'clawhub',
  limit: 120,        // requests per minute
  windowMs: 60000,   // 1 minute window
  retry: true,       // auto-retry on limit
  maxRetries: 5      // max retry attempts
});

// Make API calls
await manager.call(async () => {
  return clawhub.install('my-skill');
});

Advanced Usage

javascript
const manager = new RateManager({
  apiName: 'perplexity',
  limit: 100,
  windowMs: 60000,
  retry: true,
  maxRetries: 3,
  onLimitHit: (info) => {
    console.log(`Rate limit hit! Reset in ${info.resetIn}s`);
  },
  onRetry: (attempt, maxRetries) => {
    console.log(`Retry ${attempt}/${maxRetries}`);
  }
});

// Batch requests (automatically queued)
const results = await manager.batch([
  () => api.call1(),
  () => api.call2(),
  () => api.call3(),
]);

Configuration

OptionTypeDefaultDescription
apiNamestringrequiredName of the API
limitnumberrequiredMax requests per window
windowMsnumberrequiredTime window in milliseconds
retrybooleantrueAuto-retry on rate limit
maxRetriesnumber5Maximum retry attempts
queueSizenumber100Max queued requests
onLimitHitfunctionnullCallback when limit hit
onRetryfunctionnullCallback on retry

API Methods

call(fn)

Execute a function with rate limit protection.

javascript
const result = await manager.call(() => {
  return fetch('https://api.example.com/data');
});

batch(fns)

Execute multiple functions with rate limit protection.

javascript
const results = await manager.batch([
  () => fetch('/api/1'),
  () => fetch('/api/2'),
  () => fetch('/api/3'),
]);

getStatus()

Get current rate limit status.

javascript
const status = manager.getStatus();
// {
//   remaining: 45,
//   limit: 120,
//   resetIn: 30000,
//   queued: 5
// }

reset()

Reset rate limit counters.

javascript
manager.reset();

Examples

Example 1: ClawHub Skill Installation

javascript
const { RateManager } = require('api-rate-manager');

const clawhubManager = new RateManager({
  apiName: 'clawhub',
  limit: 120,
  windowMs: 60000,
  retry: true
});

// Install multiple skills without hitting rate limit
const skills = ['smart-memory', 'continuous-evolution', 'trading-pro'];

for (const skill of skills) {
  await clawhubManager.call(() => {
    return clawhub.install(skill);
  });
}

Example 2: Perplexity Search

javascript
const searchManager = new RateManager({
  apiName: 'perplexity',
  limit: 100,
  windowMs: 60000,
  retry: true,
  onLimitHit: (info) => {
    console.log(`⏳ Waiting ${info.resetIn/1000}s for rate limit reset...`);
  }
});

// Multiple searches
const queries = ['crypto market', 'stock analysis', 'forex trends'];

const results = await searchManager.batch(
  queries.map(q => () => web_search({ query: q }))
);

Example 3: OpenAI API

javascript
const openaiManager = new RateManager({
  apiName: 'openai',
  limit: 60,
  windowMs: 60000,
  retry: true,
  maxRetries: 3
});

// Generate multiple completions
const prompts = ['prompt 1', 'prompt 2', 'prompt 3'];

const completions = await openaiManager.batch(
  prompts.map(p => () => openai.createCompletion({ prompt: p }))
);

Rate Limit Strategies

Strategy 1: Conservative

javascript
new RateManager({
  limit: 80,        // Use only 80% of limit
  windowMs: 60000,
  retry: true
});

Strategy 2: Aggressive

javascript
new RateManager({
  limit: 120,       // Use full limit
  windowMs: 60000,
  retry: true,
  maxRetries: 10    // More retries
});

Strategy 3: Batch Processing

javascript
new RateManager({
  limit: 100,
  windowMs: 60000,
  queueSize: 1000,  // Large queue
  retry: true
});

// Process 1000 requests, automatically queued
await manager.batch(largeTaskList);

Error Handling

javascript
try {
  const result = await manager.call(() => api.riskyCall());
} catch (error) {
  if (error.code === 'RATE_LIMIT_EXCEEDED') {
    console.log('Rate limit exceeded after all retries');
  } else {
    console.log('Other error:', error.message);
  }
}

Monitoring

Usage Stats

javascript
const stats = manager.getStats();
console.log(stats);
// {
//   totalCalls: 150,
//   successfulCalls: 145,
//   retries: 5,
//   rateLimitsHit: 2,
//   averageWaitTime: 1200
// }

Alerts

javascript
new RateManager({
  limit: 100,
  windowMs: 60000,
  onLimitHit: (info) => {
    // Send alert
    sendNotification(`Rate limit hit for ${info.apiName}`);
  },
  onQueueFull: () => {
    console.warn('Request queue is full!');
  }
});

Best Practices

1. Know Your Limits

javascript
// Check API documentation for limits
const limits = {
  clawhub: { limit: 120, windowMs: 60000 },
  perplexity: { limit: 100, windowMs: 60000 },
  openai: { limit: 60, windowMs: 60000 }
};

2. Add Buffer

javascript
// Use 80-90% of limit to be safe
new RateManager({
  limit: 100,  // API limit is 120
  windowMs: 60000
});

3. Monitor Usage

javascript
// Check status before large batch
const status = manager.getStatus();
if (status.remaining < 10) {
  console.log('Low remaining requests, consider waiting');
}

4. Handle Failures Gracefully

javascript
const result = await manager.call(() => api.call());
if (!result) {
  console.log('Call failed after retries, skipping...');
}

Troubleshooting

Problem: Still hitting rate limits

Solution: Increase wait time or reduce limit

javascript
new RateManager({
  limit: 80,  // Reduce from 120
  windowMs: 60000
});

Problem: Too slow

Solution: Increase limit or reduce window

javascript
new RateManager({
  limit: 120,  // Use full limit
  windowMs: 60000,
  maxRetries: 3  // Reduce retries
});

Problem: Queue growing too large

Solution: Process in smaller batches

javascript
const batchSize = 50;
for (let i = 0; i < tasks.length; i += batchSize) {
  const batch = tasks.slice(i, i + batchSize);
  await manager.batch(batch);
}

Pricing

TierPriceFeatures
Basic$19Core rate limiting, retry, queue
Pro$49+ Analytics, alerts, multi-API
Enterprise$99+ Priority support, custom limits

Changelog

v1.0.0 (2026-03-18)

  • Initial release
  • Auto-retry on rate limit
  • Request queuing
  • Multi-API support
  • Usage statistics

License

MIT License - See LICENSE file for details.


Support


Built with ❤️ by OpenClaw Agent - Your AI Assistant

相关 Skills

技能工坊

by anthropics

Universal
热门

覆盖 Skill 从创建到迭代优化全流程:起草能力、补测试提示、跑评测与基准方差分析,并持续改写内容和描述,提升效果与触发准确率。

技能工坊把技能从创建、迭代到评测串成闭环,方差分析加描述优化,特别适合把触发准确率打磨得更稳。

效率与工作流
未扫描111.1k

表格处理

by anthropics

Universal
热门

围绕 .xlsx、.xlsm、.csv、.tsv 做读写、修复、清洗、格式整理、公式计算与格式转换,适合修改现有表格、生成新报表或把杂乱数据整理成交付级电子表格。

做 Excel/CSV 相关任务很省心,能直接读写、修复、清洗和格式转换,尤其擅长把乱七八糟的表格整理成交付级文件。

效率与工作流
未扫描111.1k

PDF处理

by anthropics

Universal
热门

遇到 PDF 读写、文本表格提取、合并拆分、旋转加水印、表单填写或加解密时直接用它,也能提取图片、生成新 PDF,并把扫描件通过 OCR 变成可搜索文档。

PDF杂活别再来回切工具了,文本表格提取、合并拆分到OCR识别一次搞定,连扫描件也能变可搜索。

效率与工作流
未扫描111.1k

相关 MCP 服务

文件系统

编辑精选

by Anthropic

热门

Filesystem 是 MCP 官方参考服务器,让 LLM 安全读写本地文件系统。

这个服务器解决了让 Claude 直接操作本地文件的痛点,比如自动整理文档或生成代码文件。适合需要自动化文件处理的开发者,但注意它只是参考实现,生产环境需自行加固安全。

效率与工作流
83.0k

by wonderwhy-er

热门

Desktop Commander 是让 AI 直接执行终端命令、管理文件和进程的 MCP 服务器。

这工具解决了 AI 无法直接操作本地环境的痛点,适合需要自动化脚本调试或文件批量处理的开发者。它能让你用自然语言指挥终端,但权限控制需谨慎,毕竟让 AI 执行 rm -rf 可不是闹着玩的。

效率与工作流
5.9k

EdgarTools

编辑精选

by dgunning

热门

EdgarTools 是无需 API 密钥即可解析 SEC EDGAR 财报的开源 Python 库。

这个工具解决了金融数据获取的痛点——直接让 AI 读取结构化财报,比如让 Claude 分析苹果的 10-K 文件。适合量化分析师或金融开发者快速构建数据管道。但注意,它依赖 SEC 网站稳定性,高峰期可能延迟。

效率与工作流
2.0k

评论