# Errors, retries and idempotency

Page: https://app.myclaimhouse.com/docs/errors-and-idempotency

Every error has the same shape, a stable `error` code and a request ID. Read this page before you write retry logic.

## The error shape

```json schema=error
{
  "error": "INVALID_REQUEST",
  "message": "The request is not valid.",
  "errors": [
    { "field": "limit", "code": "invalid_value", "message": "limit must be a whole number from 1 to 100." }
  ],
  "request_id": "req_..."
}
```

- `error`: a stable code. Branch on it, never on `message`.
- `message`: a plain sentence for a person.
- `errors`: every problem of a request that was not valid, so you can fix them in one go (empty for other errors). Each has a `field` (a dotted path such as `subscriber.member_id`, or `null`), a stable `code` and a `message`. A message never repeats the value you sent.
- `details`: present only when the error has facts for a program, as a flat object. For example `provider_id` on an NPI already in use, `claim_id` and `state` on a claim that cannot take the request, the figures of `PAYMENT_NOT_BALANCED`, and `bucket`, `per_second` and `burst` on a `429`. The [reference](https://app.myclaimhouse.com/docs/api.md) says what each endpoint's errors carry.
- `request_id`: also in the `x-request-id` header of every reply. Quote it to support.

The field `code` is one of `required`, `invalid_type`, `too_short`, `too_long`, `too_small`, `too_big`, `invalid_format`, `invalid_value`, `unknown_field`, `invalid_body`, `invalid`, or, for an eligibility request, one of the findings in [Eligibility](https://app.myclaimhouse.com/docs/eligibility.md).

```bash runnable status=422
curl "https://app.myclaimhouse.com/api/v1/payers?limit=500" -H "Authorization: Bearer $CLAIMHOUSE_KEY"
```

## Error codes

| Code | HTTP status | What it means |
| --- | --- | --- |
| `UNAUTHORIZED` | 401 | A valid API key is required. Send it as "Authorization: Bearer <key>". |
| `PERMISSION_DENIED` | 403 | This API key is not allowed to do that. |
| `FEATURE_NOT_ENABLED` | 403 | Practice groups are not enabled for this organization. Ask Claim House to turn them on. |
| `NOT_FOUND` | 404 | Not found. |
| `METHOD_NOT_ALLOWED` | 405 | This endpoint does not take this method. The Allow header lists the ones it takes. |
| `INVALID_REQUEST` | 422 | The request is not valid. |
| `IDEMPOTENCY_KEY_REQUIRED` | 400 | This request needs an Idempotency-Key header: a value you make up (a UUID is good), new for each new request. |
| `IDEMPOTENCY_KEY_INVALID` | 400 | The Idempotency-Key header must be 1 to 255 printable characters. |
| `IDEMPOTENCY_KEY_REUSED` | 422 | That Idempotency-Key was already used with a different request. |
| `IDEMPOTENCY_KEY_IN_USE` | 409 | A request with that Idempotency-Key is still running. Send it again with the same key after Retry-After seconds. |
| `TOO_MANY_REQUESTS` | 429 | Too many requests of this kind lately. Wait, then try again. |
| `REQUEST_TIMEOUT` | 408 | The request body stopped arriving, so the request was stopped. Send it again. |
| `PAYLOAD_TOO_LARGE` | 413 | The request body is larger than 1 MB. |
| `TIMEOUT` | 504 | The request took too long. Send it again with the same Idempotency-Key and body after Retry-After seconds: a 409 means it is still finishing (wait and send again), and any other answer is final. If this 504 comes back, find what the request made by listing with ?idempotency_key=<the key>. |
| `PAYER_REJECTED` | 422 | The payer rejected the check. The check object says what to change, and whether resending can help. |
| `PAYER_UNAVAILABLE` | 502 | The payer's system is not answering right now. Nothing needs to change: send the check again later. |
| `NETWORK_ERROR` | 502 | The check could not be completed because the payer network failed. It is not billed. Send it again later. |
| `ELIGIBILITY_UNAVAILABLE` | 503 | Eligibility checks are not available in live mode yet. Use a test key. |
| `CLAIMS_UNAVAILABLE` | 503 | Claims are not available in live mode yet. Use a test key. |
| `ATTACHMENTS_UNAVAILABLE` | 503 | Attachments are not available in live mode yet. Use a test key. |
| `ATTACHMENTS_NETWORK_ERROR` | 502 | The attachment network did not finish. The attachment is still open and nothing was lost: close it again. |
| `NPI_REGISTRY_UNAVAILABLE` | 502 | The NPI registry is not answering right now. Nothing needs to change: send the request again later. |
| `CONFLICT` | 409 | The resource is not in a state that allows this, or it changed while the request was handled. Read it, then decide whether to send the request again. |
| `NO_APPLIED_PAYMENT` | 409 | The claim has no payment applied from an ERA to carry to the next payer. |
| `NO_NEXT_PAYER` | 409 | The claim is tertiary: no payer comes after it. |
| `PAYMENT_NOT_BALANCED` | 409 | What the payer paid and its adjustments do not add up to the claim's charge. The details give the figures. |
| `DELIVERY_UNCERTAIN` | 409 | This claim's last file may already be with the payer: no acknowledgement came after it was handed to the network. Check the claim's status before you send it again; to send it anyway, repeat the request with confirm_resend set to true. |
| `NO_PAYER_ANSWER` | 409 | The payer has not answered this claim's last submission. Check its status with the payer before you send it again; to send it anyway, repeat the request with confirm_resend set to true, or void it. |
| `REGISTRATION_PENDING` | 409 | The office’s registration with the attachment network is pending: Claim House is waiting for the network and tries again on its own. Close the attachment again once the office is registered (the event office.attachment_registration.updated says when). |
| `NPI_CONFLICT` | 409 | This NPI belongs to another dentist in your organization: a provider with another last name has it. Check the NPI and the last name. |
| `STATUS_MANAGED` | 409 | Claim House moves this enrollment's status. |
| `INTERNAL` | 500 | Something went wrong on our side. Quote the request ID if you contact us. |

An eligibility check that is rejected, unavailable or failed carries the check itself next to the error. See [Eligibility](https://app.myclaimhouse.com/docs/eligibility.md).

## Which failures to retry

| What you got | What to do |
| --- | --- |
| No response (the connection dropped, your server restarted) | Send the same request with the same `Idempotency-Key`. You get the first answer, or it runs once. |
| `504 TIMEOUT` | Send the same request with the same key after `Retry-After`. See [After a timeout](#after-a-timeout). |
| `409 IDEMPOTENCY_KEY_IN_USE` | The same request is still running. Wait `Retry-After` seconds, send it again with the same key. |
| `409 CONFLICT` | The resource is not in a state that allows this (or changed meanwhile). Read it, then decide. |
| `409 NPI_CONFLICT` | The NPI belongs to a provider with another last name. Check the NPI and name. |
| `409 DELIVERY_UNCERTAIN` | The claim's last file may already be with the payer. Check its status; send it with `confirm_resend: true` only if it is not there. See [Claims](https://app.myclaimhouse.com/docs/claims.md#delivery-uncertain). |
| `409 NO_PAYER_ANSWER` | The payer never answered the claim's last submission. Check with the payer, then send it with `confirm_resend: true`, or void it. See [Claims](https://app.myclaimhouse.com/docs/claims.md#no-answer-from-the-payer). |
| `409 STATUS_MANAGED` | Claim House moves this enrollment's status. Change only its note or dates. See [Payer enrollment](https://app.myclaimhouse.com/docs/enrollment.md#who-files-it). |
| `401`, `403`, `404`, `422` | Fix the request, key or ID. Sent again unchanged, it gets the same answer. |
| `429 TOO_MANY_REQUESTS` | Nothing ran. Wait `Retry-After` seconds and send it again. |
| `502 PAYER_UNAVAILABLE`, `NETWORK_ERROR` | Nothing is billed. Send the check again later with a **new** key. |
| `500 INTERNAL` | Send it again with a **new** key. If the error carries a `check`, read it first: the check was made. |

## Idempotency

A POST or a PATCH needs an Idempotency-Key header, so a request that timed out can be repeated safely; for POST /api/v1/eligibility it is optional (recommended for retries); a search sent as a POST takes none. A request that needs one and has none is refused with `400 IDEMPOTENCY_KEY_REQUIRED`.

- An eligibility check runs without one: a repeat within 60 minutes reuses the saved answer, so it is neither asked nor billed twice. Send a key with a check you may retry after a timeout.
- A key is 1 to 255 printable ASCII characters, no spaces (a UUID is good); otherwise `400 IDEMPOTENCY_KEY_INVALID`. When the body has problems too, one `422 INVALID_REQUEST` names them all.
- **Never put patient information in a key.** Keys are stored and logged.
- The same key with the same method, path, query and body returns the stored answer with `idempotent-replayed: true`; nothing runs or is billed again. Its body's `request_id` is the first request's.
- The same key with anything different: `422 IDEMPOTENCY_KEY_REUSED`.
- While the first request runs, a repeat waits up to 10 seconds, then answers `409 IDEMPOTENCY_KEY_IN_USE` with `Retry-After`.
- Answers are kept 24 hours; after that the key starts a new request.

Once a request has started, its answer is final, **including a failure** (`500`, `502`): a retry with the same key replays it and never runs it twice. A retry after an error response is a new attempt with a new key. A request refused before it started (`401`) can be sent again with the same key. The exception is a `504`, below.

## After a timeout

A `504 TIMEOUT` (after 45 seconds) means Claim House stopped waiting, not that nothing happened. Do not wait on a clock, and do not decide from a lookup: the first attempt may still be committing, so a lookup can find nothing yet.

1. Send the same request, same key and body, after `Retry-After` (5 seconds).
2. `409 IDEMPOTENCY_KEY_IN_USE`: the first attempt is still running. Wait and send it again.
3. Any other answer is final. For [`POST /providers`](https://app.myclaimhouse.com/docs/api/createProvider.md), [`POST /eligibility`](https://app.myclaimhouse.com/docs/api/createEligibilityCheck.md), [`POST /claims`](https://app.myclaimhouse.com/docs/api/createClaim.md), [`POST /claims/{id}/next_claim`](https://app.myclaimhouse.com/docs/api/createNextClaim.md), [`POST /enrollments`](https://app.myclaimhouse.com/docs/api/createEnrollment.md), [`POST /attachments`](https://app.myclaimhouse.com/docs/api/createAttachment.md), [`POST /attachments/{id}/documents`](https://app.myclaimhouse.com/docs/api/uploadAttachmentDocument.md), [`POST /attachments/{id}/close`](https://app.myclaimhouse.com/docs/api/closeAttachment.md), the retry takes the first attempt over and answers as if it had finished: one claim, one attachment, one check, never two.
4. Any other operation answers the same `504` again. Find what it did with a lookup by key, below, or by reading the resource.

## Find a write by its key

Every list whose create takes a key finds what that key made: [`GET /offices`](https://app.myclaimhouse.com/docs/api/listOffices.md), [`GET /practice_groups`](https://app.myclaimhouse.com/docs/api/listPracticeGroups.md), [`GET /providers`](https://app.myclaimhouse.com/docs/api/listProviders.md), [`GET /eligibility`](https://app.myclaimhouse.com/docs/api/listEligibilityChecks.md), [`GET /eligibility/batches`](https://app.myclaimhouse.com/docs/api/listEligibilityBatches.md), [`GET /claims`](https://app.myclaimhouse.com/docs/api/listClaims.md), [`GET /enrollments`](https://app.myclaimhouse.com/docs/api/listEnrollments.md), [`GET /attachments`](https://app.myclaimhouse.com/docs/api/listAttachments.md), [`GET /payer_requests`](https://app.myclaimhouse.com/docs/api/listPayerRequests.md), [`GET /webhook_endpoints`](https://app.myclaimhouse.com/docs/api/listWebhookEndpoints.md). Use it for a request whose outcome you lost (a `504` that came back again, or a process that died after sending). It needs a key with `read`, so a submit-only integration keeps a read key for it.

```bash runnable status=200
curl "https://app.myclaimhouse.com/api/v1/claims?idempotency_key=my-key-1" -H "Authorization: Bearer $CLAIMHOUSE_KEY"
```

A claim, check or attachment also carries the `request_id` of the request that made it.

## Retried under a new key

A retry under a **new** key never sends anything twice:

| Request | Answer |
| --- | --- |
| [`POST /claims/{id}/submit`](https://app.myclaimhouse.com/docs/api/submitClaim.md) of a claim already queued | `200`, the claim as it is. Nothing new is queued. |
| `submit` or [`resubmit`](https://app.myclaimhouse.com/docs/api/resubmitClaim.md) of a claim already sent | `409 CONFLICT` with `details.claim_id` and `details.state`. No new file. |
| [`POST /claims`](https://app.myclaimhouse.com/docs/api/createClaim.md) with the same claim again | `201`, a new claim held in `needs_attention` with a `DUPLICATE_CLAIM` error naming the first. It is never sent. See [Duplicates](https://app.myclaimhouse.com/docs/claims.md#duplicates). |
| [`POST /attachments/{id}/close`](https://app.myclaimhouse.com/docs/api/closeAttachment.md) of a closed attachment | `200`, the attachment as it is, same number. Nothing is sent again. |

## Request size

A body over 1 MB is refused with `413 PAYLOAD_TOO_LARGE` before anything is recorded. An attachment upload has its own limit (see [Attachments](https://app.myclaimhouse.com/docs/attachments.md)); one whose body stops arriving for 15 seconds gets `408 REQUEST_TIMEOUT`.

## Rate limits

Each key, organization, payer-call stream and office has a steady rate with room for bursts. The same limits apply to the API and the MCP server. The standard figures:

| Limit | Counts | Steady rate | Burst |
| --- | --- | --- | --- |
| Per API key | Every request of the key | 20 a second | 40 |
| Per organization | Every request of all its keys of one mode (test and live each have their own) | 50 a second | 100 |
| Payer and registry calls | Eligibility checks and NPI lookups of the organization in one mode, on top of the two above | 5 a second | 50 |
| Per office | Eligibility checks of one office, on top of the three above | 5 a second | 50 |

[`GET /rate_limits`](https://app.myclaimhouse.com/docs/api/getRateLimits.md) returns your organization's own figures for each, with `custom: true` where they were raised:

```bash runnable status=200
curl "https://app.myclaimhouse.com/api/v1/rate_limits" -H "Authorization: Bearer $CLAIMHOUSE_KEY"
```

- A request over a limit gets `429 TOO_MANY_REQUESTS`, `Retry-After`, and `details` naming the `bucket` and its `per_second` and `burst`. Nothing of it runs or is billed. Through MCP, a tool call over the payer limit gets the error as its result.
- More keys do not mean more requests: the organization limit counts all its keys of a mode.
- An eligibility check takes a turn from its office (`office_id`, or your only office). A batch of checks takes the same turns and waits instead of failing.
- **Need more?** Any limit can be raised for your organization: ask us. A raised limit applies in test and live alike. An organization with many offices usually needs a higher organization and payer limit; the office limit still holds each office to its own rate.
- A key that keeps hitting a limit for 5 minutes is emailed about to your owners and admins (and Claim House), at most once every 60 minutes: usually a script or an agent stuck in a loop.
