Budgets and headers
What a document costs, what a client may spend per hour, what every answer says about it, and what a 429 means.
A client has two budgets per hour: requests and complexity points. Every answer says where both stand. A spent budget is a 429, and the SDK waits it out on its own.
What a document costs
Cost is scored from the document before it runs, so a budget is spent in the same unit it is set in:
| Selected | Cost |
|---|---|
| A scalar or enum field | 0.1 |
| An object or node field | 1, plus what is selected inside it |
| A list field | 1, plus per element it may return: 1 and what is selected inside |
| A connection | Its first sizes the edges and nodes lists inside it |
| A list without a size | Taken as 50 |
| A union or interface | Its costliest member |
So { viewer { __typename } } is 1.1, { products { id } } is 56, and a page of 10 orders with the full record is a few hundred points. Ask for what you will use, and say first.
Budgets
| Budget | Per client, per hour |
|---|---|
| Requests | 1,500 |
| Complexity points | 250,000 |
Windows are fixed hours. Sessions from the app itself are not budgeted; the API's own pages are.
Headers on every answer
X-Complexity: 23.1
X-RateLimit-Requests-Limit: 1500
X-RateLimit-Requests-Remaining: 1487
X-RateLimit-Requests-Reset: 2140
X-RateLimit-Complexity-Limit: 250000
X-RateLimit-Complexity-Remaining: 249104
X-RateLimit-Complexity-Reset: 2140Reset is seconds until the window ends. A request that is refused still carries them.
A spent budget
HTTP/1.1 429 Too Many Requests
Retry-After: 2140{
"errors": [
{
"message": "The client's hourly budget is spent; the headers say when it refills.",
"extensions": { "code": "RATELIMITED" }
}
]
}The SDK waits as Retry-After says, a minute at most, and tries again, three times at most. After that the 429 is the answer, an AthanorApiError with code: "RATELIMITED" and status: 429. If you are not on the SDK, do the same: never retry a 429 before Retry-After.
Staying well under
- Webhooks over polling: a notice costs you nothing and arrives sooner than the next poll.
firston every connection, sized to what you render; nested lists above all.- One
DealerContextat startup, cached; it does not change. - Read the record by id after a webhook rather than re-reading the feed.
- Register your documents; a registered hash is the same cost but tells us what to expect.
See Being a good citizen.
Registered documents
A client registers the operations its build will run, by hash. On live it can accept nothing else, so a query that was never registered cannot run against you.
Being a good citizen
What a well-behaved integration does, and why each one keeps your budget, your data and our desk in good shape.