360 Secure SkillHub
360 安全技能中心

Ratelimiter

用 FastAPI 提供内存滑动窗口速率限制服务,可为不同 API key 创建限额,在调用外部接口前检查、调用后消费配额,并支持重置、删除与列出限额;需本地启动服务,状态保存在进程内存中。

mirni
mirni
热度 37.72
最近更新 2026-05-11 17:42:52
分类:开发依赖:代码执行应用场景:API 集成 / 工作流

安装技能

复制下面的话术发给你的 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