← 返回 Skills 市场
chenghaifeng08-creator

API Rate Manager

作者 chenghaifeng08-creator · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
168
总下载
0
收藏
1
当前安装
1
版本数
在 OpenClaw 中安装
/install api-rate-manager
功能描述
Smart API rate limit manager with auto-retry, queue, and cost optimization. Prevents 429 errors and manages API quotas efficiently.
使用说明 (SKILL.md)

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:

❌ 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

clawhub install api-rate-manager

Quick Start

Basic Usage

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

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

Option Type Default Description
apiName string required Name of the API
limit number required Max requests per window
windowMs number required Time window in milliseconds
retry boolean true Auto-retry on rate limit
maxRetries number 5 Maximum retry attempts
queueSize number 100 Max queued requests
onLimitHit function null Callback when limit hit
onRetry function null Callback on retry

API Methods

call(fn)

Execute a function with rate limit protection.

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

batch(fns)

Execute multiple functions with rate limit protection.

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

getStatus()

Get current rate limit status.

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

reset()

Reset rate limit counters.

manager.reset();

Examples

Example 1: ClawHub Skill Installation

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

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

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

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

Strategy 2: Aggressive

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

Strategy 3: Batch Processing

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

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

Error Handling

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

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

Alerts

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

// 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

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

3. Monitor Usage

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

4. Handle Failures Gracefully

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

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

Problem: Too slow

Solution: Increase limit or reduce window

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

Problem: Queue growing too large

Solution: Process in smaller batches

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

Pricing

Tier Price Features
Basic $19 Core 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

安全使用建议
This package appears to be a self-contained rate-limiter library and is internally consistent with its documentation. Before installing in production: (1) review where you pass sensitive credentials — RateManager wraps user-provided functions, so ensure those functions do not leak secrets; (2) run the included tests locally; (3) monitor memory usage for long-running processes (the requests array grows until reset), and (4) if you plan autonomous agent use, remember autonomous invocation is platform default — the skill itself does not introduce extra permissions or network endpoints.
功能分析
Type: OpenClaw Skill Name: api-rate-manager Version: 1.0.0 The skill is a standard utility for managing API rate limits, providing features like request queuing, automatic retries, and usage statistics. The implementation in index.js is purely logical, wrapping user-provided functions without performing any independent network calls, file system operations, or sensitive data access. No evidence of prompt injection, obfuscation, or malicious intent was found in the code or documentation.
能力评估
Purpose & Capability
Name/description (API rate manager) match the included files and exported API. The code implements retry, queuing, stats, and batch helpers that align with the documentation.
Instruction Scope
SKILL.md instructs using the provided RateManager APIs and examples only call user-supplied functions (fetch, api.call, etc.). There are no instructions to read unrelated files, environment variables, or to transmit data to external endpoints controlled by the skill.
Install Mechanism
No install spec (instruction-only install via clawhub) and package is small with no download-from-URL or extract steps. package.json is normal and code is included; nothing writes unexpected binaries or reaches out to third-party hosting during install.
Credentials
The skill requires no environment variables, no credentials, and no config paths. The code does not read process.env or other secrets.
Persistence & Privilege
always is false and model invocation is allowed only by default platform behavior. The skill does not modify other skills or system-wide settings and does not request persistent elevated privileges.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install api-rate-manager
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /api-rate-manager 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release
元数据
Slug api-rate-manager
版本 1.0.0
许可证 MIT-0
累计安装 1
当前安装数 1
历史版本数 1
常见问题

API Rate Manager 是什么?

Smart API rate limit manager with auto-retry, queue, and cost optimization. Prevents 429 errors and manages API quotas efficiently. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 168 次。

如何安装 API Rate Manager?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install api-rate-manager」即可一键安装,无需额外配置。

API Rate Manager 是免费的吗?

是的,API Rate Manager 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

API Rate Manager 支持哪些平台?

API Rate Manager 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 API Rate Manager?

由 chenghaifeng08-creator(@chenghaifeng08-creator)开发并维护,当前版本 v1.0.0。

💬 留言讨论