Rate limits and query cost
The Admin API does not count requests. It prices each request by the work it asks for, its query cost in points, and takes those points from a bucket that refills over time.
How a request is priced
Before a request runs, the API adds up the cost of every field it selects:
| Selected field | Cost |
|---|---|
Scalar or enum (title, status) | 0 |
Object (product, featuredMedia) | 1, plus the cost of what is selected inside it |
| Interface or union | The cost of its most expensive possible type for the selection |
Connection (products(first: 10)) | 2 + page size × cost of one item |
Mutation (the root field, such as productCreate) | 10, in place of the payload object's 1, plus what is selected in the payload |
Introspection (__schema, __type, __typename) | 0 |
- A connection is a field whose type ends in
Connectionand haspageInfoandedgesornodes. One item costs 1 for the node plus what is selected in it.edges { node }andnodesreturn the same items, so when both are selected only the more expensive one counts. The edge itself,cursorandpageInfocost nothing. - The page size is the
firstorlastargument, counted in steps (below), so a page of 250 costs far less than 250 times one item. A connection with neither argument is sized 0. - A list of objects that takes
firstorlastbut is not a connection costs page size × (one object + its selections), without the connection's 2. Any other list of objects costs as one object. - Fragments are expanded, and fields skipped with
@skipor@includeare not counted.
Page size steps
A page of first: n (or last: n) counts as this many items:
first or last | Counts as |
|---|---|
| 1 to 2 | 1 |
| 3 to 4 | 2 |
| 5 to 7 | 3 |
| 8 to 12 | 4 |
| 13 to 20 | 5 |
| 21 to 33 | 6 |
| 34 to 54 | 7 |
| 55 to 88 | 8 |
| 89 to 143 | 9 |
| 144 to 232 | 10 |
| 233 or more | 11 |
Examples
| Request | Requested cost |
|---|---|
| 3 2 for the connection + 1 item × (1 for the product + 0 for its title) |
| 13 2 + a page of 250 counted as 11 × 1 |
| 26 2 + 4 × (1 for the product + the variants connection, 2 + 3 × 1) |
| 12 10 for the mutation + 1 for the product + 1 for the list of user errors |
Requested and actual cost
The requested cost is calculated from the request before it runs. The actual cost
is calculated after it runs with the same rules over what came back: a connection is sized by the items it returned,
an object that came back null costs nothing, and an interface or union costs the type that was returned.
When the actual cost is lower than the requested cost, the difference is given back to the bucket.
Single query limit
A request whose requested cost is above 1000 points is refused before it runs, and nothing is taken from the bucket. Split it into smaller requests, or ask for smaller pages.
{
"errors": [
{
"message": "Query cost is 2003, which exceeds the single query max cost limit (1000). …",
"extensions": {
"code": "MAX_COST_EXCEEDED",
"cost": 2003,
"maxCost": 1000,
"documentation": "…"
}
}
],
"extensions": { "cost": { "requestedQueryCost": 2003, "actualQueryCost": null, "throttleStatus": { … } } }
}
The bucket
Each combination of a store and a caller (an app's token, or a merchant's session) has its own bucket. It holds up to 1000 points and refills continuously at 100 points per second until it is full.
- A request needs its requested cost in the bucket. If the bucket holds less, the request is refused with
THROTTLEDand does not run. - Otherwise the requested cost is taken and the request runs.
- When it has run, the difference between the requested and the actual cost is put back.
The merchant dashboard's own sessions are priced the same way under larger limits: a bucket of 20000 points refilled at 1000 points per second, and a single query limit of 4000. Apps always get the limits above.
Reading the cost of a response
Every Admin API response carries the cost and the state of your bucket in extensions.cost:
"extensions": {
"cost": {
"requestedQueryCost": 101,
"actualQueryCost": 46,
"throttleStatus": {
"maximumAvailable": 1000,
"currentlyAvailable": 954,
"restoreRate": 100
}
}
}
requestedQueryCost- The cost calculated before the request ran.
nullwhen the document did not parse or validate. actualQueryCost- The cost of what was returned.
nullwhen the request was refused and did not run. throttleStatus.maximumAvailable- The bucket's size.
throttleStatus.currentlyAvailable- The points in the bucket after this request, rounded down.
throttleStatus.restoreRate- Points restored per second.
Throttled requests
A throttled request answers HTTP 200, like every GraphQL answer, with an error whose code is
THROTTLED:
{
"errors": [
{
"message": "Throttled",
"extensions": { "code": "THROTTLED", "retryAfterMs": 1200, "documentation": "…" }
}
],
"extensions": { "cost": { "requestedQueryCost": 220, "actualQueryCost": null, "throttleStatus": { … } } }
}
The error carries how long to wait before the bucket can cover the request: extensions.retryAfterMs
in milliseconds, and a Retry-After response header in seconds.
Staying within the limits
- Select only the fields you use, and ask for the page size you need.
- Watch
throttleStatus.currentlyAvailableand slow down before the bucket runs dry. - On
THROTTLED, wait as told above and send the same request again. - Spread large reads over several requests rather than one big one: the bucket refills while you work.
Storefront API
Query
cost and the bucket apply to the Admin API. The Storefront API does not calculate query cost and does not return
extensions.cost.