---
title: "Tune rate limits"
description: "Throttle sign-in code sends and checks, passkey sign-in challenges, billing syncs, metered AI calls, admin actions, invitations and your own endpoints with Convex's rate-limiter component, pre-seeded with the package defaults."
canonical_url: "https://nuxt-backend.dev/docs/ship/security/rate-limits"
---
# Tune rate limits

> Throttle sign-in code sends and checks, passkey sign-in challenges, billing syncs, metered AI calls, admin actions, invitations and your own endpoints with Convex's rate-limiter component, pre-seeded with the package defaults.

Version: nuxt-backend 0.6.x · Tab: Ship · Kind: how-to · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

- [API reference](https://nuxt-backend.dev/docs/reference/api/rate-limit)
- [Source](https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/rate-limit.ts)

Every flow that sends mail, spends money or acts on someone else is rate-limited by default. The limits run on Convex's official rate-limiter component, which the scaffold mounts, so you tune them in one file. `setupRateLimiter(components, limits?)` returns a `RateLimiter` pre-seeded with `DEFAULT_LIMITS`:

- sign-in codes sent and checked per address, with a ceiling for the whole deployment;
- email changes and account deletions per account;
- entitlement syncs and metered AI calls per billing entity, with a credit budget per day;
- administrator actions;
- invitations per inviter and for the deployment, and new workspaces per member;
- passkey challenges per client address and for the deployment.

[Limits and retention](https://nuxt-backend.dev/docs/reference/backend/limits#rate-limits) lists each one with its rate, burst and key, read from the code. Your `limits` merge on top and can override any of them. A launch most often raises the two deployment-wide ceilings, `emailOtpGlobal` and `invitationGlobal` ([Launch from a waitlist](https://nuxt-backend.dev/docs/ship/checklist#launch-from-a-waitlist)).

```ts [backend/rateLimiter.ts]
import { setupRateLimiter } from 'nuxt-backend/rate-limit'
import { components } from './_generated/api'

export const rateLimiter = setupRateLimiter(components, {
  // your own limits, merged over DEFAULT_LIMITS
  sendMessage: { kind: 'token bucket', rate: 10, period: 60_000 },
})
```

Pass the limiter into `setupAuth` to throttle sending and checking codes ([cross-component wiring](https://nuxt-backend.dev/docs/build/auth/setup#cross-component-wiring), [Security](https://nuxt-backend.dev/docs/ship/security#passwordless-sign-in-and-its-rate-limits)). Pass it into `setupAi` too, whose metered actions use the `ai` limit unless you name another, and into `setupEmail`, whose contact form and inbound mail spend `contact`, `contactGlobal`, `inboundMail` and `inboundMailGlobal`.

## Privileged routes

Once the limiter reaches `setupAuth`, it also bounds the auth routes where one caller acts on *other people* or on an address they typed. It bounds the route that makes a billing entity, the route that deletes an account, and the route anyone may call without a session too:

<table>
<thead>
  <tr>
    <th>
      What it limits
    </th>
    
    <th>
      Limit
    </th>
    
    <th>
      Keyed by
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        /admin/*
      </code>
      
      : list, create, update, ban/unban, set role, impersonate, revoke sessions, remove user
    </td>
    
    <td>
      <code>
        admin
      </code>
      
      : 30/minute, burst 10
    </td>
    
    <td>
      the administrator's user id
    </td>
  </tr>
  
  <tr>
    <td>
      Inviting someone to a workspace
    </td>
    
    <td>
      <code>
        invitation
      </code>
      
      : 30/hour, burst 10
    </td>
    
    <td>
      the inviter's user id
    </td>
  </tr>
  
  <tr>
    <td>
      …and the same invitation again
    </td>
    
    <td>
      <code>
        invitationGlobal
      </code>
      
      : 200/hour, fixed window
    </td>
    
    <td>
      nothing: one ceiling for the deployment
    </td>
  </tr>
  
  <tr>
    <td>
      Creating a workspace, which is a billing entity (with a free plan in the catalog, a provider customer and the plan's credits)
    </td>
    
    <td>
      <code>
        workspaceCreate
      </code>
      
      : 10/hour, burst 5
    </td>
    
    <td>
      the member's user id
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        /email-otp/request-email-change
      </code>
      
      : the code to an email change's new address
    </td>
    
    <td>
      <code>
        emailChange
      </code>
      
      : 5/hour
    </td>
    
    <td>
      the user's id
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        /delete-user
      </code>
      
      : an account's own deletion, which also takes a recent sign-in
    </td>
    
    <td>
      <code>
        accountDelete
      </code>
      
      : 3/hour
    </td>
    
    <td>
      the user's id
    </td>
  </tr>
  
  <tr>
    <td>
      …and the same route again
    </td>
    
    <td>
      <code>
        emailOtpGlobal
      </code>
      
      : 300/hour, fixed window
    </td>
    
    <td>
      nothing: the ceiling every code send spends
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        /passkey/generate-authenticate-options
      </code>
      
      : the challenge every passkey sign-in starts with
    </td>
    
    <td>
      <code>
        passkeySignIn
      </code>
      
      : 30/minute, burst 30
    </td>
    
    <td>
      an HMAC of the client's address under the auth secret, as Better Auth reads the address
    </td>
  </tr>
  
  <tr>
    <td>
      …and the same route again
    </td>
    
    <td>
      <code>
        passkeySignInGlobal
      </code>
      
      : 3000/hour, fixed window
    </td>
    
    <td>
      nothing: the ceiling behind the per-address bucket
    </td>
  </tr>
</tbody>
</table>

Better Auth already *authorizes* these routes; the limits bound how fast an authorized caller may go, so one compromised admin session cannot ban a thousand accounts. They are keyed by user id rather than by session, so opening more sessions does not multiply the budget. The caller is the session the route runs with, whether its token came in a cookie or as `Authorization: Bearer`; a request with no credential is left to the route, which answers 401 itself, and one whose credential matches no session is refused with 401 before it runs.

A per-caller limit bounds one account and nothing more: thirty invitations an hour each is still a lot of mail from a workspace of fifty. Invitations therefore also spend `invitationGlobal`, an unkeyed ceiling for the whole deployment, because the cost lands on a shared resource: your sending domain's reputation. It is consumed **after** the inviter's own bucket allowed the request, so one account's refused excess never eats everyone else's budget, and a deployment at its ceiling answers 429 with *"Invitations are temporarily unavailable"* rather than blaming the inviter. It is the counterpart of `emailOtpGlobal` on the package's other outbound-email path; admin routes have no such ceiling, because banning a user spends nothing anyone else shares.

A passkey sign-in has no caller yet either, but it serves people, so its challenge route spends a bucket per client address first. A tap on a passkey button spends one, and so does every sign-in page that offers passkeys in the email field's [autofill](https://nuxt-backend.dev/docs/build/auth/sign-in#passkey-autofill). The address is the one Convex sees connect, which it writes into `x-forwarded-for` itself, so a caller can't name another. Sign-in requests come through your Nuxt app's auth proxy, though, and there the address that connects is your server's: the app's server signs the visitor's address into each request it forwards, under `PROTECTION_PROOF_SECRET`, and the deployment takes it only when that signature holds (Better Auth then reads it first: `advanced.ipAddress.ipAddressHeaders`). Without the secret on both sides, every visitor through the app shares one bucket, so set it, or raise `passkeySignIn`. `passkeySignInGlobal` is the ceiling an address-rotating caller meets, spent only after the address's own bucket allowed the request. A request whose headers name no address Better Auth trusts spends the ceiling alone. At the ceiling, the passkey prompt answers 429, autofill offers no passkey, and sign-in codes still sign people in. The answer (`/passkey/verify-authentication`) uses its challenge up, so it spends nothing of its own. Raise `passkeySignInGlobal` when more sign-in pages than that open in an hour.

The busiest deployment-wide ceilings, `emailOtpGlobal`, `passkeySignInGlobal` and `aiGlobal`, count asynchronously (`applyUpdates: 'asynchronously'`): a request checks the window on a snapshot and queues its token, so concurrent sign-ins never conflict over the window's one row. Under a burst the ceiling lets through every request that read the window before the queue caught up, so more than its rate. The queue then applies every queued spend without stopping at zero, so the overshoot comes out of the next windows: a flood keeps the ceiling closed for longer than one window. The per-address limits don't bound a flood, which rotates addresses: a sign-in code has no per-client limit, only `emailOtp` per address and this ceiling. An override of one of them replaces its whole config, so it counts transactionally, and may be sharded, unless it sets `applyUpdates: 'asynchronously'` too; an asynchronous limit can't be sharded.

`/admin/stop-impersonating` and `/admin/has-permission` are exempt. The first is the way *out* of an impersonated session and must never be throttled, and the second is a read-only check an admin UI calls on render.

Better Auth's own per-path limiter is off by default: it keeps its counters in memory, which on Convex lasts one function call, so it would limit nothing. To throttle another route through it, turn it on (`enabled: true`) with durable storage. It counts per IP and takes its rules from your auth options:

```ts [backend/auth.ts]
setupAuth(components, query, {
  email,
  authOptions: {
    rateLimit: {
      enabled: true,
      storage: 'database',
      customRules: { '/sign-in/email-otp': { window: 60, max: 10 } },
    },
  },
})
```

## What the user sees

Every 429 the package raises is an `APIError('TOO_MANY_REQUESTS')` whose body carries `code: 'rate_limited'`, the `limit` it spent and `retryAfter`, the milliseconds until the limit lets the caller through again. That covers the code limits (`emailOtp`, `emailOtpGlobal`, `emailOtpAttempt`, `emailChange`), the passkey challenge (`passkeySignIn`, `passkeySignInGlobal`) and the privileged routes above. `useLoginFlow()` and `useEmailChange()` keep it in `error` as `{ code: 'rate_limited', data: { limit, retryAfter }, message }`, where `data.retryAfter` is still in milliseconds, and expose the same wait as `retryAfter`, in whole seconds rounded up. The body carries no sentence of its own, so `message` is the `errors.rate_limited_for` label, *"Too many requests. Try again in N seconds."*, in the person's language, and `<AuthForm>` and `<ProfileSettings>` show it (see [the authentication guide](https://nuxt-backend.dev/docs/build/auth/sign-in)).

Better Auth's own per-path limiter, once you turn it on, answers 429 too, but it sends the wait only as an `X-Retry-After` header. The auth client's `{ data, error }` result drops headers, so those refusals read *"Try again in a moment."* with `retryAfter` left `null`.

Outside the auth routes, the package's limits (`billingSync`, `ai`, `aiBudget`) throw the limiter's own error, and `getBackendError(error)` reads it, like the 429 above, as `rate_limited` with `limit` and `retryAfter` ([Handle errors](https://nuxt-backend.dev/docs/build/data/read-write/errors)).

The Convex limiter `setupRateLimiter` returns can also give capacity back: `rateLimiter.credit(ctx, 'yourLimit', { key, count })` restores `count` tokens, up to the limit's capacity. It suits a limit that counts an estimate, as `aiBudget` does: the package gives that one back what a run did not spend ([Set budgets and track costs](https://nuxt-backend.dev/docs/build/ai/models#budgets-and-costs)). A limit that counts attempts should keep them, or a refused caller could try again for free.

<note>

There are no password limits: the package has no passwords. Guessing at one code is bounded by Better Auth's own `allowedAttempts` (three wrong guesses), and guessing at one address by `emailOtpAttempt`. `DEFAULT_LIMITS` is exported from `nuxt-backend/rate-limit`, to read or extend the defaults.

</note>

## Related

- [Security model](https://nuxt-backend.dev/docs/ship/security#passwordless-sign-in-and-its-rate-limits): the code limits, and why each runs where it does.
- [Limits and retention](https://nuxt-backend.dev/docs/reference/backend/limits): every default value in one table.
- [Respond to incidents](https://nuxt-backend.dev/docs/ship/operate/runbooks#a-rate-limit-spike): what to do when the ceilings start refusing.
- [Handle errors](https://nuxt-backend.dev/docs/build/data/read-write/errors): reading `rate_limited` and `retryAfter` in a page.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
