---
title: "Limit resources per plan"
description: "Declare how many projects, stories or sites each plan allows, count them in the mutation that makes them with requireQuota, and show what is left with useFeatures and the Gate component. Experimental."
canonical_url: "https://nuxt-backend.dev/docs/build/billing/subscriptions/quotas"
---
# Limit resources per plan

> Declare how many projects, stories or sites each plan allows, count them in the mutation that makes them with requireQuota, and show what is left with useFeatures and the Gate component. Experimental.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: how-to · Status: experimental

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/use-features)
- [Source](https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/billing/quotas.ts)

A quota caps how many of a thing a billing entity may hold at once: projects, strips, sites. You declare each plan's limits in the catalog, count in the mutation that makes the thing, give back in the one that removes it, and show what is left in the UI.

- **Polar does natively:** feature-flag benefits with metadata, granted with the plan and updated for every subscriber when the benefit changes. It has no quota concept and counts nothing you hold (checked on 2026-10-25).
- **The package adds:** limits carried in that metadata, a count kept in the same transaction as your write, refusals that name the plans with room, and `<Gate quota>`.

Quotas read from the same entitlement cache as [features](https://nuxt-backend.dev/docs/build/billing/subscriptions/feature-gating), so the gate in the browser and the count behind it never disagree.

A quota never resets on a billing period. An allowance per month (exports, renders, AI calls) is what [credits](https://nuxt-backend.dev/docs/build/billing/credits) and meters are for.

Plan quotas are experimental ([Stability](https://nuxt-backend.dev/docs/ship/releases/stability)): how a quota counts, and how a downgrade below what is held reads, may still change.

## Declare quotas

Name each quota once under `quotas`, with what it counts as a sentence says it, and give each plan its limits: a whole number, or `'unlimited'`. A plan that leaves a quota out allows none of it, and so does no plan at all, so a gate fails closed:

```ts [backend/billing.catalog.ts]
quotas: {
  projects: { description: 'projects' },
  sites: { description: 'sites' },
},
plans: {
  starter: { /* … */, quotas: { projects: 3 } },
  pro: { /* … */, quotas: { projects: 25, sites: 5 } },
  studio: { /* … */, quotas: { projects: 'unlimited', sites: 50 } },
},
```

The `description` is how `<Gate>` names the quota ("You have used 3 of 3 projects"), how `getFeatures` reports it, and what DevTools shows.

`npx nuxt-backend billing sync` refuses these before it writes anything:

- a quota on members, seats, users, teammates, collaborators, guests or people, whatever words about the count follow (`seat_limit`, `users_per_workspace`): a plan here is never priced per seat, and a workspace's members are never counted ([why](#why-quotas-never-count-members));
- a quota a plan sets but the catalog does not declare;
- a limit that is neither a whole number nor `'unlimited'`;
- more than 48 quotas on one plan (the provider's metadata holds 50 keys);
- a catalog key that is a plan's `<plan>-quotas`.

### What the sync writes

Each plan with quotas gets one feature-flag benefit at the provider, `<plan>-quotas`, attached to every product of the plan. Its metadata carries each quota as `quota_<key>`:

```ts
{ managedBy: 'nuxt-backend', key: 'pro-quotas', quota_projects: 25, quota_sites: 5 }
```

- **A changed limit is pushed.** Raise Pro's `projects` to 50 and sync: the benefit's metadata changes, the provider sends `benefit.updated`, and every Pro workspace's limit moves at once, with no new checkout.
- **Products that exist get it too.** A plan that gains quotas after people subscribed gets the benefit attached to its products, and the provider grants it to the people already subscribed. After that first sync, check one subscriber in DevTools (Billing → Quotas). Limits that still read 0 mean the grant has not reached the deployment yet: the scaffold's `syncEntitlements` reads it from the provider again.
- **Dropping clears the limits.** A quota a plan drops allows none from the next sync, and so does every quota of a plan that drops `quotas` altogether. Its benefit stays attached (nothing remote is deleted) with its limits cleared, and the log shows it as `drift` until you detach it in the dashboard.
- **Adopted products are left alone.** For a product you adopted (`--adopt`), the log says to attach `<plan>-quotas` in the dashboard.

A benefit you make in the dashboard can carry quotas the same way, as `quota_<key>` metadata: an add-on with `quota_projects: 100`, say. When a workspace holds several grants, its limit is the most any of them allows, never the sum.

## Count in the creating mutation

`billing.requireQuota(ctx, key, amount?)` counts `amount` (default 1) against the billing entity's quota, or refuses the call with `quota_exceeded` when it does not fit. Call it in the mutation that makes the thing, before writing it, and `billing.releaseQuota` in the one that removes it:

```ts [backend/projects.ts]
import { v } from 'convex/values'
import { billing } from './billing'
import { workspace } from './functions'

export const createProject = workspace.mutation({
  args: { name: v.string() },
  handler: async (ctx, { name }) => {
    await billing.requireQuota(ctx, 'projects')
    return ctx.db.insert('projects', { name, workspaceId: ctx.workspace.id })
  },
})

export const deleteProject = workspace.mutation({
  args: { projectId: v.id('projects') },
  handler: async (ctx, { projectId }) => {
    const project = await ctx.db.get(projectId)
    if (project?.workspaceId !== ctx.workspace.id) return
    await ctx.db.delete(projectId)
    await billing.releaseQuota(ctx, 'projects')
  },
})
```

The check, the count and your write are one transaction. A refused call counts nothing, and neither does a mutation that fails after the claim. Two calls at once never overshoot the limit: the second retries against the count the first left. That is why `requireQuota` refuses an action's or a query's context with a `TypeError`: an action's read and write could not be one transaction, and a query writes nothing. From an action, run your creating mutation.

<table>
<thead>
  <tr>
    <th>
      Call
    </th>
    
    <th>
      Does
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        billing.requireQuota(ctx, key, amount?, options?)
      </code>
    </td>
    
    <td>
      Counts <code>
        amount
      </code>
      
       and resolves with <code>
        { limit, used }
      </code>
      
      , or throws <code>
        quota_exceeded
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        billing.releaseQuota(ctx, key, amount?, options?)
      </code>
    </td>
    
    <td>
      Gives <code>
        amount
      </code>
      
       back, never below zero, and resolves with <code>
        { limit, used }
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        billing.getQuota(ctx, key, options?)
      </code>
    </td>
    
    <td>
      <code>
        { limit, used }
      </code>
      
      , in any query, mutation or action; <code>
        { limit: 0, used: 0 }
      </code>
      
       for a caller with no billing entity
    </td>
  </tr>
</tbody>
</table>

`limit` is a whole number or `'unlimited'`. Each call checks the caller first, as the feature checks do: signed in, and a member of the workspace that pays, read fresh. Pass `{ userId }` to count for an entity your server code chose itself, from a cron or a webhook handler, never an id a caller sent. An `amount` that is not a whole number above zero, or an empty key, is `invalid_input`; a key that counts people is a `TypeError`. None of them calls the provider.

### The refusal

`quota_exceeded` carries the quota, its limit, how many are used, the amount asked for, and the plans on sale that allow enough, by catalog key, in pricing order. `getBackendError(error)` returns it as:

```ts
{ code: 'quota_exceeded', data: { quota: 'projects', limit: 3, used: 3, amount: 1, plans: ['pro', 'studio'] }, message: '…' }
```

It reads the same in the browser, in production too, and the `errors` labels word it ("Your plan's limit is reached. Upgrade for more."). Hand its `plans` to `<UpgradePrompt>` the way a [`feature_required` refusal's](https://nuxt-backend.dev/docs/build/billing/subscriptions/feature-gating#offer-the-upgrade) are. [Errors](https://nuxt-backend.dev/docs/reference/backend/errors#quota_exceeded) lists its fields.

## Show it in the UI

`useFeatures()` reads every quota the catalog declares, and every one a grant names, live:

```vue [app/pages/projects.vue]
<script setup lang="ts">
const { quota, remaining } = useFeatures()
// quota('projects') → { limit: 25, used: 7 }, undefined while loading
// remaining('projects') → 18; Infinity when unlimited; 0 while loading, on a failed read, or with none left
</script>

<template>
  <p v-if="quota('projects')">{{ quota('projects')!.used }} of {{ quota('projects')!.limit }} projects</p>
  <button type="button" :aria-disabled="remaining('projects') < 1">New project</button>
</template>
```

### Gate the button on the quota

`<Gate quota="projects">` renders its content only while the plan has room for one more. Otherwise it says how many are used of how many, names the plans on sale that allow more, and links to the first on the pricing page (`/pricing?plan=pro`). A member who manages none of the workspace's billing is asked to ask an owner or admin instead. While the quotas load, and when they could not be read, it never shows the content.

```vue [app/pages/projects.vue]
<template>
  <Gate quota="projects">
    <NewProjectButton />
    <template #fallback>
      <p>Your plan is full. Archive a project, or upgrade for more.</p>
    </template>
  </Gate>
</template>
```

The default words are the [`quota` labels](https://nuxt-backend.dev/docs/build/ui/customize/labels#the-groups) ("You have used 3 of 3 projects. More on Pro or Studio."), and `#fallback` replaces them. To check room for more than one, read `remaining(key)` from `useFeatures()`. [Shell components](https://nuxt-backend.dev/docs/reference/components/shell) list every prop and slot of `<Gate>`.

## After a downgrade

A workspace that moves to a plan with a lower limit keeps everything it holds: nothing is deleted, and the count stays. `requireQuota` refuses every claim until enough is released to fit under the new limit, `remaining()` reads 0, and `<Gate quota>` says how many are used of how many. What to do with the extra (archive it, make it read-only, ask which to keep) is your app's decision; read `billing.getQuota` where you make it.

## Why quotas never count members

A workspace pays once, whoever is in it. Billing is never per seat, and a workspace's owners and admins manage its billing as [members](https://nuxt-backend.dev/docs/build/billing/setup#who-may-buy-for-a-workspace), never as seats. A quota on members, seats, users, teammates, collaborators, guests or people would sell seats under another name, so the sync and every quota check refuse one. Count what people make (projects, stories, sites) instead.

## How the count is kept

The count lives in the sharded counter component the scaffold mounts, one count per billing entity and quota, on a single shard so a check and a claim read and write the same document. It counts claims, not rows of a table: `releaseQuota` is what gives one back. Files that [checked uploads](https://nuxt-backend.dev/docs/build/data/files/checked-uploads) keep under a quota key are counted by the storage module in the same component, and every quota read adds that count to the claims: `useFeatures().quotas`, `billing.getQuota` and `requireQuota` all show one number, whoever counts. Storage registers its file and byte counts under the quota key with each file it keeps, so a key with no file kept yet reads as nothing used. An entity's first claim of a quota is noted in the backend component, so `billing.forgetEntity` clears every count it ever made, including one for a quota the catalog has since dropped. Without the counter mounted, quotas read as nothing used and counting one throws; `npx nuxt-backend upgrade` restores the mount in `backend/convex.config.ts`.

## What happens when…

<table>
<thead>
  <tr>
    <th>
      Case
    </th>
    
    <th>
      Result
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      The claim doesn't fit
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/reference/backend/errors#quota_exceeded">
        <code>
          quota_exceeded
        </code>
      </a>
      
       with <code>
        limit
      </code>
      
      , <code>
        used
      </code>
      
      , <code>
        amount
      </code>
      
       and the plans with room; nothing is counted
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        amount
      </code>
      
       is not a whole number above zero, or the key is empty
    </td>
    
    <td>
      <code>
        invalid_input
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      The key counts people
    </td>
    
    <td>
      A <code>
        TypeError
      </code>
      
      : quotas never count members
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        requireQuota
      </code>
      
       runs in an action or a query
    </td>
    
    <td>
      A <code>
        TypeError
      </code>
      
      : run your creating mutation instead
    </td>
  </tr>
  
  <tr>
    <td>
      The workspace drops below what it holds
    </td>
    
    <td>
      Every claim is refused until enough is released (<a href="#after-a-downgrade">
        After a downgrade
      </a>
      
      )
    </td>
  </tr>
</tbody>
</table>

## Limits

- **Experimental.** How a quota counts, and how a downgrade reads, may still change.
- **Held, not per period.** A quota never resets; an allowance per month is credits.
- **48 quotas per plan.** Polar's metadata holds 50 keys, and the benefit uses two.
- **The highest grant wins.** Several grants never add up.

## Test it

The count lives in your deployment, so `convex-test` proves a refusal with no provider:

```ts [backend/projects.test.ts]
import { getBackendError } from 'nuxt-backend/functions'
import { asUser, defineBackendTestApp } from 'nuxt-backend/test'
import { expect, test } from 'vitest'
import { api } from './_generated/api'
import schema from './schema'

const testApp = defineBackendTestApp(schema, import.meta.glob('./**/*.ts'))

test('a workspace with no plan allows no projects', async () => {
  const ada = await asUser(testApp())
  const refusal = await ada.mutation(api.projects.createProject, { name: 'Sunday strips' }).catch(getBackendError)
  expect(refusal).toMatchObject({ code: 'quota_exceeded', data: { quota: 'projects', limit: 0 } })
})
```

A workspace with no grant allows none, so its first claim is refused.

## Related

- [Gate features by plan](https://nuxt-backend.dev/docs/build/billing/subscriptions/feature-gating): on/off features, the same cache and the same refusals.
- [Define and sync your catalog](https://nuxt-backend.dev/docs/build/billing/catalog): every catalog field, `quotas` included.
- [Polar](https://nuxt-backend.dev/docs/services/polar): benefits and their metadata.
- [Errors](https://nuxt-backend.dev/docs/reference/backend/errors#quota_exceeded): the refusal's fields.
- [Shell components](https://nuxt-backend.dev/docs/reference/components/shell): `<Gate>` and its props.


## Sitemap

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