Skip to main content
Each program below is complete and runnable. They use small files only to show where an application-owned persistence boundary belongs; replace those with the assessment record storage you already operate. Every program needs an organization API key in ANTIGEN_API_KEY and works only with approved targets. Two ordering rules make every one of these programs recoverable: write the Run ID as soon as creation succeeds, and write an event sequence only after that event has been processed.

Create, observe, and act on a finding

Reads approved targets, creates a Run with explicit Guardrails, persists the Run ID and event checkpoint, then turns the first finding’s remediation into a next action.
The program prints progress events and either a remediation next action or a completed assessment with no findings. Both are valid outcomes. If creation fails before an ID is recorded, correct the credential, target, or request input. If the caller loses its response after an ID is recorded, start from the recovery program below rather than creating another Run.

Recover after a local interruption or timeout

Restores the saved Run and event position, reads its status, and resumes only the events that follow the saved checkpoint. Run this after any interruption of the program above.
The event stream ends when the Run reaches a terminal state, so this program needs no separate wait. Reach for run.wait only when you are not consuming events, and treat its AntigenWaitTimeoutError as a local deadline rather than a result:
Do not restart at sequence zero unless you intend to reprocess every event as new evidence.

Create and recover through the HTTP API

Use this when the application owns its own HTTP client and persistence. curl, jq, and ANTIGEN_API_KEY are the only prerequisites. Confirm the target is approved, create the Run, and save its ID: set -euo pipefail is what makes the approval check load-bearing: without it the pipeline’s exit status is discarded and the script creates the Run anyway.
Then read the durable record whenever you need it:
If a deadline or connection interruption occurs after the Run ID is saved, read GET /v1/runs/{runId} and resume events after the saved sequence. Do not resend the creation request because the caller did not receive a conclusive response.

List and read a prior assessment

runs.list reads an organization-visible page; runs.get reads a record you already saved. The continuation cursor is opaque and must be returned unchanged.

Send guidance, then choose a lifecycle action

Reads the stored Run before sending guidance inside its approved scope, then decides an action from the observed status rather than assuming one is valid.
run.stop() requests a reviewable pause, run.resume() applies only to a stopped Run, and run.cancel() is terminal. Use each one to express a decision about the assessment. A local timeout is not a lifecycle action. These programs produce technical evidence. Turning it into accountable work, and handing an assessment to another operator, is covered in Guides. Related pages: TypeScript SDK for method and option details, Guides for evidence and recovery decisions, HTTP API reference for the direct contract, and Reliability and security for credential expectations.