> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.tradeguardins.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.tradeguardins.com/_mcp/server.

# Errors & rate limits

## Rate limits

| Setting        | Value                                                                                                                                                         |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Limit**      | 100 requests per credential (API key). The TradeGuard web dashboard gets 600 requests per dashboard session, because one dashboard page makes many API calls. |
| **Window**     | Sliding 60 seconds                                                                                                                                            |
| **Applies to** | Every authenticated `/v1` request. `GET /health` is not limited.                                                                                              |
| **Keyed by**   | Credential: each API key, and each dashboard session, has its own budget. Two keys of the same organization do not share one.                                 |

The window slides: a request "uses up" a slot for exactly 60 seconds after it was made. A request rejected with `429` does **not** use a slot, so waiting for `Retry-After` frees a slot for you. If you send several requests in parallel with the same key, another of your own requests can take that slot first; in that case you get a fresh `429` with a new `Retry-After`, so keep retrying after each one.

### Headers

Every `/v1` response carries these headers, including successful ones:

| Header                  | Meaning                                                                                                                         |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `X-RateLimit-Limit`     | Requests allowed per window (`100`).                                                                                            |
| `X-RateLimit-Remaining` | Requests left in the current window.                                                                                            |
| `X-RateLimit-Reset`     | Unix time in seconds when the oldest request in your window expires, which is when at least one more request becomes available. |

When you go over the limit you get a `429` response. It carries the same three headers plus `Retry-After`, the number of seconds to wait:

```http
HTTP/1.1 429 Too Many Requests
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1790000012
Retry-After: 12
Content-Type: application/json

{
  "error": "Rate limit exceeded: 100 requests per 60s. Retry after the number of seconds in the Retry-After header.",
  "code": "rate_limited",
  "requestId": "3f1d2c9e-…"
}
```

**Recommended client behaviour:** on a `429`, sleep for `Retry-After` seconds and retry. Before a burst, check `X-RateLimit-Remaining`.

> **Note**
>
> Requests without a valid credential are rejected with `401` before the limiter runs, so a `401` never carries rate-limit headers. Repeated invalid API keys from the same IP address (more than 30 in 60 seconds) get `429` with `code: "rate_limited"` and a `Retry-After` header until the window clears; requests with a valid key are not affected by this. If TradeGuard's rate-limit store is briefly unavailable, requests are allowed rather than failed, and those responses carry no rate-limit headers.

### Other 429s

One document endpoint has its own limits, separate from the request limit. They apply only to `POST /v1/subcontractors/{id}/documents/{documentId}/extract`, which re-runs document extraction:

| `code`                       | When                                                              |
| ---------------------------- | ----------------------------------------------------------------- |
| `reextraction_limit_reached` | More than 10 re-extractions of the same document within 24 hours. |
| `llm_budget_exhausted`       | Your organization's daily extraction budget is used up.           |

Neither sends `Retry-After`. Retrying immediately will fail the same way.

## Errors

Every error response, at every status, has this body:

```json
{
  "error": "Subcontractor not found: 7f3c1b52-…",
  "code": "not_found",
  "requestId": "3f1d2c9e-…"
}
```

| Field       | Meaning                                                                                                     |
| ----------- | ----------------------------------------------------------------------------------------------------------- |
| `error`     | A human-readable message. Show it to people or log it. Its wording may change, so don't parse it.           |
| `code`      | A stable, machine-readable code. **Branch on this.**                                                        |
| `requestId` | The same value as the `x-request-id` response header. Include it when you contact support.                  |
| `details`   | Present on `validation_failed` (and some `409`s): a list of `{ "path", "message" }`, one per invalid field. |

### Codes

| Status | `code`                                               | Meaning                                                                                                                                                                                                                                                                                                                          | Retry?                                                                                                           |
| ------ | ---------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| 400    | `validation_failed`                                  | A field in the body, form upload or query is missing, invalid or not recognized. `details` names each field. A common cause: date filters need a full UTC date-time such as `2026-12-01T00:00:00Z`, so a bare `2026-12-01` is rejected. This includes an upload's `file` (missing, empty, or an unsupported or mismatched type). | No, fix the request.                                                                                             |
| 400    | `invalid_identifier`                                 | An id in the path or query is not a valid UUID.                                                                                                                                                                                                                                                                                  | No                                                                                                               |
| 400    | `bad_request`                                        | The request can't be read or can't be carried out as sent, e.g. an unparseable JSON body, a `sourceUrl` that can't be downloaded, or a precondition that isn't met (such as attaching a profile to an inactive subcontractor).                                                                                                   | No                                                                                                               |
| 401    | `unauthenticated`                                    | Missing, malformed, expired or revoked credential.                                                                                                                                                                                                                                                                               | No, fix the credential.                                                                                          |
| 403    | `forbidden`                                          | The credential is valid but lacks the scope or role for this action.                                                                                                                                                                                                                                                             | No                                                                                                               |
| 404    | `not_found`                                          | The resource doesn't exist, or doesn't belong to your organization. The API never reveals whether another organization's resource exists. `Organization not found in this environment` usually means an organization ID from the other environment: the sandbox has its own ID, which `GET /v1/organizations` returns.           | No                                                                                                               |
| 405    | `method_not_allowed`                                 | The path exists but not for this HTTP method, e.g. `PUT` on a subcontractor (use `PATCH`). The `Allow` header lists the methods it supports.                                                                                                                                                                                     | No, use an allowed method.                                                                                       |
| 409    | `conflict`                                           | Conflicts with current state, e.g. an upload of the same document that is still in progress, or a report already in flight. Creating a subcontractor whose email or phone matches one you already have returns this too, with the subcontractor's id in `details` (path `subcontractorId`) and the field that matched.           | After the state changes                                                                                          |
| 409    | `assignment_exists`                                  | The subcontractor already has a live assignment on this project. The existing assignment's id is in `details` (path `assignmentId`).                                                                                                                                                                                             | No                                                                                                               |
| 409    | `project_not_ready`                                  | The project's setup is not Ready (a COI-required project needs its project number), so it cannot take assignments yet.                                                                                                                                                                                                           | After setup is completed in the dashboard                                                                        |
| 409    | `subcontractor_match`                                | A new subcontractor's email or phone matches one already on TradeGuard, so nothing was created or linked. The message names it, and its id is in `details` (path `existingSubcontractorId`).                                                                                                                                     | Yes: resend with that `existingSubcontractorId` to add it, or with `createNew: true` if it's a different company |
| 410    | `portal_link_expired`                                | A sub portal link is past its expiry date (sub portal only).                                                                                                                                                                                                                                                                     | Yes: ask for a fresh link with `POST /portal/link-requests`, or for an upload link, ask the company that sent it |
| 410    | `portal_link_used`                                   | A sub portal link already opened the portal on another device (sub portal only).                                                                                                                                                                                                                                                 | Yes: ask for a fresh link with `POST /portal/link-requests`                                                      |
| 409    | `project_document`                                   | The action applies to baseline documents, and this document is a project certificate filed to a project slot.                                                                                                                                                                                                                    | No                                                                                                               |
| 410    | `gone`                                               | The resource existed but has expired, e.g. an invite link.                                                                                                                                                                                                                                                                       | No                                                                                                               |
| 413    | `payload_too_large`                                  | The uploaded file is over the size limit.                                                                                                                                                                                                                                                                                        | No                                                                                                               |
| 422    | `unprocessable`                                      | Well-formed but rejected by a business rule, e.g. an upload rejected as malware (the EICAR test file), an invalid EIN or an invalid license set. For a subcontractor's EIN and licenses, `details` names the field (`ein`, `licenses`, or `licenses.0.licenseNumber`).                                                           | No                                                                                                               |
| 429    | `rate_limited`                                       | Over the request rate limit.                                                                                                                                                                                                                                                                                                     | Yes, after `Retry-After`.                                                                                        |
| 429    | `reextraction_limit_reached`, `llm_budget_exhausted` | Extraction limits (see above).                                                                                                                                                                                                                                                                                                   | Later                                                                                                            |
| 500    | `internal_error`                                     | Unexpected server error. It has been reported to us.                                                                                                                                                                                                                                                                             | Yes, with backoff, for idempotent requests.                                                                      |
| 502    | `bad_gateway`                                        | An upstream provider, e.g. an email or document service, rejected the request. Nothing was sent.                                                                                                                                                                                                                                 | Yes, with backoff.                                                                                               |
| 503    | `service_unavailable`                                | A dependency (email, document storage, workflows) is temporarily unavailable, or the request collided with a concurrent update. Honors `Retry-After`.                                                                                                                                                                            | Yes, with backoff.                                                                                               |
| 503    | `sandbox_unavailable`                                | A sandbox key (or sandbox mode) was used against a deployment where the sandbox is not provisioned.                                                                                                                                                                                                                              | No — contact support.                                                                                            |

> **Tip**
>
> New codes may be added over time. Treat an unknown `code` according to its HTTP status: 4xx means fix the request, 5xx means retry with backoff.

### Unknown fields

Request bodies and the `GET /v1/subcontractors` query are checked strictly: a field the endpoint doesn't accept is rejected with `400 validation_failed`, and `details` names it (`"message": "Unknown field \"favoriteColor\""`). A misspelled field fails loudly instead of being ignored. Read-only fields such as an organization's `slug` are rejected the same way on `PATCH`.

### Requests blocked before they reach the API

TradeGuard's hosting provider runs a web application firewall in front of the API. A request that looks like an attack, for example a value containing SQL such as `'); DROP TABLE …` or a file name containing `../`, can be blocked there. That response does **not** follow the error format above: it is a `403` with an HTML page (`Content-Type: text/html`), no `code` and no `requestId`.

Treat any error response whose `Content-Type` isn't `application/json` as this case: don't retry it unchanged, and check the request for SQL-like text or path segments. Ordinary names with apostrophes, ampersands or dashes (`O'Brien's Plumbing`, `Smith & Sons`) are not blocked. If a legitimate request is blocked, contact support with the time of the request and the `cf-ray` response header.

### Sandbox and production

Errors and limits behave identically in the sandbox, and a sandbox key has its own rate-limit budget. Two errors are sandbox-specific: `403 forbidden` when a production key calls a `/v1/sandbox/*` helper, and `503 sandbox_unavailable` if a sandbox key is used where the sandbox is not provisioned.