Edits and retries

Reference

Edits and retries

Use ETags and If-Match to protect edits, and Idempotency-Key to recover writes after a lost response.

Read the current resource before editing it. Keep its ETag and choose an Idempotency-Key for each intended change. All writes need campaign:write, both read scopes and current paid editing access through an API key.

ETags and If-Match

Single campaign, entity, session, document, world context and Journal reads include an ETag. It is bound to the campaign, key, public or private audience, resource path and returned representation. Use the same key for the read and edit.

Every PATCH or PUT needs one exact quoted ETag in If-Match. Use the matching metadata GET for detail edits, the private format=blocks GET for document edits, and the whole Journal GET for quest or thread edits. A Markdown or text document ETag cannot protect a blocks edit. POST creation, transcript imports and processing retries do not require If-Match.

Missing revisions return 428; malformed, wildcard or multiple values return 400; a changed resource returns 412. After 412, read again and reconcile your edit with the current content before sending a new command. Do not refresh the ETag and blindly resend an overwrite. The commit checks the live revision too. A write acknowledgement's revision or canonical_hash is not an ETag.

Example read header
ETag: "s20v2_2fd4e1c67a2d28fced849ee1bb76e7391b93eb12a4414f28b6e5778c79b8a108"
Read before editing
curl -i "https://app.saga20.com/api/public/v2/sessions/7b1e3f0a-52c4-4d1e-9a2b-3c8f6d1a9e41" \
  -H "Authorization: Bearer $SAGA20_API_KEY"

Idempotency-Key and retries

Every POST, PUT and PATCH needs an Idempotency-Key of 8 to 128 characters. Start with a letter or digit; the remaining characters may be letters, digits, dots, underscores, colons or hyphens. Choose a new value for each intended edit or creation.

Saga20 retains successful commit receipts for 24 hours. With the same API key, retry the same method, resource path, request content and original If-Match when supplied. JSON object field order does not matter; values and array order do. An identical retry returns the original acknowledgement with meta.replayed: true and Idempotency-Replayed: true, without applying the edit again or requiring the old ETag to match current content. Entity and text-session creation replays return 201; transcript imports and processing retries return 202.

For a multipart transcript import, identity uses the parsed metadata and transcript rather than the multipart boundary, filename or file media type.

Reusing the value for a different request returns 409 with idempotency_mismatch. Replays still check current key access, ownership, scopes, paid editing access and budgets. Rotation or revocation removes the key's receipts. After retention ends, the request is a new command; check the resource before retrying an old creation.

For a lost response or 503 with commit_unavailable, retry the identical request with its original key and If-Match, after Retry-After when supplied. In the example, SAGA20_ETAG contains the exact quoted ETag copied from the preceding session read. Keep the command key below for retries of this request only.

Edit or retry the same command
curl -X PATCH "https://app.saga20.com/api/public/v2/sessions/7b1e3f0a-52c4-4d1e-9a2b-3c8f6d1a9e41" \
  -H "Authorization: Bearer $SAGA20_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $SAGA20_ETAG" \
  -H "Idempotency-Key: greywatch-session-date-20261001" \
  --data '{"title":"The Broken Gate","recorded_at":"2026-09-24T19:00:00.000Z"}'

Request bodies

Writes accept UTF-8 JSON objects with Content-Type: application/json. Transcript imports also accept multipart/form-data with exactly one metadata part and one file part. Unsupported fields fail validation. Mutation routes accept no query parameters. Compressed bodies are unsupported; omit Content-Encoding or use identity.

Metadata, Journal and processing-retry bodies may contain at most 16,384 bytes. Document route bodies may contain at most 1,100,000 bytes; the canonical blocks inside must also pass their 1,000,000-byte document limit. Transcript-import requests may contain at most 1,100,000 bytes, including any multipart boundaries; multipart metadata is limited to 16,384 bytes and the file to 1,000,000 bytes. The formatted transcript must fit 500,000 characters, including display names and separators.

Reduce the payload after a size error. The body must arrive within five seconds. Responses have a 1,572,864-byte limit; reduce a list's limit if its response is too large.

See World pages, sessions, transcript imports, documents and Journal edits for each body contract.

Read the acknowledgement

Successful writes include data.resource_url and meta.replayed. Follow the resource URL to read the saved content and its next ETag. A document acknowledgement's revision and canonical_hash are not values for If-Match.

Entity and text-session creation return 201. Other content edits return 200. Transcript imports and processing retries return 202 with data.processing_url. Follow that URL until notes processing completes.

For exact conflict and recovery responses, see errors. Respect rate limits on both first attempts and replays.