Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx skills add PostHog/posthog-foss --skill using-redis-token-bucketsgit clone --depth 1 https://github.com/PostHog/posthog-fossWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/posthog/posthog-foss/using-redis-token-buckets)<a href="https://agentmods.dev/skills/posthog/posthog-foss/using-redis-token-buckets"><img src="https://agentmods.dev/badge/skills/posthog/posthog-foss/using-redis-token-buckets.svg" alt="Measured on agentmods" height="20"></a>- NVIDIA SkillSpector pass
What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00148 | $0.01503 |
| Opus 5 | $0.00074 | $0.00751 |
| Sonnet 5 | $0.00030 | $0.00301 |
| Haiku 4.5 | $0.00015 | $0.00150 |
Grade A, and why
using-redis-token-buckets scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 72 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Using Redis token buckets
posthog/token_bucket.py is the repo's primitive for bucket-like limits in Redis. A bucket holds up to burst tokens and refills continuously at per_hour / 3600 tokens per second. Every operation is atomic (a server-side Lua script), so concurrent web workers cannot double-spend a token.
Use this skill when
- Adding a rate limit where callers legitimately burst but must be capped on sustained rate
- A limit needs a refund path: charge on entry, give the token back when the request provably did no work
Retry-Aftermust be the real per-caller wait for the next token, not "seconds until the top of the hour"- Replacing a fixed-window cache counter that suffers 2x boundary bursts or full-window lockouts
- Exposing
RateLimit-Limit/Remaining/Resetheaders or a quota introspection endpoint (usepeek)
When NOT to use it
- Per-IP or per-user request throttling on ordinary DRF endpoints: subclass the existing throttles in
posthog/rate_limit.py(IPThrottle,UserRateThrottle,PersonalApiKeyRateThrottle). They integrate with DRF's lifecycle and theRATE_LIMIT_ENABLEDinstance setting. - Outbound third-party API calls: use
posthog/egress/and itslimits-library sliding-window limiter (posthog/egress/limiter/), which carries priorities and degraded fallbacks. - Hard quotas that must survive a Redis flush: a bucket is best-effort (eviction or failover hands the caller a fresh budget). Pair it with a durable Postgres count for the few operations where that matters, and treat the bucket as the fast path.
- Concurrency caps (how many at once, not how often): see the sorted-set gate in
posthog/clickhouse/client/limit.py.
limits (vendored library) vs this module
The repo also vendors the limits library (used by posthog/egress/limiter/backends.py). Pick by the semantics you need, not by familiarity:
- Use
limitswhen a plain window answers the question "no more than N per window" and nothing ever needs to be un-counted. ItsMovingWindowRateLimiter/SlidingWindowCounterRateLimiterstrategies avoid fixed-window boundary bursts, itsRedisStorageruns its own Lua so hits are atomic, andtest()/get_window_stats()cover peeking and remaining/reset. For outbound third-party calls specifically, don't use it directly; go throughposthog/egress/, which wraps it with priorities and a degraded in-memory fallback. - Use this module when you need what
limitscannot express: a token bucket (independent burst capacity and refill rate), a refund path (its API ishit/test/get_window_stats/clear; there is no way to give a hit back), aRetry-Afterthat is the wait for the next token rather than the window edge, or variable per-request cost.
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 4d ago First seen · 72 lines · 148 tokens per session scan A 4b87c0396448
using-redis-token-buckets is a skill published in the GitHub repository PostHog/posthog-foss (714 stars, last pushed yesterday), licensed MIT. It adds 148 tokens to every session and 1,503 once invoked, about $0.0007 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.
Other skills, from other repositories
using-redis-token-buckets
Use when adding a bucket-like rate limit backed by Redis: a per-caller budget with burst capacity and continuous refill, a refund path for requests that did no work, or a limit whose Retry-After must be a real wait rather than a window edge. posthog/tokenbucket.py provides an atomic Lua token bucket (consume, refund…
background-job-orchestrator
Expert in background job processing with Bull/BullMQ (Redis), Celery, and cloud queues. Implements retries, scheduling, priority queues, and worker management. Use for async task processing, email campaigns, report generation, batch operations. Activate on "background job", "async task", "queue", "worker", "BullMQ"…
nw-sd-patterns
Core distributed systems patterns - load balancing, caching, sharding, consistent hashing, message queues, rate limiting, CDN, Bloom filters, ID generation, replication, conflict resolution, CAP theorem.
cache-strategy
Design and implement caching layers for APIs and web applications using Redis or Memcached. Use when you need to reduce database load, improve response times, or handle traffic spikes. Covers cache-aside, write-through, and write-behind patterns, TTL strategies, cache invalidation, and stampede prevention. Trigger…
bull-mq
You are an expert in BullMQ, the high-performance job queue for Node.js built on Redis. You help developers build reliable background processing systems with delayed jobs, rate limiting, prioritization, repeatable cron jobs, job dependencies, concurrency control, and dead-letter handling — powering email sending…
spring-data-redis
Use when implementing caching, session storage, rate limiting, or any Redis integration. Covers cache-aside pattern, key naming, TTL strategy, and serialization config.