Appearance
Idempotency
Networks fail. If a run request times out, you cannot tell whether the run started. Send an Idempotency-Key header and retry safely: the API runs the request at most once per key.
http
POST /v1/agents/invoice-extractor/runs
Authorization: Bearer hk_live_…
Idempotency-Key: invoice-8812
Content-Type: application/jsonWhere it applies
The header is honoured on exactly two endpoints, both of which start a run:
POST /v1/agents/{slug}/runs(sync, stream and async runs);POST /v1/conversations/{id}/messages(a message is a run of the conversation's agent).
Every other endpoint ignores it.
Behaviour
Keys are scoped to the project and are 1 to 200 characters (otherwise 400 VALIDATION_FAILED).
| Situation | Answer |
|---|---|
| first request with the key | the run executes normally |
the key's run finished (succeeded, failed, cancelled) | 200 with the stored RunResult; nothing runs again (see below for streams) |
the key's run is still queued, running or waiting | 409 IDEMPOTENCY_IN_PROGRESS: retry later |
| the key was used for a different agent or request body | 409 IDEMPOTENCY_KEY_REUSED |
The request is compared by a fingerprint of the agent and the body (key order does not matter; stream and async are left out, so a sync retry of a streamed request replays the same run). Derive keys from your own identifiers so they are unique per piece of work, for example invoice-${invoiceId} or a job id.
A replay is answered as JSON, except for stream: true requests: they get a short event stream with run.started, one text.delta holding the whole text (when the output is { text }) and run.completed, or run.failed for failed and cancelled runs. A replayed async request gets the finished RunResult with 200, not 202.
Keys stay attached to their run, so a key is never reusable within the project.
In the SDK
agents.run, agents.stream, agents.runAsync and conversations.send send a generated key automatically while retries are enabled, so the SDK's own retries never execute a run twice. Other POST methods are never retried. Pass your own key to make a run idempotent across processes and restarts:
ts
await hevkar.agents.run(
'invoice-extractor',
{ files: [fileId] },
{ idempotencyKey: `invoice-${invoiceId}` },
);bash
curl "$HEVKAR_BASE_URL/v1/agents/invoice-extractor/runs" \
-H "Authorization: Bearer $HEVKAR_API_KEY" \
-H "Idempotency-Key: invoice-8812" \
-H "Content-Type: application/json" \
-d '{"files": ["0b8f9a43-6f55-4a8e-8f43-0d1b1c7e2a11"], "async": true}'Other endpoints
POST /v1/conversationscreates a new conversation per call; retry it only when you know the first call failed, or keep the id you got.- File uploads are not deduplicated: a retried upload can store the file twice (the SDK never retries uploads).
DELETErequests and approvals, events and cancels are naturally safe to repeat or answer a clear404/409the second time.