Requests, errors and limits
The conventions every endpoint follows: request format, the error shape and every error code, rate limits, and how to retry safely.
Requests#
- HTTPS only. Send
Authorization: Bearer pts_…on every request. - Read with
GETand query parameters. Change withPOSTand a JSON body, withContent-Type: application/json. - Write endpoints need a read and write key and the matching permission.
- Creating something (a validation request, a risk decision request, a discussion topic or reply, a report) returns
201 Created; other writes return200 OK. Both return the resulting object. - Dates are ISO 8601:
2026-12-31for dates,2026-11-26T10:15:00+00:00for times. Money is in pence, in GBP. - Invalid input is rejected before anything changes.
The error shape#
Every error, from every endpoint, has the same shape:
{
"error": {
"code": "validation_failed",
"message": "The request was not valid.",
"details": { "status": ["The selected status is invalid."] }
}
}
Branch on error.code (stable); show error.message to people; details appears for validation errors and lists problems per field.
Error codes#
| HTTP | Code | Meaning | What to do |
|---|---|---|---|
| 401 | missing_api_key | No Authorization header, or it is empty. | Send the key as a bearer token. |
| 401 | invalid_api_key | The key is malformed, unknown, expired or revoked. | Create a new key. Do not retry. |
| 403 | read_only_key | A read-only key tried to change something. | Use a read and write key, if the job really writes. |
| 403 | account_disabled | Your account is disabled, suspended or no longer in the organisation. | Contact your administrator. |
| 403 | api_keys_disabled | Your organisation turned API keys off. | Contact your administrator. |
| 403 | forbidden | Your role lacks the permission. The message names it. | Ask for the permission. |
| 404 | not_found | It does not exist, or it is outside your organisation or asset groups. | Check the code and your scope. |
| 405 | method_not_allowed | Wrong HTTP method for the path. | Check the reference. |
| 422 | validation_failed | A parameter or field is invalid; see details. Some business rules are also reported this way, with a message that explains them. | Fix the input. Do not retry unchanged. |
| 429 | rate_limited | More than 60 requests in a minute with this key. | Wait for Retry-After seconds, then retry. |
| 502 | upstream_error | The service could not complete the request. | Retry with back-off. |
| 503 | upstream_unavailable, identity_unavailable | A temporary problem. | Retry with back-off. |
Rate limits#
Each API key may make 60 requests per minute. MCP tool calls have their own, separate limit. Responses carry the standard headers:
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 57
When you exceed the limit you get 429 rate_limited with a Retry-After header in seconds. Tips:
- Use
per_page=100for exports rather than many small pages. - Run jobs sequentially rather than in parallel with the same key.
- Cache slowly-changing data (roles, asset groups) for a few minutes.
Retrying safely#
| Response | Retry? |
|---|---|
| 429 | Yes, after Retry-After. |
| 502, 503, network errors, timeouts | Yes, with exponential back-off (1 s, 2 s, 4 s, 8 s…) and a limit. |
| 400, 401, 403, 404, 405, 422 | No. Fix the request, key or permission. |
Updates such as setting an owner or a status can be repeated safely: sending the same values twice leaves the same result. Creating requests (validation, risk decisions, topics, reports) creates a new item each time, so check before retrying a POST that may have succeeded.
import time, requests
def call(session, method, url, **kw):
for attempt in range(5):
r = session.request(method, url, timeout=30, **kw)
if r.status_code == 429:
time.sleep(int(r.headers.get("Retry-After", "5")))
continue
if r.status_code in (502, 503):
time.sleep(2 ** attempt)
continue
if r.status_code >= 400:
err = r.json()["error"]
raise RuntimeError(f'{r.status_code} {err["code"]}: {err["message"]}')
return r.json()
raise RuntimeError("Pentesys API unavailable after retries")