# Trace rules

Your versioned Trace rules, which allow, challenge, review, reject or log an agent's action and a model's output.

Related guide: [Trace rules](https://provenanceauth.com/docs/trace/guides/trace-rules.md)

## Endpoints

- `POST /v1/trace/policies/versions`: [Create a capture rule draft](#post-v1-trace-policies-versions)
- `GET /v1/trace/policies`: [Retrieve your Trace rules](#get-v1-trace-policies)
- `GET /v1/trace/policies/versions/{version}`: [Retrieve a Trace rule version](#get-v1-trace-policies-versions-version)
- `GET /v1/trace/policies/versions/{version}/plan`: [Get a Trace rule version's plan](#get-v1-trace-policies-versions-version-plan)
- `GET /v1/trace/policies/trial`: [Get the trial run](#get-v1-trace-policies-trial)
- `GET /v1/trace/policies/shadow_report`: [Get the Trace rules shadow report](#get-v1-trace-policies-shadow-report)
- `GET /v1/trace/policies/performance`: [Get rule performance](#get-v1-trace-policies-performance)
- `GET /v1/trace/policies/versions`: [List Trace rule versions](#get-v1-trace-policies-versions)
- `GET /v1/trace/policies/backtest/{id}/changes`: [List the records a backtest would change](#get-v1-trace-policies-backtest-id-changes)
- `PUT /v1/trace/policies`: [Publish your Trace rules](#put-v1-trace-policies)
- `DELETE /v1/trace/policies`: [Revert to no Trace rules](#delete-v1-trace-policies)
- `GET /v1/trace/policies/versions/{version}/diff`: [Review a Trace rule version's changes](#get-v1-trace-policies-versions-version-diff)
- `POST /v1/trace/policies/versions/{version}/publish`: [Publish a Trace rule version](#post-v1-trace-policies-versions-version-publish)
- `GET /v1/trace/policies/versions/export`: [Export Trace rule versions](#get-v1-trace-policies-versions-export)
- `POST /v1/trace/policies/backtest`: [Backtest Trace rules](#post-v1-trace-policies-backtest)
- `DELETE /v1/trace/policies/trial`: [Stop the trial run](#delete-v1-trace-policies-trial)
- `POST /v1/trace/policies/trial/promote`: [Promote the trial run](#post-v1-trace-policies-trial-promote)
- `POST /v1/trace/policies/versions/{version}/shadow`: [Shadow a Trace rules version](#post-v1-trace-policies-versions-version-shadow)
- `DELETE /v1/trace/policies/versions/{version}/shadow`: [Stop shadowing Trace rules](#delete-v1-trace-policies-versions-version-shadow)
- `POST /v1/trace/policies/simulate`: [Simulate your Trace rules](#post-v1-trace-policies-simulate)

## The policy version object

### Attributes

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `object` | enum | yes | The type of object. One of `policy_version`. |
| `policy_id` | string | no | The policy's ID (`pol_…`), the same on every version of it. |
| `domain` | string | yes | The policy domain. |
| `version` | integer | yes | The version number. |
| `active` | boolean | yes | Whether this version is the active policy. |
| `note` | string \| null | no | A note for the record. |
| `created_at` | string | no | When it was created. |
| `created_by` | string \| null | no | Who saved the version. |
| `document` | object | no | The policy document as saved, with Provenance's rule IDs. |
| `shadow` | boolean | no | The shadow settings. |
| `draft` | boolean | no | Present and true on a draft saved with POST .../versions that has not gone live. |
| `trial_ends_at` | timestamp | no | Present while the version is on a trial run, with when the trial run ends. |
| `restored_from` | integer | no | On a restore, the version it copies. |
| `promoted_from_trial` | boolean | no | Present and true when the version went live from its trial run. |
| `source` | enum | no | Where the version was written: the console, the API, or a rules embed session (`<provenance-rules>`). Present on versions written since 2026-11-17. One of `console`, `api`, `embed`. |
| `embed_session` | string | no | On a version saved by a rules embed session, that session's id (the embed token's `id`, never the token). `created_by` names the API key or console member that minted the session. |
| `draft_group` | string | no | Sandbox. The draft group a rules embed session saved this draft in (`rules.draft_group`). It stays once the draft is published. Listed only with `?draft_group=` naming the group while the draft waits. |
| `key_last4` | string | no | In the version list, on a version written through the API or a rules embed session, the last four characters of the account's API key that wrote it (or minted the session). Absent when `created_by` is a console member. |
| `warnings` | array of objects | no | Checkout rules only, present when a rule never runs (`shadowed_by`). The version is saved either way. |
| `warnings.type` | enum | yes | Always `shadowed_by`. One of `shadowed_by`. |
| `warnings.rule_id` | string | yes | The rule that never runs. |
| `warnings.shadowed_by` | string | yes | The rule above it that always decides first. |
| `warnings.message` | string | yes | The warning in words ("This rule never runs: 'No mandate or approval' decides first"). |

### Example

```json
{
  "object": "policy_version",
  "policy_id": "pol_956287817DE7DEF7A3C4E0C732",
  "domain": "trace",
  "version": 1,
  "active": true,
  "note": "ask before paying after an injected email; never delete",
  "created_at": "2026-11-25T22:25:46.753Z",
  "document": {
    "rules": [
      {
        "id": "rul_01M8AD18814Z7YZAN1KM1D5677",
        "legacy_id": "injected-email-payments",
        "when": [
          {
            "fact": "action.risk",
            "op": "eq",
            "value": "pay"
          },
          {
            "fact": "context.untrusted_sources",
            "op": "contains",
            "value": "email"
          },
          {
            "fact": "finding.categories",
            "op": "contains",
            "value": "indirect_injection"
          }
        ],
        "require": {
          "approval": true
        },
        "label": "Payments after an injected email"
      },
      {
        "id": "rul_01M8AD18819JWTF7QAXS4745V5",
        "legacy_id": "no-deletes",
        "when": [
          {
            "fact": "action.risk",
            "op": "eq",
            "value": "delete"
          }
        ],
        "require": {
          "deny": true,
          "lock": true
        },
        "label": "Deletes"
      }
    ]
  }
}
```

## Events

Sent to your [webhook endpoints](https://provenanceauth.com/docs/integrate/webhooks.md) when they subscribe:

- `trace.policy.published`
- `trace.policy.notified`

## Create a capture rule draft

`POST /v1/trace/policies/versions`

Saves a draft version with the same checks as a publish. Nothing goes live until you publish it.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Retry a create safely: the same key + request returns the stored response (24 h, per caller). |
| `document` | body | object | yes | A policy document: ordered rules, in one format for an agent policy, a store's checkout rules and a person's own rules. |
| `document.rules` | body | array of objects | yes | The rules, in order (at most 50; up to 200 on Enterprise). |
| `document.rules.id` | body | string | no | The rule's ID, set by Provenance: `rul_` and a ULID, given when the rule is first saved and kept in every later version while the rule exists; a default row has a fixed `rul_default_…` ID, the same in every account. Leave it out of a new rule, and send a saved rule back with its ID to keep it. A `rul_` ID the policy never had is replaced with a new one. Any other value is kept as `legacy_id` and names the same rule when sent again. The `rul_default_` prefix is reserved for the default rows (`400 policy_invalid`). A person's own rules and the risk policies keep their IDs as written. Always present on a read. |
| `document.rules.ref` | body | string | no | Set by Provenance: the rule's short display ID (`R-103`, or `R-04` outside checkout), shown beside the rule in the console and on every decision as `policy.rule.ref`. Kept across versions and never reused in the policy. What you send here is ignored. |
| `document.rules.legacy_id` | body | string | no | Set by Provenance: the ID the rule had before rule IDs were set by Provenance (November 2026), or the value it was first written with. A decision recorded with that ID still finds the rule. What you send here is ignored. |
| `document.rules.group` | body | string | no | The rule group (`groups[].key`) this rule belongs to. It still runs in order as an ordinary rule. |
| `document.rules.label` | body | string | no | The rule's name, such as `Orders over $500`. Evaluation never reads it. |
| `document.rules.when` | body | array of objects \| object | yes | A rule's or signal's IF part. Either a list of conditions that must all match, or an object that picks a mode over conditions and groups (groups nest to three levels with the rule's own; at most 10 items in a group and 20 conditions in all). |
| `document.rules.when.match` | body | enum | no | Whether all, any, none or at least `n` of the items must match (`none` holds when no item does). One of `all`, `any`, `none`, `at_least`. |
| `document.rules.when.n` | body | integer | no | With `match: at_least`: how many items must match (1 to the item count). |
| `document.rules.when.items` | body | array of objects | no | Conditions and groups (at most 10). |
| `document.rules.when.items.fact` | body | string | no | The fact the condition reads (`transaction_amount`, `order.amount`, `agent.verified`), or `field` to read `path` from the request. |
| `document.rules.when.items.op` | body | enum | no | The comparison operator. A field condition takes the comparisons, `in`, `matches`, `contains`, `contains_any`, `is_empty` and `is_not_empty`. Every operator except the two null operators fails to match a missing or null fact, `ne` included. `is_empty` matches a fact that is missing, null, an empty string or an empty list; `is_not_empty` matches any other value. |
| `document.rules.when.items.value` | body | any | no | The value to compare with (a string, number, boolean or a list of them). `is_empty` and `is_not_empty` take `true`. |
| `document.rules.when.items.path` | body | string | no | With `fact: field`: up to 6 dotted names, each optionally followed by `[]` for every element of a list (at most one `[]`), such as `metadata.cost_center` or `order.items[].sku`. |
| `document.rules.when.items.items` | body | enum | no | With a path through a list: whether any element (the default) or every element must match. One of `any`, `all`. |
| `document.rules.when.items.metric` | body | enum | no | With `fact: velocity`: what is counted. One of `verify_count`, `amount_sum`. |
| `document.rules.when.items.window` | body | enum | no | With `fact: velocity`: the window. `1h` and `24h` are rolling; `month` is the calendar month in UTC, counted per `account` or `agent`. One of `1h`, `24h`, `month`. |
| `document.rules.when.items.per` | body | enum | no | With `fact: velocity`: what it is counted per. `agent` is the registered agent the token names (none: 0). One of `device`, `session`, `account`, `agent`. |
| `document.rules.when.items.set` | body | string | no | With `fact: canary` or `prediction`: the canary family or probe. |
| `document.rules.when.items.best_effort` | body | boolean | no | With a canary or probe: an unavailable reading evaluates false instead of failing closed. |
| `document.rules.when.items.baseline` | body | enum | no | With `z_gt` or `pct_gt`: the baseline the score is compared against. One of `agent`, `account`. |
| `document.rules.when.items.if_unavailable` | body | enum | no | What an unavailable reading means for this condition: `skip` (no match), `match`, or `ask` (match and ask a person). `ignore` is an external risk fact's older word for `skip`; a capture fact or Trace finding takes `skip` or `match`. One of `skip`, `match`, `ask`, `ignore`. |
| `document.rules.when.items.match` | body | enum | no | Whether all, any, none or at least `n` of the group's items must match (`none` holds when no item does; a condition on a missing fact doesn't hold). One of `all`, `any`, `none`, `at_least`. |
| `document.rules.when.items.n` | body | integer | no | With `match: at_least`: how many items must match (1 to the item count). N-of-M. |
| `document.rules.when.items.conditions` | body | array of objects | no | The group's conditions and groups (1 to 10). |
| `document.rules.require` | body | object | yes | A rule's THEN part: `deny` blocks, `approval` asks a person, `biometric`, `hardware` or `min_tier` ask for stronger proof, `webhook` asks your webhook, and `notify` (alone) allows and notifies. On your checkout and card issuer rules, `no_challenge` (alone) approves (Capture and Trace rules say `frictionless`), and on an after-approval rule `review` (alone) holds the order for your review. |
| `document.rules.require.review` | body | enum | no | Checkout rules with `phase: after_approval` only, set alone: Review. The customer approved, and the order waits for your decision (`status: in_review`, no token yet) until you approve or reject it, or it times out. One of `true`. |
| `document.rules.require.no_challenge` | body | enum | no | Checkout rules (`/v1/authorize/policies`) and card issuer rules, set alone: Approve. When the rule matches, the cart is approved (`allow`, reason `policy_rule_approved`) and no later rule runs, whether or not a token, mandate or earlier approval covers it. A cart nothing covers gets no token. A write may also send `frictionless`. One of `true`. |
| `document.rules.require.frictionless` | body | enum | no | Capture and Trace rules, set alone: Approve (Allow). On checkout and card issuer rules, an older word for `no_challenge`, still accepted on a write. When a checkout rule matches, the cart is approved (`allow`, reason `policy_rule_approved`) and no later rule runs, whether or not a token, mandate or earlier approval covers it. A cart nothing covers gets no token. One of `true`. |
| `document.rules.require.ucp_fallback` | body | enum | no | Checkout rules only, with `approval: true` before approval: what a Universal Commerce Protocol checkout does when the platform didn't negotiate the approval Action. `escalate` (the default) hands the checkout to your checkout page; `hold_after_order` opens the approval and you hold the order until it is approved. One of `escalate`, `hold_after_order`. |
| `document.rules.require.deny` | body | boolean | no | Block the request; the rule's `reason` is what the agent sees. |
| `document.rules.require.lock` | body | enum \| object | no | Trace rules only, with `deny` or `approval`: lock the agent session (`true` or `scope: session`), the registered agent (`agent`) or the run (`run`) until a person clears it; `revoke_session` also revokes the session's intent tokens. |
| `document.rules.require.lock.scope` | body | enum | no | What the lock names. One of `session`, `agent`, `run`. |
| `document.rules.require.lock.revoke_session` | body | enum | no | Also revoke the session's intent tokens. One of `true`. |
| `document.rules.require.suspend_agent` | body | enum | no | Trace rules only, with `deny`: suspend the registered agent. One of `true`. |
| `document.rules.require.sample_rate` | body | integer | no | Spot checks, on a Reject rule (`deny`) of checkout, agent, capture or Trace rules (Trace at phase `action` only): 1 in N of the records it would reject is asked about instead (Challenge; a capture shot goes to In review, a Trace action to Review), chosen from the record id. Card issuer rules and Trace rules at phase `completion` refuse it: nobody can answer in time. Off unless set. |
| `document.rules.require.flow` | body | string | no | Checkout and agent rules: the rule takes this sub-flow's outcome as its own (a key in the document's `flows`). The flow's `none` passes to the next rule. Takes no other requirement. |
| `document.rules.require.approval` | body | boolean | no | Ask a person to approve. |
| `document.rules.require.approvers` | body | integer | no | How many distinct approvers are needed, for a route without `steps`. |
| `document.rules.require.route` | body | object | no | Who approves a rule's request and how long it waits: either a chain of `steps`, or a first target with `escalate` and `wait`. |
| `document.rules.require.route.to` | body | string | no | The first target. With `steps` it is the first step's first target and may be left out. |
| `document.rules.require.route.steps` | body | array of objects | no | An approval chain of 1 to 5 steps, in order. The chain waits the sum of its steps' `after` (1 minute to 7 days); then the rule's `if_unanswered` applies, else the account's approval expiry default. A chain leaves out `escalate`, `wait` and `approvers`. |
| `document.rules.require.route.approvers_from` | body | enum | no | How approvals count toward the number needed. One of `any`, `distinct_people`. |
| `document.rules.require.route.escalate` | body | array of objects | no | Escalation steps, for a route without `steps`. |
| `document.rules.require.route.wait` | body | string | no | How long the request waits in all, for a route without `steps`. |
| `document.rules.require.route.if_unanswered` | body | enum | no | What happens when nobody answers. Left out, the account's approval expiry default applies. One of `expire`, `decline`, `approve_below`. |
| `document.rules.require.route.approve_below_amount` | body | number | no | With `approve_below`: the amount it approves at or under. |
| `document.rules.require.route.hours` | body | string | no | The approver group (`agr_…`) whose business hours apply. |
| `document.rules.require.route.outside_hours` | body | enum | no | What happens to a request outside business hours. One of `hold`, `escalate`. |
| `document.rules.require.route.assign` | body | enum | no | Who gets it first. A chain uses `all`. One of `all`, `round_robin`, `least_pending`. |
| `document.rules.require.biometric` | body | boolean | no | Require face, fingerprint or passkey from the person. |
| `document.rules.require.hardware` | body | boolean | no | Require a hardware-backed phone. |
| `document.rules.require.min_tier` | body | enum | no | The weakest device tier allowed. One of `simulated`, `software`, `tee`, `strongbox`, `sep`. |
| `document.rules.require.webhook` | body | string | no | The name of the policy webhook to ask. |
| `document.rules.require.notify` | body | object | no | "Approve and notify": the rule allows the request and tells the people named, the account's webhook endpoints, or both. It never decides, so evaluation goes on to the next rule. A notify rule's `require` holds `notify` alone. |
| `document.rules.require.notify.to` | body | array of strings | no | People, groups or roles to tell (1 to 10 route targets, such as `role:admins` or `user:owner`). |
| `document.rules.require.notify.webhook` | body | boolean | no | Also send the `mandate.policy.notified` event to the account's webhook endpoints. |
| `document.rules.require.approval_min_credential_age_s` | body | integer | no | With `approval`: how old the approving passkey must be, in seconds. |
| `document.rules.require.approval_method` | body | enum | no | With `approval`: only the approver's phone in the Provenance app approves. One of `device_key`. |
| `document.rules.require.individual` | body | boolean | no | With `approval`: the request is never approved in a batch. |
| `document.rules.require.auto_approve` | body | array of objects | no | Clauses under which the approval counts as given without a person. |
| `document.rules.reason` | body | string | no | The reason code a matching rule reports. On a person's rules: `store_not_allowed` on a block, or `ask_above` or `outside_hours` on an ask (the codes the rules moved from Your rules keep), else none (`person_rule`). |
| `document.rules.on_request` | body | enum | no | A person's rules only: what the rule does to a company's approval request sent to the person, when it matches. `hold` keeps the request in the person's home and sends nothing; `defer` delivers it like quiet hours. Absent: the rule leaves companies' requests alone. Such a rule reads only the store and the time. One of `hold`, `defer`. |
| `document.rules.phase` | body | enum | no | Trace rules: `action` (absent; before a tool runs) or `completion` (on model output). Your checkout rules: when the rule runs. `assess` (absent) runs at `POST /v1/authorize/checkout_assessments`; `after_approval` runs once the customer has decided a cart approval and before the token is minted, over the assessment's facts and the `approval.*` facts (`approval.decision`, `approval.location`, …). After-approval rules approve (`frictionless`; checkout rules say `no_challenge`), review (`review`) or reject (`deny`); they never challenge. Every plan. One of `assess`, `after_approval`, `action`, `completion`. |
| `document.rules.enabled` | body | boolean | no | Whether the rule is on; absent means on. `false` keeps the rule in the document (and its versions) but skips it: it never matches, decides, notifies or counts in a backtest. Turning a rule off or on is a change like any other (a new draft or version); on a person's tighten-only rules, turning one off loosens them. |
| `document.rules.if_unavailable` | body | enum | no | What an unavailable fact means for this rule, over the document's `settings.if_unavailable` (a condition's own setting wins). `fail_closed` and `fail_open` stay Trace and agent rules' words. One of `skip`, `match`, `ask`, `fail_closed`, `fail_open`. |
| `document.timezone` | body | string | no | An IANA time zone, such as `America/Chicago`, for a person's `time.local_hour` and `time.local_weekday` facts. |
| `document.tighten_only` | body | boolean | no | A person's rules only. A change that only makes the rules stricter saves without a passkey; one that loosens them needs the passkey and is refused for 7 days after a recovery. Turning it off is a loosening. |
| `document.version` | body | integer | no | Informational; the stored version number is assigned on save. |
| `document.external_confirmations` | body | object | no | Which confirmations given outside Provenance count, and whose keys. Empty by default; it also governs your store's cart approvals. Every plan. The issuers listed here are also the ones whose mandates cover a checkout assessment's cart (`checkout.covered: third_party_mandate`). |
| `document.external_confirmations.accept` | body | array of enums | no | The kinds you accept. |
| `document.external_confirmations.ap2_issuers` | body | array of objects | no | Required with `ap2_user_mandate`: the AP2 issuers whose signatures count. Their mandates also cover a checkout assessment's cart, with or without `accept`. |
| `document.external_confirmations.ap2_issuers.name` | body | string | yes | The name shown as "Confirmed in <name>". |
| `document.external_confirmations.ap2_issuers.jwks_url` | body | string | yes | The issuer's JWKS (https). |
| `document.external_confirmations.acp_issuers` | body | array of objects | no | The ACP issuers you trust: a checkout completion whose signed intent (`provenance_intent.token`) one of them signed covers a checkout assessment's cart. |
| `document.external_confirmations.acp_issuers.name` | body | string | yes | The issuer's name, as `authority.issuer` shows it. |
| `document.external_confirmations.acp_issuers.jwks_url` | body | string | yes | The issuer's JWKS (https). |
| `document.external_confirmations.platforms` | body | array of objects | no | Required with `platform`: the agent platforms whose signed confirmations count. |
| `document.external_confirmations.platforms.name` | body | string | yes | The platform's name. |
| `document.external_confirmations.platforms.jwks_url` | body | string | yes | The platform's JWKS (https). |
| `document.voice` | body | object | no | When a confirmation call may approve on the keypad, and when it needs the passkey. Set on your approval policy (`/mandate/policies`) or your checkout rules (`/authorize/policies`). Absent fields take the defaults: approve on the call up to 25.00 USD to a counterparty this person has paid before, and a passkey otherwise. Grants, delegations, new payees and contact or recovery changes always need the passkey, and so does any rule that requires a biometric. |
| `document.voice.enabled` | body | boolean | no | `false`: a call never approves; it reads the request and sends the passkey link. Default `true`. |
| `document.voice.voice_max` | body | integer | no | Approve on the call up to this amount, in minor units of `currency`. Default 2500 (25.00 USD). `0` means never. |
| `document.voice.currency` | body | string | no | The ISO 4217 currency of `voice_max`. Default `USD`. A request in another currency needs the passkey. |
| `document.voice.voice_requires_known_counterparty` | body | boolean | no | A counterparty this person hasn't paid before needs the passkey. Default `true`. |
| `document.voice.never_voice_action_types` | body | array of strings | no | Action types (`context.action_type`) that always need the passkey. |
| `document.passkeys` | body | object | no | On a checkout policy, what a new passkey needs on a cart approval. |
| `document.signals` | body | array of objects | no | Named checks with no outcome (`signal.<key>`), for checkout, agent, capture, Trace and card issuer rules. |
| `document.signals.id` | body | string | no | The server's id (`sig_` and a ULID), kept across versions. |
| `document.signals.key` | body | string | no | The fact's name part. Derived from the first label when left out, then fixed: a later write can't change it. |
| `document.signals.label` | body | string | yes | The account's name for the signal; change it at any time. |
| `document.signals.when` | body | array of objects \| object | yes | A rule's or signal's IF part. Either a list of conditions that must all match, or an object that picks a mode over conditions and groups (groups nest to three levels with the rule's own; at most 10 items in a group and 20 conditions in all). |
| `document.signals.when.match` | body | enum | no | Whether all, any, none or at least `n` of the items must match (`none` holds when no item does). One of `all`, `any`, `none`, `at_least`. |
| `document.signals.when.n` | body | integer | no | With `match: at_least`: how many items must match (1 to the item count). |
| `document.signals.when.items` | body | array of objects | no | Conditions and groups (at most 10). |
| `document.signals.when.items.fact` | body | string | no | The fact the condition reads (`transaction_amount`, `order.amount`, `agent.verified`), or `field` to read `path` from the request. |
| `document.signals.when.items.op` | body | enum | no | The comparison operator. A field condition takes the comparisons, `in`, `matches`, `contains`, `contains_any`, `is_empty` and `is_not_empty`. Every operator except the two null operators fails to match a missing or null fact, `ne` included. `is_empty` matches a fact that is missing, null, an empty string or an empty list; `is_not_empty` matches any other value. |
| `document.signals.when.items.value` | body | any | no | The value to compare with (a string, number, boolean or a list of them). `is_empty` and `is_not_empty` take `true`. |
| `document.signals.when.items.path` | body | string | no | With `fact: field`: up to 6 dotted names, each optionally followed by `[]` for every element of a list (at most one `[]`), such as `metadata.cost_center` or `order.items[].sku`. |
| `document.signals.when.items.items` | body | enum | no | With a path through a list: whether any element (the default) or every element must match. One of `any`, `all`. |
| `document.signals.when.items.metric` | body | enum | no | With `fact: velocity`: what is counted. One of `verify_count`, `amount_sum`. |
| `document.signals.when.items.window` | body | enum | no | With `fact: velocity`: the window. `1h` and `24h` are rolling; `month` is the calendar month in UTC, counted per `account` or `agent`. One of `1h`, `24h`, `month`. |
| `document.signals.when.items.per` | body | enum | no | With `fact: velocity`: what it is counted per. `agent` is the registered agent the token names (none: 0). One of `device`, `session`, `account`, `agent`. |
| `document.signals.when.items.set` | body | string | no | With `fact: canary` or `prediction`: the canary family or probe. |
| `document.signals.when.items.best_effort` | body | boolean | no | With a canary or probe: an unavailable reading evaluates false instead of failing closed. |
| `document.signals.when.items.baseline` | body | enum | no | With `z_gt` or `pct_gt`: the baseline the score is compared against. One of `agent`, `account`. |
| `document.signals.when.items.if_unavailable` | body | enum | no | What an unavailable reading means for this condition: `skip` (no match), `match`, or `ask` (match and ask a person). `ignore` is an external risk fact's older word for `skip`; a capture fact or Trace finding takes `skip` or `match`. One of `skip`, `match`, `ask`, `ignore`. |
| `document.signals.when.items.match` | body | enum | no | Whether all, any, none or at least `n` of the group's items must match (`none` holds when no item does; a condition on a missing fact doesn't hold). One of `all`, `any`, `none`, `at_least`. |
| `document.signals.when.items.n` | body | integer | no | With `match: at_least`: how many items must match (1 to the item count). N-of-M. |
| `document.signals.when.items.conditions` | body | array of objects | no | The group's conditions and groups (1 to 10). |
| `document.scorecards` | body | array of objects | no | Scorecards (`scorecard.<key>.score`, `scorecard.<key>.matched`), for checkout, agent, capture, Trace and card issuer rules. |
| `document.scorecards.id` | body | string | no | The server's id (`scd_` and a ULID), kept across versions. |
| `document.scorecards.key` | body | string | no | The fact's name part. Derived from the first label when left out, then fixed. |
| `document.scorecards.label` | body | string | yes | The account's name for the scorecard; change it at any time. |
| `document.scorecards.rows` | body | array of objects | yes | The rows. Each reads a signal or its own `when`. |
| `document.scorecards.rows.signal` | body | string | no | A signal's key in this document (one of `signal` and `when`). |
| `document.scorecards.rows.when` | body | array of objects \| object | no | A rule's or signal's IF part. Either a list of conditions that must all match, or an object that picks a mode over conditions and groups (groups nest to three levels with the rule's own; at most 10 items in a group and 20 conditions in all). |
| `document.scorecards.rows.when.match` | body | enum | no | Whether all, any, none or at least `n` of the items must match (`none` holds when no item does). One of `all`, `any`, `none`, `at_least`. |
| `document.scorecards.rows.when.n` | body | integer | no | With `match: at_least`: how many items must match (1 to the item count). |
| `document.scorecards.rows.when.items` | body | array of objects | no | Conditions and groups (at most 10). |
| `document.scorecards.rows.points` | body | integer | yes | Points the row adds when it matches. |
| `document.scorecards.rows.label` | body | string | no | The row's name. |
| `document.scorecards.min_available` | body | integer | no | How many rows must be readable for the total to be available (default: all rows but one). |
| `document.groups` | body | array of objects | no | Rule groups (`group.<key>.outcome`), for checkout, agent, capture, Trace and card issuer rules. |
| `document.groups.id` | body | string | no | The server's id (`grp_` and a ULID), kept across versions. |
| `document.groups.key` | body | string | no | The fact's name part. Derived from the first label when left out, then fixed. |
| `document.groups.label` | body | string | yes | The account's name for the group; change it at any time. |
| `document.flows` | body | array of objects | no | The sub-flows this rule set calls (checkout and agent rules). Rules read `flow.<key>.outcome`, `flow.<key>.version` and each declared output `flow.<key>.<output>`, or take the flow's outcome with `require.flow`. |
| `document.flows.key` | body | string | yes | The sub-flow's key. |
| `document.flows.follow` | body | enum | no | `latest` (the default) follows the published version; `pinned` keeps `version`. One of `latest`, `pinned`. |
| `document.flows.version` | body | integer | no | The pinned version (only with `follow` set to `pinned`). |
| `document.settings` | body | object | no | How unavailable facts and fact resolution work for every rule of the document. |
| `document.settings.if_unavailable` | body | enum | no | What an unavailable fact means for every rule: `skip` (the condition doesn't match), `match` (it matches) or `ask` (it matches and a person is asked instead of the rule's outcome; refused on issuer rules). The older `fail_closed` and `fail_open` stay Trace and agent rules' words for an unavailable Trace finding. One of `skip`, `match`, `ask`, `fail_closed`, `fail_open`. |
| `document.settings.preflight` | body | boolean | no | Trace rules only: run the rules on model output on the prompt first, before generation. |
| `document.settings.resolve` | body | enum | no | `needed` (default) reads only the facts the deciding rule still needs; `ahead` also reads the same cost tier of later rules, one round sooner. One of `needed`, `ahead`. |
| `document.fallback` | body | object | no | The built-in fallback rows' outcomes, by row: what happens when no rule decides. A store's checkout rules have `covered` (a cart a token or mandate covers; Approve by default), `uncovered` (Challenge) and `after_approval` (an approved cart; Approve), each `approve`, `challenge` or `reject` (`approve`, `review` or `reject` after approval). Capture rules have `passes` (Approve) and `flagged` (Review), each `approve`, `review` or `reject`. Agent policies have `assess` (an action no rule decides; Approve by default), `approve`, `review` (ask a person) or `reject`. The rows always run last and are never deleted; a row left out keeps its built-in outcome. |
| `note` | body | string | no | A note for the record. |

### Returns

The draft, with `draft` true and its document. See [the policy version object](#object).

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`invalid_json`](https://provenanceauth.com/docs/platform/errors.md#invalid_json)
- [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid)
- [`plan_required`](https://provenanceauth.com/docs/platform/errors.md#plan_required)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`policy_invalid`](https://provenanceauth.com/docs/platform/errors.md#policy_invalid)
- [`manage_policies_required`](https://provenanceauth.com/docs/platform/errors.md#manage_policies_required)
- [`recent_two_factor_required`](https://provenanceauth.com/docs/platform/errors.md#recent_two_factor_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)
- [`route_invalid`](https://provenanceauth.com/docs/platform/errors.md#route_invalid)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -X POST "$PROVENANCE_API/v1/trace/policies/versions" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "note": "log every send",
    "document": {
      "rules": [
        {
          "id": "log-sends",
          "label": "Log sends",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "send"
            }
          ],
          "require": {
            "notify": {
              "webhook": true
            }
          }
        }
      ]
    }
  }'
curl -s -X DELETE "$PROVENANCE_API/v1/trace/policies" \
  -H "Authorization: Bearer $PROVENANCE_KEY" > /dev/null
```

**Node**

```ts
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/versions`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({
    "note": "log every send",
    "document": {
      "rules": [
        {
          "id": "log-sends",
          "label": "Log sends",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "send"
            }
          ],
          "require": {
            "notify": {
              "webhook": true
            }
          }
        }
      ]
    }
  }),
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
data = httpx.post(f"{api}/v1/trace/policies/versions", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={
    "note": "log every send",
    "document": {
        "rules": [
            {
                "id": "log-sends",
                "label": "Log sends",
                "when": [
                    {
                        "fact": "action.risk",
                        "op": "eq",
                        "value": "send"
                    }
                ],
                "require": {
                    "notify": {
                        "webhook": True
                    }
                }
            }
        ]
    }
}).json()
```

### Response 201

```json
{
  "object": "policy_version",
  "policy_id": "pol_956287817DE7DEF7A3C4E0C732",
  "version": 4,
  "active": false,
  "note": "log every send",
  "created_by": "key_01M8AD0FNZ22RQPEGR3JHXYWRG",
  "created_at": "2026-11-25T22:25:46.759Z",
  "draft": true,
  "source": "api",
  "domain": "trace",
  "document": {
    "rules": [
      {
        "id": "rul_01M8AD1887AGHTSMEW13FB7Y8H",
        "legacy_id": "log-sends",
        "when": [
          {
            "fact": "action.risk",
            "op": "eq",
            "value": "send"
          }
        ],
        "require": {
          "notify": {
            "webhook": true
          }
        },
        "label": "Log sends"
      }
    ]
  }
}
```

## Retrieve your Trace rules

`GET /v1/trace/policies`

Returns your active Trace rules, or the built-in default with `is_default` true: no rules, so every action is allowed.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

No parameters.

### Returns

The active Trace rules.

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl "$PROVENANCE_API/v1/trace/policies" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies`, {
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
data = httpx.get(f"{api}/v1/trace/policies", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}).json()
```

### Response 200

```json
{
  "object": "policy",
  "id": null,
  "domain": "trace",
  "document": {
    "rules": [
      {
        "id": "rul_default_trace_tripped",
        "label": "A canary family tripped",
        "when": [
          {
            "fact": "trace.tripped",
            "op": "eq",
            "value": true
          }
        ],
        "require": {
          "notify": {
            "webhook": true
          }
        },
        "phase": "completion"
      }
    ]
  },
  "version": null,
  "is_default": true
}
```

## Retrieve a Trace rule version

`GET /v1/trace/policies/versions/{version}`

Returns one saved Trace rule version's document. A draft that has not gone live carries `draft: true`, and `draft_group` when a rules embed session saved it in one.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `version` | path | integer | yes | The version number. |

### Returns

The version. See [the policy version object](#object).

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)
- [`resource_missing`](https://provenanceauth.com/docs/platform/errors.md#resource_missing)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -s -X PUT "$PROVENANCE_API/v1/trace/policies" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "note": "ask before paying after an injected email; never delete",
    "document": {
      "rules": [
        {
          "id": "injected-email-payments",
          "label": "Payments after an injected email",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "pay"
            },
            {
              "fact": "context.untrusted_sources",
              "op": "contains",
              "value": "email"
            },
            {
              "fact": "finding.categories",
              "op": "contains",
              "value": "indirect_injection"
            }
          ],
          "require": {
            "approval": true
          }
        },
        {
          "id": "no-deletes",
          "label": "Deletes",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "delete"
            }
          ],
          "require": {
            "deny": true,
            "lock": true
          }
        }
      ]
    }
  }' > step.json
export TRACE_POLICY_VERSION=$(jq -r '.version' step.json)
curl "$PROVENANCE_API/v1/trace/policies/versions/$TRACE_POLICY_VERSION" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
curl -s -X DELETE "$PROVENANCE_API/v1/trace/policies" \
  -H "Authorization: Bearer $PROVENANCE_KEY" > /dev/null
```

**Node**

```ts
const step1 = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies`, {
  method: "PUT",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({
    "note": "ask before paying after an injected email; never delete",
    "document": {
      "rules": [
        {
          "id": "injected-email-payments",
          "label": "Payments after an injected email",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "pay"
            },
            {
              "fact": "context.untrusted_sources",
              "op": "contains",
              "value": "email"
            },
            {
              "fact": "finding.categories",
              "op": "contains",
              "value": "indirect_injection"
            }
          ],
          "require": {
            "approval": true
          }
        },
        {
          "id": "no-deletes",
          "label": "Deletes",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "delete"
            }
          ],
          "require": {
            "deny": true,
            "lock": true
          }
        }
      ]
    }
  }),
})).json();
const tracePolicyVersion = step1.version;
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/versions/${tracePolicyVersion}`, {
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
step1 = httpx.put(f"{api}/v1/trace/policies", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={
    "note": "ask before paying after an injected email; never delete",
    "document": {
        "rules": [
            {
                "id": "injected-email-payments",
                "label": "Payments after an injected email",
                "when": [
                    {
                        "fact": "action.risk",
                        "op": "eq",
                        "value": "pay"
                    },
                    {
                        "fact": "context.untrusted_sources",
                        "op": "contains",
                        "value": "email"
                    },
                    {
                        "fact": "finding.categories",
                        "op": "contains",
                        "value": "indirect_injection"
                    }
                ],
                "require": {
                    "approval": True
                }
            },
            {
                "id": "no-deletes",
                "label": "Deletes",
                "when": [
                    {
                        "fact": "action.risk",
                        "op": "eq",
                        "value": "delete"
                    }
                ],
                "require": {
                    "deny": True,
                    "lock": True
                }
            }
        ]
    }
}).json()
trace_policy_version = step1["version"]
data = httpx.get(f"{api}/v1/trace/policies/versions/{trace_policy_version}", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}).json()
```

### Response 200

```json
{
  "object": "policy_version",
  "domain": "trace",
  "version": 3,
  "active": true,
  "document": {
    "rules": [
      {
        "id": "rul_01M8AD18814Z7YZAN1KM1D5677",
        "legacy_id": "injected-email-payments",
        "when": [
          {
            "fact": "action.risk",
            "op": "eq",
            "value": "pay"
          },
          {
            "fact": "context.untrusted_sources",
            "op": "contains",
            "value": "email"
          },
          {
            "fact": "finding.categories",
            "op": "contains",
            "value": "indirect_injection"
          }
        ],
        "require": {
          "approval": true
        },
        "label": "Payments after an injected email"
      },
      {
        "id": "rul_01M8AD18819JWTF7QAXS4745V5",
        "legacy_id": "no-deletes",
        "when": [
          {
            "fact": "action.risk",
            "op": "eq",
            "value": "delete"
          }
        ],
        "require": {
          "deny": true,
          "lock": true
        },
        "label": "Deletes"
      }
    ]
  },
  "note": "ask before paying after an injected email; never delete",
  "created_at": "2026-11-25T22:25:46.756Z"
}
```

## Get a Trace rule version's plan

`GET /v1/trace/policies/versions/{version}/plan`

The version compiled into its plan: each rule's facts with what reading them costs (the request and token, your own records, a network call or a model call), cheapest first, and warnings for a fact this rule set can't read, an operator that never matches its fact, or a rule that's never reached.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `version` | path | integer | yes | The version number. |

### Returns

The plan.

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)
- [`resource_missing`](https://provenanceauth.com/docs/platform/errors.md#resource_missing)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -s -X POST "$PROVENANCE_API/v1/trace/policies/versions" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "note": "log every send",
    "document": {
      "rules": [
        {
          "id": "log-sends",
          "label": "Log sends",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "send"
            }
          ],
          "require": {
            "notify": {
              "webhook": true
            }
          }
        }
      ]
    }
  }' > step.json
export TRACE_POLICY_VERSION=$(jq -r '.version' step.json)
curl "$PROVENANCE_API/v1/trace/policies/versions/$TRACE_POLICY_VERSION/plan" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
curl -s -X DELETE "$PROVENANCE_API/v1/trace/policies" \
  -H "Authorization: Bearer $PROVENANCE_KEY" > /dev/null
```

**Node**

```ts
const step1 = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/versions`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({
    "note": "log every send",
    "document": {
      "rules": [
        {
          "id": "log-sends",
          "label": "Log sends",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "send"
            }
          ],
          "require": {
            "notify": {
              "webhook": true
            }
          }
        }
      ]
    }
  }),
})).json();
const tracePolicyVersion = step1.version;
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/versions/${tracePolicyVersion}/plan`, {
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
step1 = httpx.post(f"{api}/v1/trace/policies/versions", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={
    "note": "log every send",
    "document": {
        "rules": [
            {
                "id": "log-sends",
                "label": "Log sends",
                "when": [
                    {
                        "fact": "action.risk",
                        "op": "eq",
                        "value": "send"
                    }
                ],
                "require": {
                    "notify": {
                        "webhook": True
                    }
                }
            }
        ]
    }
}).json()
trace_policy_version = step1["version"]
data = httpx.get(f"{api}/v1/trace/policies/versions/{trace_policy_version}/plan", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}).json()
```

### Response 200

```json
{
  "object": "policy_plan",
  "domain": "trace",
  "version": 9,
  "plan_hash": "0a558b72f9ec7bbc548dc723c5d233bb2e37bc89dcc00b5baa54ec77632800a4",
  "node_count": 5,
  "reads": [
    {
      "fact": "action.risk",
      "tier": 0,
      "provider": "request"
    }
  ],
  "rules": [
    {
      "id": "rul_01M8V3CX9F1YQ490MZJEXVPKGV",
      "tier": 0,
      "reads": [
        {
          "fact": "action.risk",
          "tier": 0,
          "provider": "request"
        }
      ]
    }
  ],
  "nodes": [
    {
      "id": "fact:action.risk",
      "kind": "fact",
      "tier": 0,
      "reads": [],
      "fact": "action.risk"
    },
    {
      "id": "cond:rul_01M8V3CX9F1YQ490MZJEXVPKGV:0",
      "kind": "condition",
      "tier": 0,
      "reads": [
        "fact:action.risk"
      ]
    },
    {
      "id": "group:rul_01M8V3CX9F1YQ490MZJEXVPKGV:when",
      "kind": "group",
      "tier": 0,
      "reads": [
        "cond:rul_01M8V3CX9F1YQ490MZJEXVPKGV:0"
      ],
      "match": "all"
    },
    {
      "id": "rule:rul_01M8V3CX9F1YQ490MZJEXVPKGV",
      "kind": "rule",
      "tier": 0,
      "reads": [
        "group:rul_01M8V3CX9F1YQ490MZJEXVPKGV:when"
      ]
    },
    {
      "id": "outcome",
      "kind": "outcome",
      "tier": 0,
      "reads": [
        "rule:rul_01M8V3CX9F1YQ490MZJEXVPKGV"
      ]
    }
  ],
  "warnings": [],
  "approve_on_tier3_only": []
}
```

## Get the trial run

`GET /v1/trace/policies/trial`

The trial run now: its draft version, when it ends, how many trace assessments it ran beside the live rules and where it would have decided differently (from the shadow outcome each assessment records).

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

No parameters.

### Returns

The trial run.

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl "$PROVENANCE_API/v1/trace/policies/trial" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/trial`, {
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
data = httpx.get(f"{api}/v1/trace/policies/trial", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}).json()
```

### Response 200

```json
{
  "object": "policy_trial",
  "domain": "trace",
  "active": false,
  "version": null
}
```

## Get the Trace rules shadow report

`GET /v1/trace/policies/shadow_report`

Where the shadow version would have decided differently from the live Trace rules, over the trace assessments that recorded a shadow outcome (`transitions` counts each live → shadow change).

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `created_gte` | query | timestamp | no | The start of the time window, as an ISO 8601 time. |
| `created_lte` | query | timestamp | no | The end of the time window, as an ISO 8601 time. |

### Returns

The shadow report.

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl "$PROVENANCE_API/v1/trace/policies/shadow_report" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/shadow_report`, {
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
data = httpx.get(f"{api}/v1/trace/policies/shadow_report", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}).json()
```

### Response 200

```json
{
  "object": "shadow_report",
  "domain": "trace",
  "shadow_active": false,
  "shadow_version": null,
  "from": null,
  "to": null,
  "evaluated": 0,
  "diverged": 0,
  "divergence_rate": 0,
  "transitions": {}
}
```

## Get rule performance

`GET /v1/trace/policies/performance`

Trace policies don't offer rule performance yet (checkout policies do): this answers 400 `policy_feature_unsupported`. The route is here so every policy has the same routes.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `from` | query | string | no | The first UTC day, YYYY-MM-DD (default: 29 days before `to`). |
| `to` | query | string | no | The last UTC day, YYYY-MM-DD (default: today). A window covers at most 366 days. |
| `version` | query | integer | no | Only the decisions this version made (default: every version in the window, in the live version's rule order). |
| `currency` | query | string | no | The ISO 4217 currency values are summed in (default: the one with the most orders). |

### Returns

The rule set's totals and each rule's numbers.

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`policy_feature_unsupported`](https://provenanceauth.com/docs/platform/errors.md#policy_feature_unsupported)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl "$PROVENANCE_API/v1/trace/policies/performance" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/performance`, {
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
data = httpx.get(f"{api}/v1/trace/policies/performance", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}).json()
```

### Response 200

```json
{
  "object": "policy_performance",
  "domain": "checkout",
  "from": "2026-11-03",
  "to": "2026-12-02",
  "version": null,
  "currency": "USD",
  "other_currencies": [],
  "totals": {
    "matched": 1,
    "value_minor": 3800,
    "outcomes": [
      {
        "outcome": "approve",
        "count": 0,
        "value_minor": 0,
        "currency": "USD",
        "share": 0
      },
      {
        "outcome": "challenge",
        "count": 1,
        "value_minor": 3800,
        "currency": "USD",
        "share": 1
      },
      {
        "outcome": "reject",
        "count": 0,
        "value_minor": 0,
        "currency": "USD",
        "share": 0
      }
    ],
    "results": {
      "true_positive": {
        "count": 0,
        "value_minor": 0,
        "currency": "USD"
      },
      "false_positive": {
        "count": 0,
        "value_minor": 0,
        "currency": "USD"
      },
      "missed": {
        "count": 0,
        "value_minor": 0,
        "currency": "USD"
      },
      "allowed": {
        "count": 0,
        "value_minor": 0,
        "currency": "USD"
      },
      "unlabelled": {
        "count": 1,
        "value_minor": 3800,
        "currency": "USD"
      }
    },
    "labelled": 0,
    "enough_labels": false
  },
  "rules": [
    {
      "rule_id": "fallback",
      "name": null,
      "outcomes": [
        "challenge"
      ],
      "matched": 1,
      "value_minor": 3800,
      "results": {
        "true_positive": {
          "count": 0,
          "value_minor": 0,
          "currency": "USD"
        },
        "false_positive": {
          "count": 0,
          "value_minor": 0,
          "currency": "USD"
        },
        "missed": {
          "count": 0,
          "value_minor": 0,
          "currency": "USD"
        },
        "allowed": {
          "count": 0,
          "value_minor": 0,
          "currency": "USD"
        },
        "unlabelled": {
          "count": 1,
          "value_minor": 3800,
          "currency": "USD"
        }
      }
    }
  ],
  "labels_note": "A rejected order has no outcome, so rejections count only when a label says whether they were right; the rest show as No label yet."
}
```

## List Trace rule versions

`GET /v1/trace/policies/versions`

Lists your saved Trace rule versions, newest first, and which is active.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `limit` | query | integer | no | Page size, 1–100 (default 20). Outside the range → 400 parameter_invalid. |
| `cursor` | query | string | no | Opaque; pass a response's `next_cursor` back to get the next page. |

### Returns

The versions, newest first.

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -s -X PUT "$PROVENANCE_API/v1/trace/policies" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "note": "ask before paying after an injected email; never delete",
    "document": {
      "rules": [
        {
          "id": "injected-email-payments",
          "label": "Payments after an injected email",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "pay"
            },
            {
              "fact": "context.untrusted_sources",
              "op": "contains",
              "value": "email"
            },
            {
              "fact": "finding.categories",
              "op": "contains",
              "value": "indirect_injection"
            }
          ],
          "require": {
            "approval": true
          }
        },
        {
          "id": "no-deletes",
          "label": "Deletes",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "delete"
            }
          ],
          "require": {
            "deny": true,
            "lock": true
          }
        }
      ]
    }
  }' > step.json
export TRACE_POLICY_VERSION=$(jq -r '.version' step.json)
curl "$PROVENANCE_API/v1/trace/policies/versions" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
curl -s -X DELETE "$PROVENANCE_API/v1/trace/policies" \
  -H "Authorization: Bearer $PROVENANCE_KEY" > /dev/null
```

**Node**

```ts
const step1 = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies`, {
  method: "PUT",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({
    "note": "ask before paying after an injected email; never delete",
    "document": {
      "rules": [
        {
          "id": "injected-email-payments",
          "label": "Payments after an injected email",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "pay"
            },
            {
              "fact": "context.untrusted_sources",
              "op": "contains",
              "value": "email"
            },
            {
              "fact": "finding.categories",
              "op": "contains",
              "value": "indirect_injection"
            }
          ],
          "require": {
            "approval": true
          }
        },
        {
          "id": "no-deletes",
          "label": "Deletes",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "delete"
            }
          ],
          "require": {
            "deny": true,
            "lock": true
          }
        }
      ]
    }
  }),
})).json();
const tracePolicyVersion = step1.version;
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/versions`, {
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
step1 = httpx.put(f"{api}/v1/trace/policies", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={
    "note": "ask before paying after an injected email; never delete",
    "document": {
        "rules": [
            {
                "id": "injected-email-payments",
                "label": "Payments after an injected email",
                "when": [
                    {
                        "fact": "action.risk",
                        "op": "eq",
                        "value": "pay"
                    },
                    {
                        "fact": "context.untrusted_sources",
                        "op": "contains",
                        "value": "email"
                    },
                    {
                        "fact": "finding.categories",
                        "op": "contains",
                        "value": "indirect_injection"
                    }
                ],
                "require": {
                    "approval": True
                }
            },
            {
                "id": "no-deletes",
                "label": "Deletes",
                "when": [
                    {
                        "fact": "action.risk",
                        "op": "eq",
                        "value": "delete"
                    }
                ],
                "require": {
                    "deny": True,
                    "lock": True
                }
            }
        ]
    }
}).json()
trace_policy_version = step1["version"]
data = httpx.get(f"{api}/v1/trace/policies/versions", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}).json()
```

### Response 200

```json
{
  "object": "list",
  "data": [
    {
      "object": "policy_version",
      "policy_id": "pol_956287817DE7DEF7A3C4E0C732",
      "version": 2,
      "active": true,
      "note": "ask before paying after an injected email; never delete",
      "created_by": "key_01M8AD0FNZ22RQPEGR3JHXYWRG",
      "created_at": "2026-11-25T22:25:46.754Z",
      "source": "api",
      "key_last4": "1kR5",
      "domain": "trace"
    },
    {
      "object": "policy_version",
      "policy_id": "pol_956287817DE7DEF7A3C4E0C732",
      "version": 1,
      "active": false,
      "note": "ask before paying after an injected email; never delete",
      "created_by": "key_01M8AD0FNZ22RQPEGR3JHXYWRG",
      "created_at": "2026-11-25T22:25:46.753Z",
      "source": "api",
      "key_last4": "1kR5",
      "domain": "trace"
    }
  ],
  "has_more": false,
  "next_cursor": null
}
```

## List the records a backtest would change

`GET /v1/trace/policies/backtest/{id}/changes`

Backtests of trace rules keep no changed records yet (checkout and agent policies do), so no backtest has an id to read here: this answers 404 `resource_missing`, or 400 `policy_feature_unsupported` where the policy has no backtest. The route is here so every policy has the same routes.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The backtest's id (`pbt_…`), from `POST …/backtest`. |
| `limit` | query | integer | no | Page size, 1–100 (default 20). Outside the range → 400 parameter_invalid. |
| `cursor` | query | string | no | Opaque; pass a response's `next_cursor` back to get the next page. |

### Returns

One page of the records that would change.

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`policy_feature_unsupported`](https://provenanceauth.com/docs/platform/errors.md#policy_feature_unsupported)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)
- [`resource_missing`](https://provenanceauth.com/docs/platform/errors.md#resource_missing)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl "$PROVENANCE_API/v1/trace/policies/backtest/pbt_01M8WMKZJ4EZ1EWXVEN3N4HE9R/changes" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/backtest/pbt_01M8WMKZJ4EZ1EWXVEN3N4HE9R/changes`, {
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
data = httpx.get(f"{api}/v1/trace/policies/backtest/pbt_01M8WMKZJ4EZ1EWXVEN3N4HE9R/changes", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}).json()
```

### Response 200

```json
{
  "object": "list",
  "data": [
    {
      "id": "cas_01M81CRZ5CX8S238KB791A7JB0",
      "kind": "checkout_assessment",
      "created_at": "2026-12-01T18:05:02.794Z",
      "value_minor": 124000,
      "currency": "USD",
      "live": "challenge",
      "draft": "reject",
      "live_rule_id": "first-order-over-500",
      "draft_rule_id": "two-risk-signs",
      "label": "disputed",
      "live_result": "true_positive",
      "draft_result": "true_positive"
    }
  ],
  "has_more": false,
  "next_cursor": null,
  "total": 1,
  "capped": false,
  "policy_version": 13
}
```

## Publish your Trace rules

`PUT /v1/trace/policies`

Saves your Trace rules as the next version, live at once (`trace.policy.published`). A rule runs at `phase: "action"` (before a tool call, the default) or `"completion"`; the first match decides: Allow, Challenge or Review (`approval`, Review with a `route`), Reject, or Log (`notify`). `settings.if_unavailable` and `fallback.action` are described in the Trace rules guide.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `document` | body | object | yes | The rules, `settings` and `fallback`. Each rule: `when` over Trace facts (`canary`, `trace.*`, `finding.*`, `action.*`, `context.untrusted_sources`, `agent_id`, `run.*`), `require`, and optionally `phase`, `if_unavailable`, `label`, `reason`. |
| `document.rules` | body | array of objects | no | The rules in the order they run. |
| `document.settings` | body | object | no | Settings that apply to every rule. |
| `document.settings.if_unavailable` | body | enum | no | What an unavailable Trace finding means for every rule (default `fail_closed`). One of `fail_closed`, `fail_open`. |
| `document.fallback` | body | object | no | The fallback row's outcome. |
| `document.fallback.action` | body | enum | no | The fallback row, "Otherwise" (default `approve`: allow). One of `approve`, `review`, `reject`. |
| `note` | body | string | no | A note for the record. |

### Returns

The new version, now active. See [the policy version object](#object).

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`invalid_json`](https://provenanceauth.com/docs/platform/errors.md#invalid_json)
- [`plan_required`](https://provenanceauth.com/docs/platform/errors.md#plan_required)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`policy_invalid`](https://provenanceauth.com/docs/platform/errors.md#policy_invalid)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -X PUT "$PROVENANCE_API/v1/trace/policies" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "note": "ask before paying after an injected email; never delete",
    "document": {
      "rules": [
        {
          "id": "injected-email-payments",
          "label": "Payments after an injected email",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "pay"
            },
            {
              "fact": "context.untrusted_sources",
              "op": "contains",
              "value": "email"
            },
            {
              "fact": "finding.categories",
              "op": "contains",
              "value": "indirect_injection"
            }
          ],
          "require": {
            "approval": true
          }
        },
        {
          "id": "no-deletes",
          "label": "Deletes",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "delete"
            }
          ],
          "require": {
            "deny": true,
            "lock": true
          }
        }
      ]
    }
  }'
curl -s -X DELETE "$PROVENANCE_API/v1/trace/policies" \
  -H "Authorization: Bearer $PROVENANCE_KEY" > /dev/null
```

**Node**

```ts
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies`, {
  method: "PUT",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({
    "note": "ask before paying after an injected email; never delete",
    "document": {
      "rules": [
        {
          "id": "injected-email-payments",
          "label": "Payments after an injected email",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "pay"
            },
            {
              "fact": "context.untrusted_sources",
              "op": "contains",
              "value": "email"
            },
            {
              "fact": "finding.categories",
              "op": "contains",
              "value": "indirect_injection"
            }
          ],
          "require": {
            "approval": true
          }
        },
        {
          "id": "no-deletes",
          "label": "Deletes",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "delete"
            }
          ],
          "require": {
            "deny": true,
            "lock": true
          }
        }
      ]
    }
  }),
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
data = httpx.put(f"{api}/v1/trace/policies", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={
    "note": "ask before paying after an injected email; never delete",
    "document": {
        "rules": [
            {
                "id": "injected-email-payments",
                "label": "Payments after an injected email",
                "when": [
                    {
                        "fact": "action.risk",
                        "op": "eq",
                        "value": "pay"
                    },
                    {
                        "fact": "context.untrusted_sources",
                        "op": "contains",
                        "value": "email"
                    },
                    {
                        "fact": "finding.categories",
                        "op": "contains",
                        "value": "indirect_injection"
                    }
                ],
                "require": {
                    "approval": True
                }
            },
            {
                "id": "no-deletes",
                "label": "Deletes",
                "when": [
                    {
                        "fact": "action.risk",
                        "op": "eq",
                        "value": "delete"
                    }
                ],
                "require": {
                    "deny": True,
                    "lock": True
                }
            }
        ]
    }
}).json()
```

### Response 201

```json
{
  "object": "policy_version",
  "policy_id": "pol_956287817DE7DEF7A3C4E0C732",
  "domain": "trace",
  "version": 1,
  "active": true,
  "note": "ask before paying after an injected email; never delete",
  "created_at": "2026-11-25T22:25:46.753Z",
  "document": {
    "rules": [
      {
        "id": "rul_01M8AD18814Z7YZAN1KM1D5677",
        "legacy_id": "injected-email-payments",
        "when": [
          {
            "fact": "action.risk",
            "op": "eq",
            "value": "pay"
          },
          {
            "fact": "context.untrusted_sources",
            "op": "contains",
            "value": "email"
          },
          {
            "fact": "finding.categories",
            "op": "contains",
            "value": "indirect_injection"
          }
        ],
        "require": {
          "approval": true
        },
        "label": "Payments after an injected email"
      },
      {
        "id": "rul_01M8AD18819JWTF7QAXS4745V5",
        "legacy_id": "no-deletes",
        "when": [
          {
            "fact": "action.risk",
            "op": "eq",
            "value": "delete"
          }
        ],
        "require": {
          "deny": true,
          "lock": true
        },
        "label": "Deletes"
      }
    ]
  }
}
```

## Revert to no Trace rules

`DELETE /v1/trace/policies`

Deactivates your Trace rules (history is kept) and returns the built-in default: no rules.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

No parameters.

### Returns

The built-in default, now active.

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -X DELETE "$PROVENANCE_API/v1/trace/policies" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies`, {
  method: "DELETE",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
data = httpx.delete(f"{api}/v1/trace/policies", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}).json()
```

### Response 200

```json
{
  "object": "policy",
  "id": null,
  "domain": "trace",
  "document": {
    "rules": [
      {
        "id": "rul_default_trace_tripped",
        "label": "A canary family tripped",
        "when": [
          {
            "fact": "trace.tripped",
            "op": "eq",
            "value": true
          }
        ],
        "require": {
          "notify": {
            "webhook": true
          }
        },
        "phase": "completion"
      }
    ]
  },
  "version": null,
  "is_default": true
}
```

## Review a Trace rule version's changes

`GET /v1/trace/policies/versions/{version}/diff`

Compares a version with the live rules (or `against`, another version), rule by rule, in words.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `version` | path | integer | yes | The version number. |
| `against` | query | string | no | `active` (the default) or another version number to compare with. |

### Returns

The changes.

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)
- [`resource_missing`](https://provenanceauth.com/docs/platform/errors.md#resource_missing)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -s -X POST "$PROVENANCE_API/v1/trace/policies/versions" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "note": "log every send",
    "document": {
      "rules": [
        {
          "id": "log-sends",
          "label": "Log sends",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "send"
            }
          ],
          "require": {
            "notify": {
              "webhook": true
            }
          }
        }
      ]
    }
  }' > step.json
export TRACE_POLICY_VERSION=$(jq -r '.version' step.json)
curl "$PROVENANCE_API/v1/trace/policies/versions/$TRACE_POLICY_VERSION/diff" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
curl -s -X DELETE "$PROVENANCE_API/v1/trace/policies" \
  -H "Authorization: Bearer $PROVENANCE_KEY" > /dev/null
```

**Node**

```ts
const step1 = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/versions`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({
    "note": "log every send",
    "document": {
      "rules": [
        {
          "id": "log-sends",
          "label": "Log sends",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "send"
            }
          ],
          "require": {
            "notify": {
              "webhook": true
            }
          }
        }
      ]
    }
  }),
})).json();
const tracePolicyVersion = step1.version;
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/versions/${tracePolicyVersion}/diff`, {
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
step1 = httpx.post(f"{api}/v1/trace/policies/versions", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={
    "note": "log every send",
    "document": {
        "rules": [
            {
                "id": "log-sends",
                "label": "Log sends",
                "when": [
                    {
                        "fact": "action.risk",
                        "op": "eq",
                        "value": "send"
                    }
                ],
                "require": {
                    "notify": {
                        "webhook": True
                    }
                }
            }
        ]
    }
}).json()
trace_policy_version = step1["version"]
data = httpx.get(f"{api}/v1/trace/policies/versions/{trace_policy_version}/diff", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}).json()
```

### Response 200

```json
{
  "object": "policy_diff",
  "domain": "trace",
  "version": 5,
  "against": null,
  "changes": [
    {
      "rule_id": "rul_01M8AD1887AGHTSMEW13FB7Y8H",
      "label": "Log sends",
      "change": "added",
      "parts": [],
      "before": null,
      "after": "Log sends"
    }
  ]
}
```

## Publish a Trace rule version

`POST /v1/trace/policies/versions/{version}/publish`

Makes a saved version live now. Trial runs (`trial_days`) come to Trace rules with shadow mode; until then `trial_days` answers 400 `policy_feature_unsupported`. Sends `trace.policy.published`.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Retry a create safely: the same key + request returns the stored response (24 h, per caller). |
| `version` | path | integer | yes | The version number. |
| `trial_days` | body | integer | no | Run the draft silently next to the live version for this many days instead of publishing now. |

### Returns

The live version, or the trial run when `trial_days` is set.

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`invalid_json`](https://provenanceauth.com/docs/platform/errors.md#invalid_json)
- [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid)
- [`plan_required`](https://provenanceauth.com/docs/platform/errors.md#plan_required)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`manage_policies_required`](https://provenanceauth.com/docs/platform/errors.md#manage_policies_required)
- [`recent_two_factor_required`](https://provenanceauth.com/docs/platform/errors.md#recent_two_factor_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)
- [`resource_missing`](https://provenanceauth.com/docs/platform/errors.md#resource_missing)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -s -X POST "$PROVENANCE_API/v1/trace/policies/versions" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "note": "log every send",
    "document": {
      "rules": [
        {
          "id": "log-sends",
          "label": "Log sends",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "send"
            }
          ],
          "require": {
            "notify": {
              "webhook": true
            }
          }
        }
      ]
    }
  }' > step.json
export TRACE_POLICY_VERSION=$(jq -r '.version' step.json)
curl -X POST "$PROVENANCE_API/v1/trace/policies/versions/$TRACE_POLICY_VERSION/publish" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
curl -s -X DELETE "$PROVENANCE_API/v1/trace/policies" \
  -H "Authorization: Bearer $PROVENANCE_KEY" > /dev/null
```

**Node**

```ts
const step1 = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/versions`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({
    "note": "log every send",
    "document": {
      "rules": [
        {
          "id": "log-sends",
          "label": "Log sends",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "send"
            }
          ],
          "require": {
            "notify": {
              "webhook": true
            }
          }
        }
      ]
    }
  }),
})).json();
const tracePolicyVersion = step1.version;
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/versions/${tracePolicyVersion}/publish`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
step1 = httpx.post(f"{api}/v1/trace/policies/versions", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={
    "note": "log every send",
    "document": {
        "rules": [
            {
                "id": "log-sends",
                "label": "Log sends",
                "when": [
                    {
                        "fact": "action.risk",
                        "op": "eq",
                        "value": "send"
                    }
                ],
                "require": {
                    "notify": {
                        "webhook": True
                    }
                }
            }
        ]
    }
}).json()
trace_policy_version = step1["version"]
data = httpx.post(f"{api}/v1/trace/policies/versions/{trace_policy_version}/publish", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}).json()
```

### Response 200

```json
{
  "object": "policy_version",
  "policy_id": "pol_956287817DE7DEF7A3C4E0C732",
  "version": 6,
  "active": true,
  "note": "log every send",
  "created_by": "key_01M8AD0FNZ22RQPEGR3JHXYWRG",
  "created_at": "2026-11-25T22:25:46.762Z",
  "source": "api",
  "domain": "trace"
}
```

## Export Trace rule versions

`GET /v1/trace/policies/versions/export`

Every version with its document (Enterprise).

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

No parameters.

### Returns

Every version.

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`plan_required`](https://provenanceauth.com/docs/platform/errors.md#plan_required)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_ent_E7nT2vQ9bW4mK8sYd3cFjLh6gAe1pR5x
curl "$PROVENANCE_API/v1/trace/policies/versions/export" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/versions/export`, {
  headers: { Authorization: "Bearer prv_test_ent_E7nT2vQ9bW4mK8sYd3cFjLh6gAe1pR5x" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
data = httpx.get(f"{api}/v1/trace/policies/versions/export", headers={"Authorization": "Bearer prv_test_ent_E7nT2vQ9bW4mK8sYd3cFjLh6gAe1pR5x"}).json()
```

### Response 200

```json
{
  "object": "policy_version_export",
  "domain": "trace",
  "exported_at": "2026-11-16T18:02:11.204Z",
  "versions": [
    {
      "object": "policy_version",
      "version": 1,
      "active": true,
      "note": "review photos far from the loss, reject mock locations",
      "created_by": "usr_01M6VQBCTY8NPW81EFB7PMWCDK",
      "created_at": "2026-11-16T17:58:40.112Z",
      "domain": "trace",
      "document": {
        "rules": [
          {
            "id": "far-from-loss",
            "label": "More than 5 km from the loss address",
            "when": [
              {
                "fact": "capture.min_distance_km.loss_address",
                "op": "gt",
                "value": 5
              }
            ],
            "require": {
              "approval": true
            }
          }
        ]
      }
    }
  ]
}
```

## Backtest Trace rules

`POST /v1/trace/policies/backtest`

Replays a document over the last 30 days (or `days`): model-output rules over recent traced inferences and sidecar readings, action rules over recorded trace assessments. Each rule gives its stage, matches, decisions, money by currency and `labelled_false` (matches a person marked a false signal).

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Retry a create safely: the same key + request returns the stored response (24 h, per caller). |
| `document` | body | object | no | A policy document: ordered rules, in one format for an agent policy, a store's checkout rules and a person's own rules. |
| `document.rules` | body | array of objects | yes | The rules, in order (at most 50; up to 200 on Enterprise). |
| `document.rules.id` | body | string | no | The rule's ID, set by Provenance: `rul_` and a ULID, given when the rule is first saved and kept in every later version while the rule exists; a default row has a fixed `rul_default_…` ID, the same in every account. Leave it out of a new rule, and send a saved rule back with its ID to keep it. A `rul_` ID the policy never had is replaced with a new one. Any other value is kept as `legacy_id` and names the same rule when sent again. The `rul_default_` prefix is reserved for the default rows (`400 policy_invalid`). A person's own rules and the risk policies keep their IDs as written. Always present on a read. |
| `document.rules.ref` | body | string | no | Set by Provenance: the rule's short display ID (`R-103`, or `R-04` outside checkout), shown beside the rule in the console and on every decision as `policy.rule.ref`. Kept across versions and never reused in the policy. What you send here is ignored. |
| `document.rules.legacy_id` | body | string | no | Set by Provenance: the ID the rule had before rule IDs were set by Provenance (November 2026), or the value it was first written with. A decision recorded with that ID still finds the rule. What you send here is ignored. |
| `document.rules.group` | body | string | no | The rule group (`groups[].key`) this rule belongs to. It still runs in order as an ordinary rule. |
| `document.rules.label` | body | string | no | The rule's name, such as `Orders over $500`. Evaluation never reads it. |
| `document.rules.when` | body | array of objects \| object | yes | A rule's or signal's IF part. Either a list of conditions that must all match, or an object that picks a mode over conditions and groups (groups nest to three levels with the rule's own; at most 10 items in a group and 20 conditions in all). |
| `document.rules.when.match` | body | enum | no | Whether all, any, none or at least `n` of the items must match (`none` holds when no item does). One of `all`, `any`, `none`, `at_least`. |
| `document.rules.when.n` | body | integer | no | With `match: at_least`: how many items must match (1 to the item count). |
| `document.rules.when.items` | body | array of objects | no | Conditions and groups (at most 10). |
| `document.rules.when.items.fact` | body | string | no | The fact the condition reads (`transaction_amount`, `order.amount`, `agent.verified`), or `field` to read `path` from the request. |
| `document.rules.when.items.op` | body | enum | no | The comparison operator. A field condition takes the comparisons, `in`, `matches`, `contains`, `contains_any`, `is_empty` and `is_not_empty`. Every operator except the two null operators fails to match a missing or null fact, `ne` included. `is_empty` matches a fact that is missing, null, an empty string or an empty list; `is_not_empty` matches any other value. |
| `document.rules.when.items.value` | body | any | no | The value to compare with (a string, number, boolean or a list of them). `is_empty` and `is_not_empty` take `true`. |
| `document.rules.when.items.path` | body | string | no | With `fact: field`: up to 6 dotted names, each optionally followed by `[]` for every element of a list (at most one `[]`), such as `metadata.cost_center` or `order.items[].sku`. |
| `document.rules.when.items.items` | body | enum | no | With a path through a list: whether any element (the default) or every element must match. One of `any`, `all`. |
| `document.rules.when.items.metric` | body | enum | no | With `fact: velocity`: what is counted. One of `verify_count`, `amount_sum`. |
| `document.rules.when.items.window` | body | enum | no | With `fact: velocity`: the window. `1h` and `24h` are rolling; `month` is the calendar month in UTC, counted per `account` or `agent`. One of `1h`, `24h`, `month`. |
| `document.rules.when.items.per` | body | enum | no | With `fact: velocity`: what it is counted per. `agent` is the registered agent the token names (none: 0). One of `device`, `session`, `account`, `agent`. |
| `document.rules.when.items.set` | body | string | no | With `fact: canary` or `prediction`: the canary family or probe. |
| `document.rules.when.items.best_effort` | body | boolean | no | With a canary or probe: an unavailable reading evaluates false instead of failing closed. |
| `document.rules.when.items.baseline` | body | enum | no | With `z_gt` or `pct_gt`: the baseline the score is compared against. One of `agent`, `account`. |
| `document.rules.when.items.if_unavailable` | body | enum | no | What an unavailable reading means for this condition: `skip` (no match), `match`, or `ask` (match and ask a person). `ignore` is an external risk fact's older word for `skip`; a capture fact or Trace finding takes `skip` or `match`. One of `skip`, `match`, `ask`, `ignore`. |
| `document.rules.when.items.match` | body | enum | no | Whether all, any, none or at least `n` of the group's items must match (`none` holds when no item does; a condition on a missing fact doesn't hold). One of `all`, `any`, `none`, `at_least`. |
| `document.rules.when.items.n` | body | integer | no | With `match: at_least`: how many items must match (1 to the item count). N-of-M. |
| `document.rules.when.items.conditions` | body | array of objects | no | The group's conditions and groups (1 to 10). |
| `document.rules.require` | body | object | yes | A rule's THEN part: `deny` blocks, `approval` asks a person, `biometric`, `hardware` or `min_tier` ask for stronger proof, `webhook` asks your webhook, and `notify` (alone) allows and notifies. On your checkout and card issuer rules, `no_challenge` (alone) approves (Capture and Trace rules say `frictionless`), and on an after-approval rule `review` (alone) holds the order for your review. |
| `document.rules.require.review` | body | enum | no | Checkout rules with `phase: after_approval` only, set alone: Review. The customer approved, and the order waits for your decision (`status: in_review`, no token yet) until you approve or reject it, or it times out. One of `true`. |
| `document.rules.require.no_challenge` | body | enum | no | Checkout rules (`/v1/authorize/policies`) and card issuer rules, set alone: Approve. When the rule matches, the cart is approved (`allow`, reason `policy_rule_approved`) and no later rule runs, whether or not a token, mandate or earlier approval covers it. A cart nothing covers gets no token. A write may also send `frictionless`. One of `true`. |
| `document.rules.require.frictionless` | body | enum | no | Capture and Trace rules, set alone: Approve (Allow). On checkout and card issuer rules, an older word for `no_challenge`, still accepted on a write. When a checkout rule matches, the cart is approved (`allow`, reason `policy_rule_approved`) and no later rule runs, whether or not a token, mandate or earlier approval covers it. A cart nothing covers gets no token. One of `true`. |
| `document.rules.require.ucp_fallback` | body | enum | no | Checkout rules only, with `approval: true` before approval: what a Universal Commerce Protocol checkout does when the platform didn't negotiate the approval Action. `escalate` (the default) hands the checkout to your checkout page; `hold_after_order` opens the approval and you hold the order until it is approved. One of `escalate`, `hold_after_order`. |
| `document.rules.require.deny` | body | boolean | no | Block the request; the rule's `reason` is what the agent sees. |
| `document.rules.require.lock` | body | enum \| object | no | Trace rules only, with `deny` or `approval`: lock the agent session (`true` or `scope: session`), the registered agent (`agent`) or the run (`run`) until a person clears it; `revoke_session` also revokes the session's intent tokens. |
| `document.rules.require.lock.scope` | body | enum | no | What the lock names. One of `session`, `agent`, `run`. |
| `document.rules.require.lock.revoke_session` | body | enum | no | Also revoke the session's intent tokens. One of `true`. |
| `document.rules.require.suspend_agent` | body | enum | no | Trace rules only, with `deny`: suspend the registered agent. One of `true`. |
| `document.rules.require.sample_rate` | body | integer | no | Spot checks, on a Reject rule (`deny`) of checkout, agent, capture or Trace rules (Trace at phase `action` only): 1 in N of the records it would reject is asked about instead (Challenge; a capture shot goes to In review, a Trace action to Review), chosen from the record id. Card issuer rules and Trace rules at phase `completion` refuse it: nobody can answer in time. Off unless set. |
| `document.rules.require.flow` | body | string | no | Checkout and agent rules: the rule takes this sub-flow's outcome as its own (a key in the document's `flows`). The flow's `none` passes to the next rule. Takes no other requirement. |
| `document.rules.require.approval` | body | boolean | no | Ask a person to approve. |
| `document.rules.require.approvers` | body | integer | no | How many distinct approvers are needed, for a route without `steps`. |
| `document.rules.require.route` | body | object | no | Who approves a rule's request and how long it waits: either a chain of `steps`, or a first target with `escalate` and `wait`. |
| `document.rules.require.route.to` | body | string | no | The first target. With `steps` it is the first step's first target and may be left out. |
| `document.rules.require.route.steps` | body | array of objects | no | An approval chain of 1 to 5 steps, in order. The chain waits the sum of its steps' `after` (1 minute to 7 days); then the rule's `if_unanswered` applies, else the account's approval expiry default. A chain leaves out `escalate`, `wait` and `approvers`. |
| `document.rules.require.route.approvers_from` | body | enum | no | How approvals count toward the number needed. One of `any`, `distinct_people`. |
| `document.rules.require.route.escalate` | body | array of objects | no | Escalation steps, for a route without `steps`. |
| `document.rules.require.route.wait` | body | string | no | How long the request waits in all, for a route without `steps`. |
| `document.rules.require.route.if_unanswered` | body | enum | no | What happens when nobody answers. Left out, the account's approval expiry default applies. One of `expire`, `decline`, `approve_below`. |
| `document.rules.require.route.approve_below_amount` | body | number | no | With `approve_below`: the amount it approves at or under. |
| `document.rules.require.route.hours` | body | string | no | The approver group (`agr_…`) whose business hours apply. |
| `document.rules.require.route.outside_hours` | body | enum | no | What happens to a request outside business hours. One of `hold`, `escalate`. |
| `document.rules.require.route.assign` | body | enum | no | Who gets it first. A chain uses `all`. One of `all`, `round_robin`, `least_pending`. |
| `document.rules.require.biometric` | body | boolean | no | Require face, fingerprint or passkey from the person. |
| `document.rules.require.hardware` | body | boolean | no | Require a hardware-backed phone. |
| `document.rules.require.min_tier` | body | enum | no | The weakest device tier allowed. One of `simulated`, `software`, `tee`, `strongbox`, `sep`. |
| `document.rules.require.webhook` | body | string | no | The name of the policy webhook to ask. |
| `document.rules.require.notify` | body | object | no | "Approve and notify": the rule allows the request and tells the people named, the account's webhook endpoints, or both. It never decides, so evaluation goes on to the next rule. A notify rule's `require` holds `notify` alone. |
| `document.rules.require.notify.to` | body | array of strings | no | People, groups or roles to tell (1 to 10 route targets, such as `role:admins` or `user:owner`). |
| `document.rules.require.notify.webhook` | body | boolean | no | Also send the `mandate.policy.notified` event to the account's webhook endpoints. |
| `document.rules.require.approval_min_credential_age_s` | body | integer | no | With `approval`: how old the approving passkey must be, in seconds. |
| `document.rules.require.approval_method` | body | enum | no | With `approval`: only the approver's phone in the Provenance app approves. One of `device_key`. |
| `document.rules.require.individual` | body | boolean | no | With `approval`: the request is never approved in a batch. |
| `document.rules.require.auto_approve` | body | array of objects | no | Clauses under which the approval counts as given without a person. |
| `document.rules.reason` | body | string | no | The reason code a matching rule reports. On a person's rules: `store_not_allowed` on a block, or `ask_above` or `outside_hours` on an ask (the codes the rules moved from Your rules keep), else none (`person_rule`). |
| `document.rules.on_request` | body | enum | no | A person's rules only: what the rule does to a company's approval request sent to the person, when it matches. `hold` keeps the request in the person's home and sends nothing; `defer` delivers it like quiet hours. Absent: the rule leaves companies' requests alone. Such a rule reads only the store and the time. One of `hold`, `defer`. |
| `document.rules.phase` | body | enum | no | Trace rules: `action` (absent; before a tool runs) or `completion` (on model output). Your checkout rules: when the rule runs. `assess` (absent) runs at `POST /v1/authorize/checkout_assessments`; `after_approval` runs once the customer has decided a cart approval and before the token is minted, over the assessment's facts and the `approval.*` facts (`approval.decision`, `approval.location`, …). After-approval rules approve (`frictionless`; checkout rules say `no_challenge`), review (`review`) or reject (`deny`); they never challenge. Every plan. One of `assess`, `after_approval`, `action`, `completion`. |
| `document.rules.enabled` | body | boolean | no | Whether the rule is on; absent means on. `false` keeps the rule in the document (and its versions) but skips it: it never matches, decides, notifies or counts in a backtest. Turning a rule off or on is a change like any other (a new draft or version); on a person's tighten-only rules, turning one off loosens them. |
| `document.rules.if_unavailable` | body | enum | no | What an unavailable fact means for this rule, over the document's `settings.if_unavailable` (a condition's own setting wins). `fail_closed` and `fail_open` stay Trace and agent rules' words. One of `skip`, `match`, `ask`, `fail_closed`, `fail_open`. |
| `document.timezone` | body | string | no | An IANA time zone, such as `America/Chicago`, for a person's `time.local_hour` and `time.local_weekday` facts. |
| `document.tighten_only` | body | boolean | no | A person's rules only. A change that only makes the rules stricter saves without a passkey; one that loosens them needs the passkey and is refused for 7 days after a recovery. Turning it off is a loosening. |
| `document.version` | body | integer | no | Informational; the stored version number is assigned on save. |
| `document.external_confirmations` | body | object | no | Which confirmations given outside Provenance count, and whose keys. Empty by default; it also governs your store's cart approvals. Every plan. The issuers listed here are also the ones whose mandates cover a checkout assessment's cart (`checkout.covered: third_party_mandate`). |
| `document.external_confirmations.accept` | body | array of enums | no | The kinds you accept. |
| `document.external_confirmations.ap2_issuers` | body | array of objects | no | Required with `ap2_user_mandate`: the AP2 issuers whose signatures count. Their mandates also cover a checkout assessment's cart, with or without `accept`. |
| `document.external_confirmations.ap2_issuers.name` | body | string | yes | The name shown as "Confirmed in <name>". |
| `document.external_confirmations.ap2_issuers.jwks_url` | body | string | yes | The issuer's JWKS (https). |
| `document.external_confirmations.acp_issuers` | body | array of objects | no | The ACP issuers you trust: a checkout completion whose signed intent (`provenance_intent.token`) one of them signed covers a checkout assessment's cart. |
| `document.external_confirmations.acp_issuers.name` | body | string | yes | The issuer's name, as `authority.issuer` shows it. |
| `document.external_confirmations.acp_issuers.jwks_url` | body | string | yes | The issuer's JWKS (https). |
| `document.external_confirmations.platforms` | body | array of objects | no | Required with `platform`: the agent platforms whose signed confirmations count. |
| `document.external_confirmations.platforms.name` | body | string | yes | The platform's name. |
| `document.external_confirmations.platforms.jwks_url` | body | string | yes | The platform's JWKS (https). |
| `document.voice` | body | object | no | When a confirmation call may approve on the keypad, and when it needs the passkey. Set on your approval policy (`/mandate/policies`) or your checkout rules (`/authorize/policies`). Absent fields take the defaults: approve on the call up to 25.00 USD to a counterparty this person has paid before, and a passkey otherwise. Grants, delegations, new payees and contact or recovery changes always need the passkey, and so does any rule that requires a biometric. |
| `document.voice.enabled` | body | boolean | no | `false`: a call never approves; it reads the request and sends the passkey link. Default `true`. |
| `document.voice.voice_max` | body | integer | no | Approve on the call up to this amount, in minor units of `currency`. Default 2500 (25.00 USD). `0` means never. |
| `document.voice.currency` | body | string | no | The ISO 4217 currency of `voice_max`. Default `USD`. A request in another currency needs the passkey. |
| `document.voice.voice_requires_known_counterparty` | body | boolean | no | A counterparty this person hasn't paid before needs the passkey. Default `true`. |
| `document.voice.never_voice_action_types` | body | array of strings | no | Action types (`context.action_type`) that always need the passkey. |
| `document.passkeys` | body | object | no | On a checkout policy, what a new passkey needs on a cart approval. |
| `document.signals` | body | array of objects | no | Named checks with no outcome (`signal.<key>`), for checkout, agent, capture, Trace and card issuer rules. |
| `document.signals.id` | body | string | no | The server's id (`sig_` and a ULID), kept across versions. |
| `document.signals.key` | body | string | no | The fact's name part. Derived from the first label when left out, then fixed: a later write can't change it. |
| `document.signals.label` | body | string | yes | The account's name for the signal; change it at any time. |
| `document.signals.when` | body | array of objects \| object | yes | A rule's or signal's IF part. Either a list of conditions that must all match, or an object that picks a mode over conditions and groups (groups nest to three levels with the rule's own; at most 10 items in a group and 20 conditions in all). |
| `document.signals.when.match` | body | enum | no | Whether all, any, none or at least `n` of the items must match (`none` holds when no item does). One of `all`, `any`, `none`, `at_least`. |
| `document.signals.when.n` | body | integer | no | With `match: at_least`: how many items must match (1 to the item count). |
| `document.signals.when.items` | body | array of objects | no | Conditions and groups (at most 10). |
| `document.signals.when.items.fact` | body | string | no | The fact the condition reads (`transaction_amount`, `order.amount`, `agent.verified`), or `field` to read `path` from the request. |
| `document.signals.when.items.op` | body | enum | no | The comparison operator. A field condition takes the comparisons, `in`, `matches`, `contains`, `contains_any`, `is_empty` and `is_not_empty`. Every operator except the two null operators fails to match a missing or null fact, `ne` included. `is_empty` matches a fact that is missing, null, an empty string or an empty list; `is_not_empty` matches any other value. |
| `document.signals.when.items.value` | body | any | no | The value to compare with (a string, number, boolean or a list of them). `is_empty` and `is_not_empty` take `true`. |
| `document.signals.when.items.path` | body | string | no | With `fact: field`: up to 6 dotted names, each optionally followed by `[]` for every element of a list (at most one `[]`), such as `metadata.cost_center` or `order.items[].sku`. |
| `document.signals.when.items.items` | body | enum | no | With a path through a list: whether any element (the default) or every element must match. One of `any`, `all`. |
| `document.signals.when.items.metric` | body | enum | no | With `fact: velocity`: what is counted. One of `verify_count`, `amount_sum`. |
| `document.signals.when.items.window` | body | enum | no | With `fact: velocity`: the window. `1h` and `24h` are rolling; `month` is the calendar month in UTC, counted per `account` or `agent`. One of `1h`, `24h`, `month`. |
| `document.signals.when.items.per` | body | enum | no | With `fact: velocity`: what it is counted per. `agent` is the registered agent the token names (none: 0). One of `device`, `session`, `account`, `agent`. |
| `document.signals.when.items.set` | body | string | no | With `fact: canary` or `prediction`: the canary family or probe. |
| `document.signals.when.items.best_effort` | body | boolean | no | With a canary or probe: an unavailable reading evaluates false instead of failing closed. |
| `document.signals.when.items.baseline` | body | enum | no | With `z_gt` or `pct_gt`: the baseline the score is compared against. One of `agent`, `account`. |
| `document.signals.when.items.if_unavailable` | body | enum | no | What an unavailable reading means for this condition: `skip` (no match), `match`, or `ask` (match and ask a person). `ignore` is an external risk fact's older word for `skip`; a capture fact or Trace finding takes `skip` or `match`. One of `skip`, `match`, `ask`, `ignore`. |
| `document.signals.when.items.match` | body | enum | no | Whether all, any, none or at least `n` of the group's items must match (`none` holds when no item does; a condition on a missing fact doesn't hold). One of `all`, `any`, `none`, `at_least`. |
| `document.signals.when.items.n` | body | integer | no | With `match: at_least`: how many items must match (1 to the item count). N-of-M. |
| `document.signals.when.items.conditions` | body | array of objects | no | The group's conditions and groups (1 to 10). |
| `document.scorecards` | body | array of objects | no | Scorecards (`scorecard.<key>.score`, `scorecard.<key>.matched`), for checkout, agent, capture, Trace and card issuer rules. |
| `document.scorecards.id` | body | string | no | The server's id (`scd_` and a ULID), kept across versions. |
| `document.scorecards.key` | body | string | no | The fact's name part. Derived from the first label when left out, then fixed. |
| `document.scorecards.label` | body | string | yes | The account's name for the scorecard; change it at any time. |
| `document.scorecards.rows` | body | array of objects | yes | The rows. Each reads a signal or its own `when`. |
| `document.scorecards.rows.signal` | body | string | no | A signal's key in this document (one of `signal` and `when`). |
| `document.scorecards.rows.when` | body | array of objects \| object | no | A rule's or signal's IF part. Either a list of conditions that must all match, or an object that picks a mode over conditions and groups (groups nest to three levels with the rule's own; at most 10 items in a group and 20 conditions in all). |
| `document.scorecards.rows.when.match` | body | enum | no | Whether all, any, none or at least `n` of the items must match (`none` holds when no item does). One of `all`, `any`, `none`, `at_least`. |
| `document.scorecards.rows.when.n` | body | integer | no | With `match: at_least`: how many items must match (1 to the item count). |
| `document.scorecards.rows.when.items` | body | array of objects | no | Conditions and groups (at most 10). |
| `document.scorecards.rows.points` | body | integer | yes | Points the row adds when it matches. |
| `document.scorecards.rows.label` | body | string | no | The row's name. |
| `document.scorecards.min_available` | body | integer | no | How many rows must be readable for the total to be available (default: all rows but one). |
| `document.groups` | body | array of objects | no | Rule groups (`group.<key>.outcome`), for checkout, agent, capture, Trace and card issuer rules. |
| `document.groups.id` | body | string | no | The server's id (`grp_` and a ULID), kept across versions. |
| `document.groups.key` | body | string | no | The fact's name part. Derived from the first label when left out, then fixed. |
| `document.groups.label` | body | string | yes | The account's name for the group; change it at any time. |
| `document.flows` | body | array of objects | no | The sub-flows this rule set calls (checkout and agent rules). Rules read `flow.<key>.outcome`, `flow.<key>.version` and each declared output `flow.<key>.<output>`, or take the flow's outcome with `require.flow`. |
| `document.flows.key` | body | string | yes | The sub-flow's key. |
| `document.flows.follow` | body | enum | no | `latest` (the default) follows the published version; `pinned` keeps `version`. One of `latest`, `pinned`. |
| `document.flows.version` | body | integer | no | The pinned version (only with `follow` set to `pinned`). |
| `document.settings` | body | object | no | How unavailable facts and fact resolution work for every rule of the document. |
| `document.settings.if_unavailable` | body | enum | no | What an unavailable fact means for every rule: `skip` (the condition doesn't match), `match` (it matches) or `ask` (it matches and a person is asked instead of the rule's outcome; refused on issuer rules). The older `fail_closed` and `fail_open` stay Trace and agent rules' words for an unavailable Trace finding. One of `skip`, `match`, `ask`, `fail_closed`, `fail_open`. |
| `document.settings.preflight` | body | boolean | no | Trace rules only: run the rules on model output on the prompt first, before generation. |
| `document.settings.resolve` | body | enum | no | `needed` (default) reads only the facts the deciding rule still needs; `ahead` also reads the same cost tier of later rules, one round sooner. One of `needed`, `ahead`. |
| `document.fallback` | body | object | no | The built-in fallback rows' outcomes, by row: what happens when no rule decides. A store's checkout rules have `covered` (a cart a token or mandate covers; Approve by default), `uncovered` (Challenge) and `after_approval` (an approved cart; Approve), each `approve`, `challenge` or `reject` (`approve`, `review` or `reject` after approval). Capture rules have `passes` (Approve) and `flagged` (Review), each `approve`, `review` or `reject`. Agent policies have `assess` (an action no rule decides; Approve by default), `approve`, `review` (ask a person) or `reject`. The rows always run last and are never deleted; a row left out keeps its built-in outcome. |
| `version` | body | integer | no | Replay a saved version instead of `document` (send one or the other). Where the backtest is kept, it becomes that version's test at publish. |
| `days` | body | integer | no | How many days to replay (default 30). |

### Returns

How the document would have decided.

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`invalid_json`](https://provenanceauth.com/docs/platform/errors.md#invalid_json)
- [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid)
- [`plan_required`](https://provenanceauth.com/docs/platform/errors.md#plan_required)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`policy_invalid`](https://provenanceauth.com/docs/platform/errors.md#policy_invalid)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -X POST "$PROVENANCE_API/v1/trace/policies/backtest" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "document": {
      "rules": [
        {
          "label": "Big payments",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "pay"
            },
            {
              "fact": "action.amount",
              "op": "gt",
              "value": 100000
            }
          ],
          "require": {
            "approval": true
          }
        },
        {
          "label": "Injection on model output",
          "when": [
            {
              "fact": "canary",
              "set": "prompt_injection",
              "op": "gte",
              "value": 0.9
            }
          ],
          "require": {
            "deny": true
          },
          "phase": "completion"
        }
      ]
    }
  }'
```

**Node**

```ts
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/backtest`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({
    "document": {
      "rules": [
        {
          "label": "Big payments",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "pay"
            },
            {
              "fact": "action.amount",
              "op": "gt",
              "value": 100000
            }
          ],
          "require": {
            "approval": true
          }
        },
        {
          "label": "Injection on model output",
          "when": [
            {
              "fact": "canary",
              "set": "prompt_injection",
              "op": "gte",
              "value": 0.9
            }
          ],
          "require": {
            "deny": true
          },
          "phase": "completion"
        }
      ]
    }
  }),
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
data = httpx.post(f"{api}/v1/trace/policies/backtest", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={
    "document": {
        "rules": [
            {
                "label": "Big payments",
                "when": [
                    {
                        "fact": "action.risk",
                        "op": "eq",
                        "value": "pay"
                    },
                    {
                        "fact": "action.amount",
                        "op": "gt",
                        "value": 100000
                    }
                ],
                "require": {
                    "approval": True
                }
            },
            {
                "label": "Injection on model output",
                "when": [
                    {
                        "fact": "canary",
                        "set": "prompt_injection",
                        "op": "gte",
                        "value": 0.9
                    }
                ],
                "require": {
                    "deny": True
                },
                "phase": "completion"
            }
        ]
    }
}).json()
```

### Response 200

```json
{
  "object": "policy_backtest",
  "available": true,
  "days": 30,
  "from": "2026-10-29T10:48:44.346Z",
  "to": "2026-11-28T10:48:44.346Z",
  "requests": 16,
  "truncated": false,
  "field_conditions_unscored": false,
  "totals": {
    "allowed": 2,
    "challenged": 0,
    "rejected": 14
  },
  "amounts": {
    "fact": "action.amount",
    "allowed": [],
    "challenged": [],
    "rejected": [],
    "unsummed": 0
  },
  "rules": [
    {
      "rule_id": "rul_01M8GWB31S472F46K7SQ606HHK",
      "label": "Big payments",
      "stage": "action",
      "outcome": "ask",
      "matched": 0,
      "decided": 0,
      "labelled_false": 0,
      "per_week": 0,
      "summary": "Last 30 days: matched 0 times.",
      "amounts": []
    },
    {
      "rule_id": "rul_01M8GWB31TQ7A0XD2ZFMWP4992",
      "label": "Injection on model output",
      "stage": "completion",
      "outcome": "block",
      "matched": 14,
      "decided": 14,
      "labelled_false": 0,
      "per_week": 3.3,
      "summary": "Last 30 days: matched 14 times.",
      "amounts": []
    }
  ]
}
```

## Stop the trial run

`DELETE /v1/trace/policies/trial`

Stops the trial run; the draft stays in the history and the live rules keep deciding.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

No parameters.

### Returns

No trial run.

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`manage_policies_required`](https://provenanceauth.com/docs/platform/errors.md#manage_policies_required)
- [`recent_two_factor_required`](https://provenanceauth.com/docs/platform/errors.md#recent_two_factor_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -X DELETE "$PROVENANCE_API/v1/trace/policies/trial" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/trial`, {
  method: "DELETE",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
data = httpx.delete(f"{api}/v1/trace/policies/trial", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}).json()
```

### Response 200

```json
{
  "object": "policy_trial",
  "domain": "trace",
  "active": false,
  "version": null
}
```

## Promote the trial run

`POST /v1/trace/policies/trial/promote`

Publishes the draft on trial: it becomes the live Trace rules at once.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Retry a create safely: the same key + request returns the stored response (24 h, per caller). |

### Returns

The new live version, with `promoted_from_trial`. See [the policy version object](#object).

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`policy_trial_not_active`](https://provenanceauth.com/docs/platform/errors.md#policy_trial_not_active)
- [`manage_policies_required`](https://provenanceauth.com/docs/platform/errors.md#manage_policies_required)
- [`recent_two_factor_required`](https://provenanceauth.com/docs/platform/errors.md#recent_two_factor_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -X POST "$PROVENANCE_API/v1/trace/policies/trial/promote" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
```

**Node**

```ts
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/trial/promote`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({}),
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
data = httpx.post(f"{api}/v1/trace/policies/trial/promote", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={}).json()
```

### Response 200

```json
{
  "object": "policy_version",
  "policy_id": "pol_AC2A5612965B31B91188589F91",
  "version": 13,
  "active": true,
  "note": "big orders from new shoppers or unsigned agents",
  "created_by": "key_7FHWBSCG1E8PJV9C3XB7HS0CF4",
  "created_at": "2026-11-08T18:05:02.805Z",
  "trial_ends_at": "2026-11-15T18:05:02.805Z",
  "source": "api",
  "domain": "trace",
  "promoted_from_trial": true
}
```

## Shadow a Trace rules version

`POST /v1/trace/policies/versions/{version}/shadow`

Runs this version beside the live Trace rules without enforcing it: each trace assessment records what it would have decided (`shadow`). One shadow per account; publishing it makes it live.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Retry a create safely: the same key + request returns the stored response (24 h, per caller). |
| `version` | path | integer | yes | The version number. |

### Returns

The version, now running in shadow. See [the policy version object](#object).

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)
- [`resource_missing`](https://provenanceauth.com/docs/platform/errors.md#resource_missing)
- [`usage_limit_reached`](https://provenanceauth.com/docs/platform/errors.md#usage_limit_reached)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -s -X POST "$PROVENANCE_API/v1/trace/policies/versions" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "document": {
      "rules": [
        {
          "label": "Big payments",
          "when": [
            {
              "fact": "action.amount",
              "op": "gt",
              "value": 100000
            }
          ],
          "require": {
            "deny": true
          }
        }
      ]
    }
  }' > step.json
export VERSION=$(jq -r '.version' step.json)
curl -X POST "$PROVENANCE_API/v1/trace/policies/versions/$VERSION/shadow" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
```

**Node**

```ts
const step1 = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/versions`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({
    "document": {
      "rules": [
        {
          "label": "Big payments",
          "when": [
            {
              "fact": "action.amount",
              "op": "gt",
              "value": 100000
            }
          ],
          "require": {
            "deny": true
          }
        }
      ]
    }
  }),
})).json();
const version = step1.version;
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/versions/${version}/shadow`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({}),
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
step1 = httpx.post(f"{api}/v1/trace/policies/versions", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={
    "document": {
        "rules": [
            {
                "label": "Big payments",
                "when": [
                    {
                        "fact": "action.amount",
                        "op": "gt",
                        "value": 100000
                    }
                ],
                "require": {
                    "deny": True
                }
            }
        ]
    }
}).json()
version = step1["version"]
data = httpx.post(f"{api}/v1/trace/policies/versions/{version}/shadow", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={}).json()
```

### Response 200

```json
{
  "object": "policy_version",
  "domain": "trace",
  "version": 1,
  "active": false,
  "shadow": true
}
```

## Stop shadowing Trace rules

`DELETE /v1/trace/policies/versions/{version}/shadow`

Stops shadowing; the version stays in the history.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `version` | path | integer | yes | The version number. |

### Returns

The shadow is off.

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -s -X POST "$PROVENANCE_API/v1/trace/policies/versions" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "document": {
      "rules": [
        {
          "label": "Big payments",
          "when": [
            {
              "fact": "action.amount",
              "op": "gt",
              "value": 100000
            }
          ],
          "require": {
            "deny": true
          }
        }
      ]
    }
  }' > step.json
export VERSION=$(jq -r '.version' step.json)
curl -X DELETE "$PROVENANCE_API/v1/trace/policies/versions/$VERSION/shadow" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const step1 = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/versions`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({
    "document": {
      "rules": [
        {
          "label": "Big payments",
          "when": [
            {
              "fact": "action.amount",
              "op": "gt",
              "value": 100000
            }
          ],
          "require": {
            "deny": true
          }
        }
      ]
    }
  }),
})).json();
const version = step1.version;
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/versions/${version}/shadow`, {
  method: "DELETE",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5" },
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
step1 = httpx.post(f"{api}/v1/trace/policies/versions", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={
    "document": {
        "rules": [
            {
                "label": "Big payments",
                "when": [
                    {
                        "fact": "action.amount",
                        "op": "gt",
                        "value": 100000
                    }
                ],
                "require": {
                    "deny": True
                }
            }
        ]
    }
}).json()
version = step1["version"]
data = httpx.delete(f"{api}/v1/trace/policies/versions/{version}/shadow", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}).json()
```

### Response 200

```json
{
  "object": "policy_shadow",
  "domain": "trace",
  "shadow": false
}
```

## Simulate your Trace rules

`POST /v1/trace/policies/simulate`

Evaluates a draft or your active Trace rules against a fact bag at a stage and changes nothing. `unavailable` names Trace findings that couldn't be loaded and why; the policy's fail setting decides what each means, and the answer lists them.

Auth: an API key, as `Authorization: Bearer <key>`.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Retry a create safely: the same key + request returns the stored response (24 h, per caller). |
| `document` | body | object | no | A draft to simulate; your active rules when left out. |
| `phase` | body | enum | no | The stage (default `action`). One of `action`, `completion`. |
| `facts` | body | object | no | The facts, by name: `action.risk`, `context.untrusted_sources`, `finding.categories`, `canary:prompt_injection`, `trace.tripped`, ... A fact left out is absent. |
| `unavailable` | body | object | no | Findings that couldn't be loaded, each with its reason (`no_trace`, `not_found`, `stale`, `backend_unavailable`, `trace_paused`, `guard_unanswered`). |

### Returns

What the rules would decide.

### Errors

- [`authentication_required`](https://provenanceauth.com/docs/platform/errors.md#authentication_required)
- [`invalid_json`](https://provenanceauth.com/docs/platform/errors.md#invalid_json)
- [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid)
- [`policy_account_required`](https://provenanceauth.com/docs/platform/errors.md#policy_account_required)
- [`policy_invalid`](https://provenanceauth.com/docs/platform/errors.md#policy_invalid)
- [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded)

### Request

**curl**

```bash
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
curl -X POST "$PROVENANCE_API/v1/trace/policies/simulate" \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "document": {
      "rules": [
        {
          "id": "injected-email-payments",
          "label": "Payments after an injected email",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "pay"
            },
            {
              "fact": "context.untrusted_sources",
              "op": "contains",
              "value": "email"
            }
          ],
          "require": {
            "approval": true
          }
        }
      ]
    },
    "facts": {
      "action.risk": "pay",
      "context.untrusted_sources": [
        "email"
      ]
    }
  }'
```

**Node**

```ts
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies/simulate`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({
    "document": {
      "rules": [
        {
          "id": "injected-email-payments",
          "label": "Payments after an injected email",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "pay"
            },
            {
              "fact": "context.untrusted_sources",
              "op": "contains",
              "value": "email"
            }
          ],
          "require": {
            "approval": true
          }
        }
      ]
    },
    "facts": {
      "action.risk": "pay",
      "context.untrusted_sources": [
        "email"
      ]
    }
  }),
})).json();
```

**Python**

```python
import os
import httpx

api = os.environ["PROVENANCE_API"]
data = httpx.post(f"{api}/v1/trace/policies/simulate", headers={"Authorization": "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5"}, json={
    "document": {
        "rules": [
            {
                "id": "injected-email-payments",
                "label": "Payments after an injected email",
                "when": [
                    {
                        "fact": "action.risk",
                        "op": "eq",
                        "value": "pay"
                    },
                    {
                        "fact": "context.untrusted_sources",
                        "op": "contains",
                        "value": "email"
                    }
                ],
                "require": {
                    "approval": True
                }
            }
        ]
    },
    "facts": {
        "action.risk": "pay",
        "context.untrusted_sources": [
            "email"
        ]
    }
}).json()
```

### Response 200

```json
{
  "object": "policy_simulation",
  "domain": "trace",
  "stage": "action",
  "outcome": "challenge",
  "reason": "approval_required",
  "policy": {
    "id": "pol_956287817DE7DEF7A3C4E0C732",
    "version": 0,
    "rule": {
      "id": "injected-email-payments",
      "name": "Payments after an injected email",
      "phase": "action",
      "action": "challenge",
      "conditions": [
        {
          "fact": "action.risk",
          "op": "eq",
          "value": "pay",
          "actual": "pay"
        },
        {
          "fact": "context.untrusted_sources",
          "op": "contains",
          "value": "email",
          "actual": [
            "email"
          ]
        }
      ]
    }
  },
  "logged": [],
  "unavailable": []
}
```
