API Reference
Hono helpers for @g14o/ratelimit.
Generics and Env typing
@g14o/ratelimit-hono is generic over Hono's Env so Bindings and Variables flow into handler callbacks.
| Symbol | Description |
|---|---|
createRateLimit<E extends Env>(options) | Factory. Pass your app's env (e.g. AppEnv) to bind types for the whole client. |
HonoRateLimitClient<E> | Client returned by the factory. All methods use Context<E>. |
HonoRateLimitOptions<E> | Per-call options. identifierFn and skipRateLimit (boolean or callback) receive Context<E>. Global skipRateLimit on CreateRateLimitOptions is boolean-only. |
HonoHandler<E> | Route handler passed to withRateLimit / withUserRateLimit. |
Env | Re-exported from hono. Use as the base for your AppEnv type. |
withRateLimit and withUserRateLimit return MiddlewareHandler<E>, assignable to typed app.get / app.post routes.
CreateRateLimitOptions
| Option | Type | Description |
|---|---|---|
env? | | Environment name override. When omitted, falls back to Values |
inMemoryDuringBuild? | | When true |
hooks? | | Optional lifecycle hooks for observability and side effects. Hooks are awaited; hook errors are logged and swallowed so they never affect rate limiting or fail-open behavior. |
logger? | | Application logger. Defaults to a silent no-op logger. |
skipRateLimit? | | When |
tiers? | | Override built-in tier limits/windows/prefixes. Each tier key is optional; each field inside a tier is optional and merged onto factory defaults. |
redis? | | Legacy Upstash credentials or client. Mutually exclusive with |
store? | | Explicit store implementation (preferred). |
HonoRateLimitClient
| Prop | Type | Description |
|---|---|---|
checkRateLimit | | Checks the rate limit for a Hono request without wrapping a handler. |
getRateLimiter | | Returns a cached rate limiter adapter for a tier. |
middleware | | Hono middleware that rate-limits before Returns |
reset | | Clears in-memory limiter state and the adapter cache. Useful in tests; does not reset Upstash Redis counters. |
userMiddleware | | Hono middleware with per-user rate limiting. Uses |
withRateLimit | | Wraps a Hono route handler with rate limiting. Returns |
withUserRateLimit | | Wraps a Hono route handler with per-user rate limiting. |
HonoRateLimitOptions
| Option | Type | Description |
|---|---|---|
identifierFn? | | Function to get the identifier for the request. Defaults to the IP address of the request. |
prefix? | | Redis key prefix override for this call. Defaults to the tier prefix. |
skipRateLimit? | | Skip rate limit for this request. |
tier? | | Rate limit tier to use. Defaults to |