---
title: "Keep models under their limits"
description: "How a job's model calls stay under each provider's rate limit: a per-model limit that halves on a 429 and grows back after clean calls, retries that honor Retry-After, and which errors fail a job instead."
canonical_url: "https://nuxt-backend.dev/docs/build/ai/jobs/model-limits"
---
# Keep models under their limits

> How a job's model calls stay under each provider's rate limit: a per-model limit that halves on a 429 and grows back after clean calls, retries that honor Retry-After, and which errors fail a job instead.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: concept · 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.

- **You get:** jobs that slow down when a provider throttles them, instead of failing.
- **Powered by:** Convex's rate limiter component, and the `429` and `Retry-After` answers the gateway passes on.
- **The package adds:** a token bucket per model that halves on a `429` and grows back after clean calls, retries with backoff and jitter, and error classification inside the step.

Every model has a rate limit at its provider, and a gateway reports none of it in advance. The only signal is a `429` once the limit is passed. So the job queue learns each model's limit from those answers. It halves a model's rate the moment one comes back, then earns the rate back one call per minute while calls succeed. A job whose call was throttled waits and tries again, so a burst of `429`s slows jobs down before it fails any. Metered actions and streams make one call each and are not throttled this way: this is the queue's.

## The limit per model

Each model a step names gets a token bucket, counted in calls per minute, on Convex's rate limiter component. A step takes a turn from its model's bucket before your handler runs. When the bucket is empty, the step returns at once with the time the next turn frees up, and `job.run` schedules it again for then: no action sleeps while it waits.

The bucket's rate adapts. The pattern is additive increase, multiplicative decrease, the one TCP uses for congestion control:

<table>
<thead>
  <tr>
    <th>
      What happens
    </th>
    
    <th>
      What the rate does
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      A call comes back <code>
        429
      </code>
    </td>
    
    <td>
      Halves at once, never below <code>
        min
      </code>
      
      , and at most once a minute: a burst of <code>
        429
      </code>
      
      s from jobs running together halves it once
    </td>
  </tr>
  
  <tr>
    <td>
      Five calls in a row succeed, a minute or more after the last <code>
        429
      </code>
    </td>
    
    <td>
      Grows by one call a minute, never above <code>
        max
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Any other error
    </td>
    
    <td>
      Stays, and the run of clean calls starts over
    </td>
  </tr>
</tbody>
</table>

The burst a bucket allows is a third of a minute's rate, one call at least. Set where each model starts on `defineJobQueue`:

```ts [backend/jobs.ts]
export const jobs = defineJobQueue(components, {
  ai,
  models: {
    'google/gemini-3.1-flash-image-preview': { perMinute: 6, min: 1, max: 30 },
    'anthropic/claude-sonnet-4.5': { perMinute: 20, min: 2, max: 60 },
  },
})
```

A model you do not list starts at 6 calls a minute, between 1 and 30. The rate the queue has learned is kept, so a deploy does not start it over, and the admin console can retune it by hand ([Operate the queue](https://nuxt-backend.dev/docs/build/ai/jobs/operate)). A step without `model` runs without a bucket.

## Retries

`job.run` tries a step up to 4 times, a throttled attempt included, so a model that answers `429` four times in a row fails the job. A step that found no free turn never ran, and does not count. Between attempts it waits:

1. The time the provider asked for, when its answer carries `Retry-After`. The Convex AI Gateway documents forwarding it on chat completions (checked on 2026-10-27), and the Vercel AI Gateway sends `retry-after` on some `429`s. A wait longer than 5 minutes counts as 5.
2. Otherwise 5 seconds, doubled on each attempt.
3. Plus up to 2 seconds of jitter, the same for the same job and step, so jobs throttled together do not retry together.

The wait is a scheduled step, and it extends the job's lease, so the queue never mistakes a waiting job for a stalled one.

## Which errors fail a job

The step classifies its own error, inside the action, where the error object, its status code and its headers still exist. It hands `job.run` the outcome as data, never the error's message:

<table>
<thead>
  <tr>
    <th>
      The step's error
    </th>
    
    <th>
      What <code>
        job.run
      </code>
      
       does
    </th>
    
    <th>
      If it fails the job
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        429
      </code>
      
      , or the gateway's rate-limit error
    </td>
    
    <td>
      Halves the model's rate, waits, tries again
    </td>
    
    <td>
      <code>
        unavailable
      </code>
      
      , reason <code>
        provider_refused
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      A timeout (the step's own <code>
        timeout
      </code>
      
       included), or an error the provider marks retryable (a <code>
        502
      </code>
      
      , a <code>
        503
      </code>
      
      )
    </td>
    
    <td>
      Waits, tries again
    </td>
    
    <td>
      <code>
        unavailable
      </code>
      
      , reason <code>
        provider_refused
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      An error your step throws with <code>
        retryable(message)
      </code>
    </td>
    
    <td>
      Waits, tries again
    </td>
    
    <td>
      <code>
        unavailable
      </code>
      
      , reason <code>
        provider_refused
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      The model refuses the content: a <code>
        content-filter
      </code>
      
       finish, a content policy (<code>
        content_policy_violation
      </code>
      
      ), an image model's <code>
        moderation_blocked
      </code>
      
       or a request "rejected by the safety system", or an image model that answers with no image and says no other try would draw one, or gives a finish reason for safety (such as Google's <code>
        IMAGE_SAFETY
      </code>
      
       or <code>
        PROHIBITED_CONTENT
      </code>
      
      )
    </td>
    
    <td>
      Fails the job at once
    </td>
    
    <td>
      <code>
        invalid_input
      </code>
      
      , reason <code>
        content_blocked
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      An image call that got no image back (the AI SDK's <code>
        NoImageGeneratedError
      </code>
      
      ) and says nothing more
    </td>
    
    <td>
      Waits, tries once more, not three more times: each try bills the prompt again
    </td>
    
    <td>
      <code>
        unavailable
      </code>
      
      , reason <code>
        provider_refused
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      A catalog error your step throws (<code>
        backendError(...)
      </code>
      
      )
    </td>
    
    <td>
      Fails the job at once
    </td>
    
    <td>
      That error, as it is
    </td>
  </tr>
  
  <tr>
    <td>
      Anything else
    </td>
    
    <td>
      Fails the job at once
    </td>
    
    <td>
      <code>
        unavailable
      </code>
      
      , reason <code>
        job_failed
      </code>
    </td>
  </tr>
</tbody>
</table>

A failed job gets its credits back ([Charge for a queued job](https://nuxt-backend.dev/docs/build/ai/jobs/credits)). The person sees the catalog error's message in their language. The provider's own error goes to your logs with the job's id, and never to the page.

## What this means for you

- **List the models your steps use, with a rate you know is safe.** The queue only lowers a rate on a `429`, so a start far above the provider's limit costs a few failed calls before it settles.
- **A slot in the queue is not a turn at the model.** Every running job shares each model's bucket, whatever its tier, so dedicated slots ([Keep slots for paid plans](https://nuxt-backend.dev/docs/build/ai/jobs/priority#keep-slots-for-paid-plans)) guarantee a running place, not calls. Route a paid kind to a model of its own when it must not share.
- **Make each step one model call.** A retry repeats the whole step, so two calls in one step pay for the first one twice when the second is throttled.
- **Throw a catalog error for what a retry cannot fix**, such as an input your step rejects. The queue fails the job at once instead of trying three more times.
- **Throw retryable(message) for what another attempt may fix**, such as a model you know answers with no image now and then. Import it from `nuxt-backend/ai`: the queue waits and runs the step again, up to 4 attempts, as for a provider's passing error, whatever the call's answer was. An empty answer the step lets through gets one more attempt only.
- **A call the deadline cuts may still be billed.** The step's `timeout` aborts the call on your side; the provider may finish the work and charge for it. Such a call reports no cost, so neither the Costs tab nor `spendLimit` counts it. Give a step a `timeout` that its slowest call fits.
- **Watch the Queue tab after a launch.** A model whose rate keeps sitting at `min` is under-provisioned at its provider: ask for a higher limit, or move the step to another model.

## Related

- [AI gateway](https://nuxt-backend.dev/docs/services/ai-gateway): the route the calls take, and its own limits.
- [Run generation jobs](https://nuxt-backend.dev/docs/build/ai/jobs): `job.run` and `jobs.step`.
- [Operate the queue](https://nuxt-backend.dev/docs/build/ai/jobs/operate): see each model's rate and retune it.
- [Choose a model](https://nuxt-backend.dev/docs/build/ai/models): the route every call takes, and the gateway's own spending cap.


## Sitemap

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