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). first counts up to its maximum of 100. If you leave first out, 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:

ExampleCost
Get a job with its customer, property, products, estimates and invoices159
One customer with nested lists of jobs, estimates and invoices238
A technician's week: 50 jobs with status, customer and address951
Overdue invoices: 100 invoices with customer and job1,501
Any delete mutation15

Every successful response reports the cost in extensions.cost:

{
  "data": { "...": "..." },
  "extensions": {
    "cost": { "requested": 159, "available": 5841, "max_query_cost": 2000 }
  }
}
PropertyDescription
requestedThe cost of this request
availableThe points left in your budget for the current window
max_query_costThe maximum cost allowed for a single request

Limits

LimitValueError
Maximum cost per request2,000MAX_COST_EXCEEDED
Cost budget per user6,000 points per 60-second windowTHROTTLED
Maximum query depth7 levelsGRAPHQL_VALIDATION_FAILED
Maximum aliases per request10GRAPHQL_VALIDATION_FAILED
Maximum tokens per query3,000GRAPHQL_VALIDATION_FAILED
Maximum directives per query20GRAPHQL_VALIDATION_FAILED
Maximum records per page (first)100Larger 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_429 in user_errors when your REST rate limit is reached.

To keep costs down:

  • Select only the fields you need.
  • Keep first small on nested lists.
  • Use nodes instead of edges unless you need a cursor for each record.
  • For bulk exports, page through a top-level list with first: 100 rather than nesting large lists.

Note: When you receive THROTTLED, wait for retry_after_seconds before 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:

CodeWhen
UNAUTHENTICATEDThe API key is missing or invalid, or its user is inactive or deleted. Returned with HTTP status 401
FORBIDDENA mutation was sent with a read-only API key
BAD_USER_INPUTfirst is not a positive number, or the after cursor is invalid
GRAPHQL_VALIDATION_FAILEDThe query doesn't match the schema, or exceeds the depth, alias, token or directive limit
MAX_COST_EXCEEDEDThe request costs more than 2,000. Includes cost and max_cost
THROTTLEDYour cost budget for the current window is used up. Includes cost, available and retry_after_seconds
SERVICE_UNAVAILABLEA mutation couldn't be completed in time. Retry it later
INTERNAL_SERVER_ERRORAn unexpected error occurred

Note: Check the errors list in the response body rather than relying on the HTTP status code. Apart from UNAUTHENTICATED, 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" }
      ]
    }
  }
}
codefieldWhen
NOT_FOUND["id"]The id doesn't exist in your account
HTTP_400, HTTP_404, HTTP_409 and so onnullThe change was rejected. message explains why, and code contains the matching HTTP status
HTTP_401, HTTP_403nullYour user isn't allowed to make this change, for example a field executive updating a job they aren't assigned to
HTTP_429nullYour REST API rate limit was reached

Note: A query for a single record, such as job(id: ...), returns null when the record doesn't exist in your account. It doesn't return an error.


Did this page help you?