API

CMS integration guide

Sign each revision once. Prove what readers get.

A label is worth something only if it matches the article on the page. This guide follows the same publishing lifecycle as Encypher's WordPress integration and gives you a small worker that signs from any CMS queue through the public API.

Lifecycle

Sign a saved generation, not a request

A generation is one saved, signable state of an article: its text plus the metadata the label will carry. Your CMS creates a generation token when that save commits and stores it with the post. Everything below hangs off that token.

1

Trigger after the save commits

Queue signing only after content and metadata are both saved. In WordPress that is wp_after_insert_post, which runs after post meta is written; save_post can run before it. Elsewhere, use a post-commit hook or an outbox row, not a pre-save filter.

2

Ignore what is not a publication

Skip autosaves, previews, revision copies and drafts you do not publish. Webhooks arrive more than once, so queue at most one job per generation token.

3

One generation, one key, one document

Derive the Idempotency-Key and document_id from the generation and never change them. An edit is a new generation with its own key; earlier generations stay as history. Never sign while rendering a page view.

4

Sign what readers read

Render the article, extract its plain text with an HTML parser, and normalize it the same way every time. Signing runs in a server-side worker; the API key never reaches a browser or editor.

5

Let the newest generation win

An edit can land while an older job is still running. Commit a result only if its generation is still the pending one. A late result is kept as history and never served.

6

Check before you claim

Verify the returned text before marking the article protected, then check the page your CDN actually serves. Copy text from the live page into POST /public/verify after template or cache changes.

State

Keep the signed copy beside the source

Editors keep editing the source. The signed text is a delivery artifact. Store it exactly as returned, in its own field, and never write it back over the post body: an editor round trip or a sanitizer can strip the invisible marks.

generation and idempotency_key
Reused for every retry of this generation. A new key for the same request can create a second signature.
work_id
One stable identity for the article across revisions, sent as options.work_id. The worker requests retained manifests so the next edit can resolve its parent; do not disable manifest storage for this flow.
document_id
Store the value the response returns. The API can answer under a different id than you sent.
instance_id and signed_text
The next edit sends them as previous_instance_id and previous_signed_content, with action: c2pa.edited, so the history chains.
correlation_id
Log it with every failure. Support uses it to find the request. The worker also sends its own X-Request-ID.

Compare-and-set

Publish only the newest generation

-- Illustrative schema. Record every finished generation as history.
INSERT INTO article_signatures
  (post_id, generation, document_id, instance_id, signed_text, verified_at)
VALUES (:post_id, :generation, :document_id, :instance_id, :signed_text, now());

-- Publish it only if no newer edit has been queued since.
UPDATE articles
   SET live_generation = :generation
 WHERE id = :post_id
   AND pending_generation = :generation;
-- 0 rows: a newer generation owns the post. Keep the row; do not serve it.

What a label proves

Say what it shows, nothing more

A valid label shows who signed the text, what they declared, including how AI was involved, and that the text has not changed since. It does not show that the article is true or who owns the rights to it. Keep reader-facing wording to those facts.

The first generation sends action: c2pa.created with an IPTC digital_source_type, for example digitalCreation for human-written text. Send the value your editors declared, not a default that makes every article look human-written.

HTML

Keep the markup; place the marks

POST /sign signs plain text and returns it with invisible marks. Your templates serve HTML. Map the marks into the rendered HTML's text nodes with a real HTML parser, so links, emphasis and embeds survive. The WordPress plugin does this for WordPress. Never strip tags, sign the result, and save that plain text over the article.

Extract and place with one parser

Use the same parser and normalization for extraction and placement, so the signed characters line up with the served characters. options.return_embedding_plan returns codepoint positions for the marks if you place them yourself.

Protect the marks downstream

Minifiers, AMP converters, feed builders and sanitizers can drop invisible characters. Verify each delivery path you care about: page, CDN, feed and syndication.

Serve, do not re-sign

Page views read the stored signed copy. A template change that alters visible text is a new generation, signed by the queue, not on request.

Failures

Retry the same request, a few times, then stop

Retry only with the same key and the same bytes, a bounded number of times. Branch on the HTTP status and error.code, and check Content-Type before parsing: an edge rejection may be HTML.

Timeout, network error, 5xx
The request may have succeeded. Retry with the same key; a completed request replays its first result. Exception: 503 SIGNING_CERT_UNAVAILABLE is configuration, so stop.
429
Rate limit: wait for Retry-After. When error.error names an allowance, such as QuotaExceeded, waiting a minute will not help: stop and alert.
409 SIGNING_IN_PROGRESS
The first attempt is still running. Wait for Retry-After and send the same request again.
409 SIGNING_IDEMPOTENCY_CONFLICT
The key was used with a different body. Your extraction is not deterministic, or the content changed without a new generation. Fix that; do not mint a fresh key for the same generation.
401, 402, 403
Key, plan, allowance or entitlement. Stop, alert an operator, and apply your publication policy.
410, 413, 422
410 SIGNING_RESULT_PURGED means the stored result expired: sign a new generation. 413 is too large. 422 is invalid input, including a missing Idempotency-Key.

Fail closed

Hold until protected

Keep the last protected version live, or hold a first publication, until the new generation verifies. Use this when readers rely on the label.

Fail open

Publish now, label honestly

Publish the new text at once, without the badge or any protected claim, and let the queue sign it later. Never show a badge for text that has not verified. Choose one policy and write it down.

Direct API example

A signing worker for your queue

This Node.js script performs the signing step for one job: it calls POST /sign with a stable article work_id and a separate key and document id per generation, retains the manifest for edit history, retries a few times within Retry-After limits, and verifies the returned text with POST /public/verify. It is a building block, not a CMS integration: your code still extracts the text, runs the queue, applies the compare-and-set and publishes. It uses only the public HTTP API; no SDK package is needed.

Input

One job per generation

{
  "site_id": "news.example",
  "post_id": "1234",
  "generation": "4f1c2a9e-rev-17",
  "title": "Council approves budget",
  "canonical_url": "https://news.example/council-budget",
  "text": "The council approved the budget on Tuesday.\n\nThe vote was 7-2.",
  "digital_source_type": "http://cv.iptc.org/newscodes/digitalsourcetype/digitalCreation",
  "previous": null
}

For an edit, set previous to the instance_id and signed_text of the generation readers see now. Without it, the job is a first signature and needs digital_source_type.

Run

Exit code tells the queue what to do

export ENCYPHER_API_KEY="<server-side key>"
node cms-sign-worker.mjs < job.json > result.json

0: status: signed; store the result. 75: run the same job again after retry_after_seconds. 1: blocked, rejected or verification_failed; alert and apply your publication policy.

Treat result.json as article content, not an application log. Store it with the revision; log identifiers, status and error codes rather than API keys or article bodies.

View the complete Node.js worker
// cms-sign-worker.mjs
// Signs one immutable CMS text generation with the Encypher API, then verifies
// the signed text it gets back. One job in (JSON on stdin), one result out
// (JSON on stdout).
//   exit 0   signed and verified: store the result, then publish
//   exit 75  run the same job again after retry_after_seconds
//   exit 1   do not retry automatically: read "status" and "code"
//
// Scope: the signing step only. Your CMS still owns the queue, the generation
// compare-and-set, storage and publication. Node.js 18 or later, no packages.
//   ENCYPHER_API_KEY   required; keep it on the server
//   ENCYPHER_API_BASE  optional; default https://api.encypher.com/api/v1
import { createHash, randomUUID } from "node:crypto";

const API_BASE = process.env.ENCYPHER_API_BASE || "https://api.encypher.com/api/v1";
const MAX_ATTEMPTS = 3; // tries in this run; longer waits go back to your queue
const MAX_WAIT_SECONDS = 30; // a longer Retry-After is handed back as exit 75
const RETRY_LATER = 75;

const sleep = (seconds) => new Promise((resolve) => setTimeout(resolve, seconds * 1000));

function retryAfterSeconds(response) {
  const value = response.headers?.get("retry-after");
  if (!value) return null;
  const seconds = Number(value);
  if (Number.isFinite(seconds)) return Math.max(0, Math.ceil(seconds));
  const date = Date.parse(value);
  return Number.isNaN(date) ? null : Math.max(0, Math.ceil((date - Date.now()) / 1000));
}

async function post(path, body, headers, timeoutMs) {
  const requestId = `cms-${randomUUID()}`; // sent as X-Request-ID; log it
  try {
    const response = await fetch(API_BASE + path, {
      method: "POST",
      headers: { "Content-Type": "application/json", Accept: "application/json", "X-Request-ID": requestId, ...headers },
      body,
      redirect: "error",
      signal: AbortSignal.timeout(timeoutMs),
    });
    // An edge rejection can be HTML, so check the type before parsing.
    let json = null;
    if ((response.headers.get("content-type") || "").includes("application/json")) {
      json = await response.json().catch(() => null);
    } else {
      await response.text();
    }
    return { status: response.status, json, headers: response.headers, requestId };
  } catch (error) {
    // Timeout or network failure. The request may still have succeeded.
    return { status: 0, json: null, headers: null, requestId, transport: error.name };
  }
}

// "retry": same key, same bytes, later. "blocked": the key, plan, allowance or
// signing certificate needs a person. "rejected": this job is wrong; fix the
// integration, or create a new generation if the content changed.
function classify(response) {
  const { status } = response;
  const error = response.json?.error || {};
  if (status === 0 || status === 408) return "retry";
  if (status === 409) return error.code === "SIGNING_IN_PROGRESS" ? "retry" : "rejected";
  if (status === 429) return error.error ? "blocked" : "retry"; // error.error names a spent allowance
  if (status === 401 || status === 402 || status === 403) return "blocked";
  if (status === 503 && error.code === "SIGNING_CERT_UNAVAILABLE") return "blocked";
  if (status >= 500) return "retry";
  return "rejected"; // 400, 404, 409 conflict, 410 purged, 413, 422
}

function outcome(status, response, extra = {}) {
  const error = response.json?.error || {};
  return {
    status,
    http_status: response.status,
    code: error.code || response.transport || null,
    message: error.message || null,
    correlation_id: response.json?.correlation_id || response.headers?.get("x-request-id") || response.requestId,
    ...extra,
  };
}

async function main(job) {
  for (const field of ["site_id", "post_id", "generation", "text"]) {
    if (typeof job[field] !== "string" || job[field] === "") {
      return [1, { status: "rejected", code: "INVALID_JOB", message: `${field} is required` }];
    }
  }
  const previous = job.previous || null;
  if (previous ? !(previous.instance_id && previous.signed_text) : !job.digital_source_type) {
    const message = "a first generation needs digital_source_type; an edit needs previous.instance_id and previous.signed_text";
    return [1, { status: "rejected", code: "INVALID_JOB", message }];
  }
  const apiKey = process.env.ENCYPHER_API_KEY;
  if (!apiKey) return [1, { status: "blocked", code: "MISSING_API_KEY", message: "set ENCYPHER_API_KEY on the server" }];
  const base = new URL(API_BASE);
  if (base.protocol !== "https:" && !["localhost", "127.0.0.1"].includes(base.hostname)) {
    return [1, { status: "blocked", code: "INSECURE_API_BASE", message: "the API key is only sent over https" }];
  }

  // One generation: one key, one document id, one exact request body. A retry
  // sends the same bytes under the same key, so a lost response replays the
  // first result instead of signing twice.
  const workDigest = createHash("sha256").update([job.site_id, job.post_id].join("\0")).digest("hex");
  const digest = createHash("sha256").update([job.site_id, job.post_id, job.generation].join("\0")).digest("hex");
  const ids = { generation: job.generation, work_id: `cms_work_${workDigest}`, idempotency_key: `cms-sign-${digest}` };
  const provenance = previous
    ? { action: "c2pa.edited", previous_instance_id: previous.instance_id, previous_signed_content: previous.signed_text }
    : { action: "c2pa.created" };
  if (job.digital_source_type) provenance.digital_source_type = job.digital_source_type;
  const body = JSON.stringify({
    text: job.text,
    document_id: `cms_${digest.slice(0, 60)}`,
    document_title: job.title,
    document_url: job.canonical_url,
    options: { document_type: "article", work_id: ids.work_id, store_c2pa_manifest: true, ...provenance },
  });
  const auth = { Authorization: `Bearer ${apiKey}`, "Idempotency-Key": ids.idempotency_key };

  let signed;
  for (let attempt = 1; ; attempt += 1) {
    signed = await post("/sign", body, auth, 30000);
    if (signed.status >= 200 && signed.status < 300) break;
    const kind = classify(signed);
    if (kind !== "retry") return [1, { ...outcome(kind, signed), ...ids }];
    const wait = retryAfterSeconds(signed) ?? 2 ** (attempt - 1);
    if (attempt >= MAX_ATTEMPTS || wait > MAX_WAIT_SECONDS) {
      return [RETRY_LATER, { ...outcome("retry_later", signed), ...ids, retry_after_seconds: Math.max(wait, 1) }];
    }
    await sleep(wait);
  }
  const doc = signed.json?.data?.document;
  if (signed.json?.success !== true || !doc?.signed_text || !doc.document_id) {
    return [1, { ...outcome("rejected", signed, { code: "UNEXPECTED_RESPONSE" }), ...ids }];
  }

  // Check the exact text you will store. Running this job again after a
  // verify failure replays the signature above; it does not sign again.
  const check = await post("/public/verify", JSON.stringify({ text: doc.signed_text }), {}, 15000);
  if (check.status === 0 || check.status === 429 || check.status >= 500) {
    return [RETRY_LATER, { ...outcome("retry_later", check), ...ids, retry_after_seconds: retryAfterSeconds(check) ?? 30 }];
  }
  if (check.status !== 200 || check.json?.success !== true || check.json?.valid !== true || check.json?.tampered === true) {
    const reason = { code: check.json?.reason_code || null, document_id: doc.document_id };
    return [1, { ...outcome("verification_failed", check, reason), ...ids }];
  }
  return [0, {
    status: "signed",
    ...ids,
    document_id: doc.document_id, // store the id the API returns
    instance_id: doc.instance_id ?? null, // the next edit's previous_instance_id
    signed_text: doc.signed_text, // serve this; the next edit's previous_signed_content
    verification_url: doc.verification_url,
    reused: doc.reused === true,
    correlation_id: signed.json?.correlation_id || signed.requestId,
  }];
}

let input = "";
process.stdin.setEncoding("utf8");
for await (const chunk of process.stdin) input += chunk;
let job = null;
try {
  job = JSON.parse(input);
} catch {
  job = null;
}
const [exitCode, result] = job && typeof job === "object"
  ? await main(job)
  : [1, { status: "rejected", code: "INVALID_JOB", message: "stdin must be one JSON object" }];
process.stdout.write(`${JSON.stringify(result)}\n`);
process.exitCode = exitCode;

Download cms-sign-worker.mjs. Test it against your account with a draft article first; every successful call is a real signature.

Media

Pick the endpoint by what you publish

POST /sign for article text. POST /sign/rich when the article and its images, audio or video should be one signed record. POST /sign/media for a standalone file, such as a featured image or a library upload. Each has its own Idempotency-Key per file version. For files of 100 MB and above, check GET /sign/media/hash/capabilities and use prepared signing when it reports enabled: true.

Account setup

Account settings live in the dashboard

Create server-side API keys, set the organization name readers see, choose a rights profile and watch usage and allowances in the dashboard. This guide covers what is the same for every account. WordPress sites can use the Encypher WordPress plugin instead of building this.