> ## Documentation Index
> Fetch the complete documentation index at: /developers/llms.txt
> Use this file to discover all available pages before exploring further.

# Errors, limits, and retries

> Handle API errors, retry requests, and work within rate limits.

Request errors return a `message` and an `errors` array. Use the error code to
choose a recovery action.

## Read an error

Example authentication error:

```json theme={null}
{
  "message": "Access token is invalid or expired",
  "errors": [{"code":"INVALID_ACCESS_TOKEN"}]
}
```

Save `X-Cortexa-Request-Id` from the response headers for support.

| HTTP status | Typical cause | Next action |
| - | - | - |
| 400 | Invalid application or callback | Correct the authorization request |
| 401 | Invalid API key, JWT, or grant | Check credential type/environment; renew the JWT or obtain authorization again |
| 403 | Missing scope, entitlement, or workspace access | Check application/grant scopes and clinician permissions |
| 404 | Resource not available to this grant | Check the returned ID, grant mapping, and deletion status |
| 409 | Version conflict, inconsistent replay, identity/link conflict, or missing prerequisite | Read the error code and resolve the specific conflict |
| 413 | Audio or context file too large | Reduce the chunk/request size |
| 422 | Invalid fields or a workflow requirement | Inspect field details and correct the request |
| 429 | Application request allowance reached | Honor the `Retry-After` header |
| 502 | Audio, storage, or another upstream operation failed | Resolve the upstream failure and retry the same operation as appropriate |
| 503 | API configuration, accounting, or a required dependency unavailable | Retry later with backoff; contact Cortexa if persistent |

Unknown request fields return a validation error. Check the API reference for
accepted fields.

## Common error codes

| Code or situation | Explanation |
| - | - |
| `INVALID_API_KEY` | `/jwt` did not receive valid application credentials |
| `INVALID_ACCESS_TOKEN` | A valid Partner JWT is required for the clinical request |
| `INVALID_GRANT` | The grant is unavailable, revoked, or belongs to another application |
| `INSUFFICIENT_SCOPE` | The token lacks the operation's required scope |
| `RESOURCE_NOT_FOUND` | The resource is absent, deleted, or outside this grant |
| `TRANSCRIPT_NOT_FOUND` | A session transcript is not available yet |
| `CONSULT_NOTE_REQUIRED` | Complete a consult note before editing the latest note or requesting E/M |
| `SEGMENT_CONFLICT` | An audio index was reused with different bytes or duration |
| `RECORDING_FINISHED` | New chunks cannot be added to a finished recording |
| `PATIENT_LINK_MISMATCH` | The session is not linked to the patient in the unlink request |
| `409` while editing a document | Fetch the current document and resolve its version conflict |

A `202` response accepts the request. Check the [job](/developers/jobs.md) for its final status
and `failure_code`.

## Failures during streaming

Before streaming starts, errors use HTTP status and JSON. During the stream,
`output.failed` or `generation.failed` carries the failure code. Wait for
`output.ready` before treating a document as complete. See [Streaming](/developers/streaming.md)
for reconnects.

## Request limits

The default application allowance is 120 authenticated requests per minute.
Cortexa can assign a different limit. All grants under an application share the
allowance, including token exchange and polling. On `429`, wait for `Retry-After`
and reduce request frequency.

Plan entitlements and generation quotas apply separately.

## Retry a request

| Operation | Replay identifier |
| - | - |
| Create patient/session | Stable external ID within the grant |
| Append transcript, create/complete upload, start segmented recording | `Idempotency-Key` |
| Generate note, create document, generate content/custom response, Ask AI, explicit coding run, context upload | `Idempotency-Key` |
| Upload an audio segment | Recording ID + index, with identical bytes and duration |
| Finish segmented recording | Same recording ID |
| Edit document | Current `base_version`; resolve conflicts before retrying changed text |

After a lost response, reuse the same `Idempotency-Key` and unchanged body.
Keys are scoped to the grant and operation and kept for seven days.

Use a new key for new work, including a fresh attempt after resolving a failed
job. Replaying a failed request returns its original result. See [Jobs](/developers/jobs.md).

## Pagination

Most list endpoints accept `page` (starting at 1) and `per_page` (1–100).
They return this shape:

```json theme={null}
{
  "items": [],
  "page": 1,
  "per_page": 20,
  "total": 0,
  "has_next": false
}
```

Increment `page` while `has_next` is true. The workspace list `GET /teams` is an
array rather than a paginated object. See [Workspace directory](/developers/workspace-directory.md).

## Support diagnostics

Send the operation, HTTP status, error code, and `X-Cortexa-Request-Id` to your
integration contact. Keep credentials and clinical data out of logs and
idempotency keys.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.