{"success":true,"name":"rate-limit-and-budget-the-endpoint-before-someone-abuses-it","description":"Exposing an endpoint that is expensive, public, or callable in loops","category":"ai-brimind","path":"ai-brimind/rate-limit-and-budget-the-endpoint-before-someone-abuses-it/SKILL.md","file":"SKILL.md","content":"---\nname: rate-limit-and-budget-the-endpoint-before-someone-abuses-it\ndescription: \"Exposing an endpoint that is expensive, public, or callable in loops\"\n---\n\n# Rate-Limit and Budget the Endpoint Before Someone Abuses It\n\n## When to use\nYou are exposing an endpoint that hits the database, an external paid API, or heavy compute, and nothing limits how often one caller can hit it.\n\n## Example request\nSearch endpoint with no limit → one script hammers it and the database melts for everyone; per-caller rate limiting is the standard guard. — Endpoint calls a paid third-party API per request → a bug in one client burns the monthly budget in an hour; a quota is the cost seatbelt. — Login endpoint unthrottled → attackers brute-force passwords freely; throttling failed attempts is a security control, not just performance. — Rate limit exists but returns a generic 500 → clients can't back off properly; 429 with retry-after is the agreed signal.\n\n## Instructions\nAct as a capacity guardian who assumes every public endpoint will be called in a loop by accident or on purpose. Before exposing it: 1) Estimate the cost of one call — database load, external API fees, compute — and ask what happens at 100x expected traffic from a single caller. 2) Check the existing mechanism first: API gateway limits, framework middleware, provider-side quotas — configure what exists before writing a custom limiter. 3) Choose the limiting key deliberately (per user, per API key, per IP) based on who the realistic abuser is, and set stricter limits on sensitive endpoints like login. 4) Return the standard signal on limit: 429 with retry-after information, using the project's error envelope, so well-behaved clients back off correctly. 5) If you can't predict traffic, set a conservative limit with monitoring and loosen it with data — never launch unlimited 'to see what happens'. Only expose once the abuse case is confirmed bounded, and explain how the limit protects shared resources rather than just annoying users.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #893\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}