360 Secure SkillHub
360 安全技能中心

Ratelimiter

这是为AI代理打造的内存滑动窗口限流器,核心功能包括创建/管理速率限制、检查请求是否允许、消耗配额、重置/删除限制等。典型场景是AI代理调用外部API前,通过该工具管控请求频次,避免触发外部API限流。以FastAPI服务运行,通过HTTP接口交互,输入支持JSON或路径参数,输出JSON格式的权限状态、剩余配额等信息。

mirni
mirni
热度 37.63
最近更新 2026-05-11 17:42:52
分类:开发依赖:代码执行 / 第三方 API应用场景:API 集成 / DevOps / 自动化脚本

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add gh-ratelimiter
Metadata
name
gh-ratelimiter
description
In-memory sliding window rate limiter for AI agents. Create rate limits per API key, check quota before calling, consume requests, reset, and list all limits. Keeps agents from hitting rate limits on external APIs.
metadata
{"openclaw":{"emoji":"⏱️","requires":{"bins":["python"]},"install":[{"id":"pip","kind":"uv","packages":["fastapi","uvicorn","pydantic"]}]}}

RateLimiter

Track and enforce rate limits so your agent doesn't get throttled.

Start the server

uvicorn ratelimiter.app:app --port 8012

Create a rate limit

curl -s -X POST http://localhost:8012/v1/limits \
  -H "Content-Type: application/json" \
  -d '{"key": "openai-api", "max_requests": 60, "window_seconds": 60}' | jq

Check before calling

curl -s http://localhost:8012/v1/check/openai-api | jq '.allowed'

Consume after calling

curl -s -X POST http://localhost:8012/v1/consume/openai-api | jq

Returns allowed (true/false), remaining, and retry_after_seconds (how long to wait if exhausted).

List all limits

curl -s http://localhost:8012/v1/limits | jq

Reset quota

curl -s -X POST http://localhost:8012/v1/reset/openai-api | jq

Delete a limit

curl -s -X DELETE http://localhost:8012/v1/limits/openai-api | jq

Endpoints

Method Path Description
POST /v1/limits Create/update a rate limit
GET /v1/limits List all rate limits
GET /v1/check/{key} Check if next request is allowed
POST /v1/consume/{key} Use one request from quota
POST /v1/reset/{key} Reset quota to full
DELETE /v1/limits/{key} Delete a rate limit