For the complete documentation index, see llms.txt. This page is also available as Markdown.

Handling 429s

A refusal tells you which budget ran out and exactly how long to wait.

Check your headers

Every charged response reports the budget it drew on. Add -i to any request to see them:

curl -si 'https://api.durohub.com/graphql' \
  -H 'x-api-key: YOUR_API_KEY' \
  -H 'x-organization: @your-org' \
  -H 'Content-Type: application/json' \
  -d '{"query": "query { libraries { id name slug } }"}' \
  | grep -i '^ratelimit'

On a Standard plan, with a full bucket:

ratelimit-policy: "default-read";q=600;w=60
ratelimit: "default-read";r=599;t=1

libraries is one default-read operation. You had 600 tokens per 60 seconds, one is spent, and the bucket will be full again within a second. See Every response tells you where you stand for each field.

The refusal

When an operation's budget is empty, the API answers 429 Too Many Requests before running anything:

HTTP/1.1 429 Too Many Requests
Content-Type: application/json
Retry-After: 2
RateLimit-Policy: "bulk-write";q=20;w=60
RateLimit: "bulk-write";r=0;t=59
Field
Meaning

extensions.code

Always RATE_LIMITED. Branch on this, not on message

extensions.budget

The budget that ran out, as named in the Budget Reference

extensions.retryAfter

Seconds until this request would be accepted: a whole number, at least 1

Retry-After header

The same value as extensions.retryAfter

RateLimit-Policy, RateLimit

The refused budget's size, what is left, and t, the seconds until it is completely full again

Wait for retryAfter, not t. t is how long until the whole bucket refills; retryAfter is how long until there is room for this request, which is usually much sooner. If more than one budget refused, budget and retryAfter name the one with the longest wait.

Nothing in a refused request ran, so it is always safe to send again unchanged, mutations included.

RATE_LIMITED is the GraphQL API's refusal. The account APIs under /auth/* use a different code, AUTH_RATE_LIMITED, in their own flat error body. See Sign-in is limited differently.

Retry with Retry-After

This helper sends a GraphQL request and, on a 429, waits the time the API asks for plus a little random jitter, then tries again, up to a fixed number of attempts. Jitter keeps several workers that were refused together from all retrying in the same instant.

Use it like any other request:

maxWaitSeconds matters for the hourly budgets (import-start, export-start, ai, invite, api-keys): a refusal there can ask you to wait many minutes. A long-running job may be happy to sleep through it; an interactive tool should stop and tell the user when to try again.

When waiting won't help

Two budgets mean something other than "slow down":

  • invalid-credential — the API key or bearer token on the request is expired, revoked or not valid. Requests carrying it are counted per IP address until the client signs in again or switches to a valid key.

  • ip-backstop — the request carried no valid credential, and its IP address has sent a great many such requests.

Fix the credential; retrying the same request will keep failing. The helper above stops immediately on both.

Pace yourself with the headers

An integration that watches RateLimit can slow down before it is ever refused. This version spaces requests out to the bucket's refill rate once fewer than a tenth of the tokens are left:

Call paceAfter(response) after each request in a loop. On a Standard default-read budget (q=600;w=60) the refill interval is 100 ms, so a sync that runs low settles at ten operations a second instead of hitting the wall. Keep the retry helper as well: pacing makes a 429 rare, not impossible.

The headers describe whichever budget the request touched that is closest to running out, so pacing on them protects the budget that matters.

Use less of your budget

The limits are sized so that an integration doing these things has room to spare on any plan.

Use the bulk operations. Each call is charged once, whatever its size. One component.bulkUpdate updating fifty components costs one bulk-write token; fifty component.update calls cost fifty default-write tokens.

The same goes for change orders: add every item in one changeOrders.addItems call (up to 1,000 items) rather than one call per item.

Use the combined operations. A write that bundles several edits is charged once too. One vendorSourcing.saveLibraryVendor call that updates a vendor's profile, account details and approval status costs one default-write token; updateVendor, updateLibraryVendor and changeVendorApprovalStatus in turn cost three.

Subscribe instead of polling. Webhooks tell you when a component or change order is created, updated or deleted. Polling for the same news spends default-read or search tokens on every check, most of them to learn that nothing changed.

Poll jobs gently. Imports and exports report progress through componentImport.jobStatus and exportJob.findOne, which share the job-status budget (60 a minute on Standard). Checking every few seconds is plenty.

Cache what rarely changes. Libraries, categories, statuses and configuration change far less often than components. Read them once per run, not once per item.

Give each integration its own identity. An API key's budget belongs to the user who created it, for the library it is scoped to. Two keys created by the same user for the same library share one budget, so a nightly sync and a dashboard on such keys slow each other down. Integrations that should never compete for a budget belong under different users or in different libraries. A key never shares organization budgets with its owner's web session, so your sync won't slow you down in the app.

Paginate instead of re-searching. component.findAll and the other searches draw on search, a smaller budget than default-read. Walk the pages of one search with pagination: { first, after } rather than starting new searches, and look up a known part directly with component.findByCpn or component.findOne, which use default-read.

Next steps

Last updated

Was this helpful?