Ratelimit with unkey

Unkey’s ratelimit API provides a global low latency solution to limit your functions and protect upstream services.

Val Town users get limited free usage of unkey's rate limiting service, so you can import and start rate limiting immediately. No need to set up an unkey account or copy & paste an API key.

Usage

import { ratelimit } from "https://www.val.town/x/unkey/ratelimit/code/sdk.ts"; export default async function (req: Request): Promise<Response> { const rl = await ratelimit({ identifier: "someone", limit: 5, duration: 60000, }); if (!rl.success) { return Response.json("back off", { status: 429 }); } // Perform expensive operation here return new Response("ok"); }

Limitations

TODO - explain how much "free rate limiting" Val Town users get

If you need higher limits, sign up for your own unkey account here.