{"uid":"cap__uEptHzn6n47OaBjVTEkK","slug":"writerslogic-token-bucket-rate-limiter-5234a421","name":"WritersLogic Token Bucket Rate Limiter","description":"Pay-per-call agents settled in USDC on Base via x402. Every response carries a signed provenance envelope.","url":"https://agents.writerslogic.com/api/v1/token-bucket?utm_source=zero.xyz","method":"POST","headers":{},"bodySchema":{"type":"object","properties":{"op":{"enum":["take","peek"],"type":"string"},"cost":{"type":"number","maximum":1000000,"minimum":0.000001,"description":"Tokens to spend; default 1."},"bucket":{"type":"string","pattern":"^[A-Za-z0-9_.:/@+-]{1,200}$","description":"Bucket name, e.g. openai:org-123:rpm."},"capacity":{"type":"number","maximum":1000000,"minimum":1},"tenantId":{"type":"string","pattern":"^[A-Za-z0-9_.-]{1,64}$","description":"Required for API-key callers (namespaced as key:<tenantId>; keep it unguessable). Ignored when a wallet paid: the payer address is the tenant."},"requestId":{"type":"string","pattern":"^[A-Za-z0-9_.:-]{1,128}$","description":"Caller-chosen id for this mutation. A retry with the same id and same input returns the stored response (24 h) instead of applying twice; the same id with different input is rejected. Send one on every mutation you may retry: without it a retry is applied again (fleet-memory record appends a duplicate; a repeated spend-ledger commit or release answers NO_HOLD because the first call already took effect)."},"refillPerSecond":{"type":"number","maximum":1000000,"minimum":0.000001}}},"responseSchema":{"type":"json"},"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.005","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.005/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.005","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.005","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_JYrK9_o9M85qYxkOnA8m5","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.005","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Atomically consumes or inspects tokens from a named rate-limiting bucket shared across an entire agent fleet, with idempotent retry support.","exampleAgentPrompt":"Check if my agent fleet can make another OpenAI call right now — use the bucket 'openai:org-123:rpm' with capacity 60 and refill 1 token per second, deduct 1 token, and use request ID 'req-abc-001' so a retry won't double-charge.","exampleUseCases":[{"title":"Throttle OpenAI calls across agent fleet","prompt":"My agents all share one OpenAI API key with a 60 requests-per-minute limit — before each call, check the bucket 'openai:shared:rpm' (capacity 60, refill 1 per second) and deduct 1 token; use request ID 'openai-req-7842' so if the agent retries it doesn't get charged twice."},{"title":"Peek at remaining quota without spending","prompt":"Don't spend any tokens — just peek at how many tokens are left in the bucket 'stripe:webhooks:rps' so I can decide whether to queue my next batch of webhook calls or wait."},{"title":"Enforce per-tenant API budget limits","prompt":"Before processing this user's request, check the bucket 'tenant:acme-corp:daily-calls' with capacity 1000 and refill rate 0.012 per second, deduct 5 tokens for this bulk operation, and use tenant ID 'acme-corp' with request ID 'bulk-op-20240115' so retries are safe."}],"resultDescription":"Returns an 'allowed' boolean indicating whether the requested tokens were successfully consumed, plus 'remaining' token count after the operation. If denied, returns 'retryAfterMs' indicating how long to wait before enough tokens refill. For peek operations, returns current state without modification. Duplicate request IDs within 24 hours return the stored response without re-applying.","failureModes":["Bucket configuration conflict: if capacity or refillPerSecond differ from initial settings, the call is rejected to prevent fleet misconfiguration","Duplicate request ID with different inputs: rejected to prevent ambiguous idempotency","Token cost exceeds remaining capacity: returns allowed=false with retryAfterMs","Invalid bucket name pattern: rejected if name contains disallowed characters","Missing tenantId for API-key callers: required field absent causes rejection","Cost below minimum (0.000001) or above maximum (1000000): schema validation failure"],"whenToPreferThis":"Use this endpoint when you need a single, consistent rate limiter shared across multiple concurrent AI agents or workers that all hit the same downstream API or resource. It is especially valuable when agents run in parallel and a local in-memory counter would cause each to independently exceed quota. The idempotent requestId makes it safe for retry-heavy agent loops. Prefer this over local throttling whenever your fleet has more than one worker or when you need verifiable, auditable quota enforcement with atomic semantics.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-11-18T18:42:49.534Z","isFirstParty":false,"canonicalSlug":"writerslogic-token-bucket-rate-limiter-5234a421"}