GraphQL Query Cost, Limits and Errors
One GraphQL request can read 5 records or 5,000, so the Zuper GraphQL API limits the cost of your queries instead of counting requests.
How cost is calculated
Cost is calculated from the query before it runs:
- Every selected field costs 1, plus the cost of its sub-fields.
- A list field costs 1 + (cost of one record ×
first).firstcounts up to its maximum of 100. If you leavefirstout, the default (25 for top-level lists, 10 for nested lists) is used. - Each mutation adds 10.
Nested lists multiply. For example, customers(first: 50) { jobs(first: 10) { ... } } costs about 50 × 10 × the cost of one job.
Costs of some examples in these guides:
| Example | Cost |
|---|---|
| Get a job with its customer, property, products, estimates and invoices | 159 |
| One customer with nested lists of jobs, estimates and invoices | 238 |
| A technician's week: 50 jobs with status, customer and address | 951 |
| Overdue invoices: 100 invoices with customer and job | 1,501 |
| Any delete mutation | 15 |
Every successful response reports the cost in extensions.cost:
{
"data": { "...": "..." },
"extensions": {
"cost": { "requested": 159, "available": 5841, "max_query_cost": 2000 }
}
}| Property | Description |
|---|---|
requested | The cost of this request |
available | The points left in your budget for the current window |
max_query_cost | The maximum cost allowed for a single request |
Limits
| Limit | Value | Error |
|---|---|---|
| Maximum cost per request | 2,000 | MAX_COST_EXCEEDED |
| Cost budget per user | 6,000 points per 60-second window | THROTTLED |
| Maximum query depth | 7 levels | GRAPHQL_VALIDATION_FAILED |
| Maximum aliases per request | 10 | GRAPHQL_VALIDATION_FAILED |
| Maximum tokens per query | 3,000 | GRAPHQL_VALIDATION_FAILED |
| Maximum directives per query | 20 | GRAPHQL_VALIDATION_FAILED |
Maximum records per page (first) | 100 | Larger values are reduced to 100 |
The cost budget:
- Each user has their own budget, shared by every API key that user owns.
- The budget resets in full when the 60-second window ends. It doesn't refill gradually.
- A mutation sent with a read-only API key is rejected before any cost is charged.
- The GraphQL budget is separate from the REST API's rate limits. Mutations call the same services as the REST API, so a mutation can also return
HTTP_429inuser_errorswhen your REST rate limit is reached.
To keep costs down:
- Select only the fields you need.
- Keep
firstsmall on nested lists. - Use
nodesinstead ofedgesunless you need a cursor for each record. - For bulk exports, page through a top-level list with
first: 100rather than nesting large lists.
Note: When you receive
THROTTLED, wait forretry_after_secondsbefore sending the next request.
Errors
GraphQL reports errors in two places.
Top-level errors are returned when the request can't run, for example a bad API key or a query that's too expensive. The error code is in errors[].extensions.code:
| Code | When |
|---|---|
UNAUTHENTICATED | The API key is missing or invalid, or its user is inactive or deleted. Returned with HTTP status 401 |
FORBIDDEN | A mutation was sent with a read-only API key |
BAD_USER_INPUT | first is not a positive number, or the after cursor is invalid |
GRAPHQL_VALIDATION_FAILED | The query doesn't match the schema, or exceeds the depth, alias, token or directive limit |
MAX_COST_EXCEEDED | The request costs more than 2,000. Includes cost and max_cost |
THROTTLED | Your cost budget for the current window is used up. Includes cost, available and retry_after_seconds |
SERVICE_UNAVAILABLE | A mutation couldn't be completed in time. Retry it later |
INTERNAL_SERVER_ERROR | An unexpected error occurred |
Note: Check the
errorslist in the response body rather than relying on the HTTP status code. Apart fromUNAUTHENTICATED, these errors can be returned with HTTP status 200.
Throttled:
{
"errors": [
{
"message": "Throttled: query cost budget exhausted for this user",
"extensions": { "code": "THROTTLED", "cost": 900, "available": 0, "retry_after_seconds": 34 }
}
]
}Over the cost limit:
{
"errors": [
{
"message": "Query cost 2603 exceeds the maximum of 2000. Reduce `first` or nesting.",
"extensions": { "code": "MAX_COST_EXCEEDED", "cost": 2603, "max_cost": 2000 }
}
]
}user_errors are returned by mutations when the request ran but the change was not made, for example because a required field is missing. The HTTP status is 200.
{
"data": {
"createJob": {
"job": null,
"user_errors": [
{ "field": null, "message": "No Category is found for given Category UID", "code": "HTTP_400" }
]
}
}
}code | field | When |
|---|---|---|
NOT_FOUND | ["id"] | The id doesn't exist in your account |
HTTP_400, HTTP_404, HTTP_409 and so on | null | The change was rejected. message explains why, and code contains the matching HTTP status |
HTTP_401, HTTP_403 | null | Your user isn't allowed to make this change, for example a field executive updating a job they aren't assigned to |
HTTP_429 | null | Your REST API rate limit was reached |
Note: A query for a single record, such as
job(id: ...), returnsnullwhen the record doesn't exist in your account. It doesn't return an error.
Updated about 21 hours ago
