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

# Wait for background work

> Poll generation and processing jobs, retrieve their results, and handle failures.

Poll a job to check when background work is complete. A `202` response accepts
the request; it does not contain the finished result.

Notes and document content [stream by default](/developers/streaming.md). Use jobs for
`?stream=false` and the other background operations below.

## Which ID should you poll?

| Workflow | Job reference | Where to get the result |
| - | - | - |
| Consult note with `stream=false`, or custom template | `job_ids`, with `job_id` for a single/default reference | Returned `document_ids` |
| Generate document content with `stream=false` | `job_id` | The document you requested |
| Complete an audio upload | `transcription_job_id`, when returned | Session transcript |
| Ask AI | `job_id` | Session's Ask AI result endpoint |
| Clinical coding | `job_id`, when returned | Session's clinical-codes endpoint |
| Context attachment processing | Attachment status fields | Context-document list |

Keep the session/document IDs from the initiating response. The generic job
endpoint does not return note contents.

## Poll a job

`GET /jobs/{job_id}` requires `scribe:read` and the same grant that started the job.

```bash theme={null}
curl "$CORTEXA_API_BASE/jobs/$CORTEXA_JOB_ID" \
  --header "Authorization: Bearer $CORTEXA_JWT"
```

Example response:

```json theme={null}
{
  "id": "job_example",
  "job_type": "output_generation",
  "status": "succeeded",
  "failure_code": null
}
```

`job_type` describes the operation; use `status` to decide what to do next.

| Status | Your next action |
| - | - |
| `queued`, `running`, or `processing` | Continue polling until processing completes |
| `succeeded` | Retrieve the document, transcript, answer, or coding result |
| `failed` | Read `failure_code`; resolve the cause before submitting new work |
| `cancelled` | Stop polling and tell the clinician the work did not complete |

Start with a polling interval of about two seconds and increase it for longer
jobs. Honor `Retry-After` on `429`; polling shares your application's rate limit.
Keep the job ID if the clinician leaves the page.

## Handle reused output

A generation response can return ready documents without creating new work.
When `status` is `succeeded` and `job_id` is null, retrieve the supplied document
IDs rather than calling `/jobs/null`.

## Retry a request

If the initial request loses its response, resend the same request with the same
idempotency key. This recovers its original receipt. Poll the existing job after
you have the receipt.

Once a job reports failure, replaying the original key is not a new generation
request. Resolve the failure and use a new operation/key when intentionally
requesting new work. For an existing document, use its
[content-generation endpoint](/developers/documents.md#generate-or-regenerate-content).

The public API does not expose completion webhooks, a generic job cancellation
endpoint, or a job retry endpoint.


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