# API conventions

How every Provenance endpoint shapes errors, lists, resources, deletes, idempotent retries and headers, and how to migrate from the beta API.

Every Provenance endpoint follows the same rules for errors, lists, resources, deletes, retries and headers. Learn them once and every route behaves the way you expect.

## Errors

Every 4xx and 5xx response has one shape. Branch on `error.code`, show `error.message` to a person, and log `error.request_id`.

```json
{
  "error": {
    "type": "invalid_request_error",
    "code": "parameter_missing",
    "message": "Missing required parameter 'action_description'.",
    "param": "action_description",
    "doc_url": "https://www.provenanceauth.com/docs/errors#parameter_missing",
    "request_id": "req_01HX…"
  }
}
```

| Type | Status | Typical codes |
| --- | --- | --- |
| `invalid_request_error` | 400, 404, 409, 413 | `invalid_json`, `parameter_missing`, `parameter_invalid`, `resource_missing`, `route_not_found` |
| `authentication_error` | 401 | `authentication_required`, `invalid_api_key`, `session_expired` |
| `permission_error` | 403 | `insufficient_scope`, `insufficient_role`, `agent_suspended` |
| `billing_error` | 402 | `plan_required`, `usage_limit_reached`, `spend_limit_exceeded` |
| `rate_limit_error` | 429 | `rate_limit_exceeded` (with `details.limit` and `details.retry_after`) |
| `idempotency_error` | 400 | `idempotency_key_reused` |
| `unavailable_error` | 503 | `detector_not_configured`, `trace_backend_cold`, `service_unavailable_maintenance` |
| `api_error` | other 5xx | `internal_error`, `trace_backend_error`, `screening_provider_error` |

`param` names the input as a dotted path, such as `provenance.session.agent_id`. A missing resource is always `resource_missing`, whether it never existed, has expired or belongs to another account. Every code is on [error codes](https://provenanceauth.com/docs/platform/errors.md).

## Outcomes are reasons, not errors

A request that succeeds but reports a negative outcome returns 200. An intent verify that denies an action carries `valid: false` and a `reason`; a verification of a tampered asset carries risk factors. Every reason is lowercase snake_case and listed on [reason codes](https://provenanceauth.com/docs/platform/reason-codes.md). Your own policy rules can return their own `reason` strings.

## Resources

Every resource carries `object` and its own key as `id`. A reference to another resource keeps the `<resource>_id` name.

```json
{ "id": "appr_01HX…", "object": "approval", "status": "pending", "jti": "4f1c…", "matched_rule_id": "big-wire" }
```

Every ID starts with a prefix for its type:

| Prefix | Resource |
| --- | --- |
| `appr_` | Approval |
| `dec_` | Decision |
| `agt_` | Agent |
| `case_` | Case |
| `lnk_` | Approver link |
| `grt_` | Grant |
| `we_`, `evt_`, `dlv_` | Webhook endpoint, event, delivery |
| `trc_` | Traced inference |
| `rcpt_` | Receipt |
| `acct_` | Account |
| `key_` | API key |
| `dev_` | Device |
| `cses_` | Capture session |
| `att_` | Attestation |
| `car_` | Carrier |

A token's `jti` is a UUID. Older IDs without a prefix keep working, except for the six kinds above that were UUIDs: use their prefixed form. An action returns the updated resource plus its outcome.

Every receipt endpoint (decisions, agreements, orders and the receipt embed) returns the same object. `claims` is the signed payload, decoded; `token` is the ES256 JWS that carries it; `verify_url` opens the console's [Verify a proof](https://provenanceauth.com/docs/integrate/verify-a-proof.md) page with the receipt filled in.

```json
{ "object": "receipt", "id": "rcpt_9c1e…", "claims": { "receipt_id": "rcpt_9c1e…", "decision_id": "mas_01HX…" }, "token": "eyJhbGciOiJFUzI1NiIs…", "verify_url": "https://…/developers/verify?receipt=eyJhbGciOiJFUzI1NiIs…" }
```

## Lists

Every list endpoint returns the same envelope:

```json
{ "object": "list", "data": [ { "id": "agt_01HX…", "object": "agent" } ], "has_more": true, "next_cursor": "eyJpZCI6…" }
```

Pass `limit` from 1 to 100 (default 20). A value outside that range returns 400 `parameter_invalid` instead of being clamped. Pass a response's `next_cursor` back as `cursor` to get the next page; cursors are opaque.

## Deletes

A `DELETE` returns 200 with `{ "id": "…", "object": "…", "deleted": true }`. A revoke (`POST …/revoke`) returns the updated resource with its new `status`.

## Idempotent retries

Send `Idempotency-Key` on a create `POST` to retry it safely. A V4 UUID works; keys are 1–255 printable characters and are kept for 24 hours per account.

**curl**

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5

curl -X POST $PROVENANCE_API/v1/mandate/agents \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Idempotency-Key: 8b1f2c4e-0f7a-4a1d-9d3e-2b6c5a7e9f10" \
  -H "Content-Type: application/json" \
  -d '{ "name": "invoice-bot" }'
```

**Node**

```ts
const res = await fetch(`${process.env.PROVENANCE_API}/v1/mandate/agents`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.PROVENANCE_KEY}`,
    "Idempotency-Key": "8b1f2c4e-0f7a-4a1d-9d3e-2b6c5a7e9f10",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ name: "invoice-bot" }),
});
console.log(res.headers.get("idempotent-replayed"));
```

**Python**

```python
import os
import httpx

res = httpx.post(
    f"{os.environ['PROVENANCE_API']}/v1/mandate/agents",
    headers={"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}", "Idempotency-Key": "8b1f2c4e-0f7a-4a1d-9d3e-2b6c5a7e9f10"},
    json={"name": "invoice-bot"},
)
print(res.headers.get("idempotent-replayed"))
```

```json
{
  "id": "agt_01M5Q9W1T8BH6JYGCNGRTPE8E6",
  "object": "agent",
  "name": "invoice-bot",
  "status": "active"
}
```

- The same key with the same request returns the stored response with `Idempotent-Replayed: true`.
- The same key with a different request returns 400 `idempotency_key_reused`.
- A retry while the first request still runs returns 409 `idempotency_key_in_use`.
- Only a 2xx response is stored, so a corrected retry after an error runs again.

The TypeScript and Python SDKs add a key to every `POST` automatically, so their own retries never create a resource twice.

## Headers

| Header | Direction | Meaning |
| --- | --- | --- |
| `X-Request-Id` | response | `req_` + ULID on every response, also in `error.request_id` |
| `Provenance-Version` | request and response | the API version date: send it to choose a version, else your account's pinned version; every response names the version used ([versioning](https://provenanceauth.com/docs/reference/versioning.md)) |
| `X-RateLimit-Limit`, `-Remaining`, `-Reset` | response | your current rate-limit window |
| `Retry-After` | response | seconds to wait, on 429 and 503 |
| `Idempotency-Key` | request | makes a create `POST` safe to retry |
| `Idempotent-Replayed` | response | `true` on a stored replay |

## Product namespaces

Every product route is `/v1/{product}/{resource}`, with snake_case segments, in the product order Identify, Authorize, Attest, Mandate, Trace and Personal. Account, webhook, embed, sign-in and organization routes stay at the top level. An old path answers `404` with `route_moved`, and `details` names the new method and path:

```json
{ "error": { "type": "invalid_request_error", "code": "route_moved", "message": "This endpoint moved to POST /v1/mandate/intents.", "details": { "method": "POST", "path": "/v1/mandate/intents" } } }
```

| Before | Now |
| --- | --- |
| `POST /v1/intent/authorize` | `POST /v1/mandate/intents` |
| `POST /v1/intent/verify` | `POST /v1/mandate/assessments` (agent builders), `POST /v1/authorize/verifications` (merchants) or the free `POST /v1/verify` |
| `POST /v1/intent/revoke`, `GET /v1/intent/status/{jti}` | `POST /v1/mandate/revocations`, `GET /v1/mandate/intents/{jti}` |
| `/v1/mandates/*` | `/v1/mandate/grants/*` (and `grant_drafts`) |
| `/v1/approvals`, `/v1/approval-links`, `/v1/approval-routes`, `/v1/approver-*`, `/v1/agreements`, `/v1/runs`, `/v1/decisions`, `/v1/policies`, `/v1/risk-signals`, `/v1/takeover-events` | the same resource under `/v1/mandate/`, snake_case |
| `/v1/agents` | `/v1/mandate/agents` (your agents) and `/v1/identify/agents` (signed agents) |
| `/v1/network/*` | `/v1/mandate/network_grants`, `/v1/mandate/grant_requests`, `/v1/mandate/network_orders`, and the store's `/v1/authorize/network_orders/accept` |
| `/v1/checkout-approvals`, `/v1/deals`, `/v1/tabs`, `/v1/disputes` | the same resource under `/v1/authorize/` |
| `/v1/claims/attest`, `/v1/claims/verify`, `/v1/claims/*` | `/v1/attest/attestations`, `/v1/attest/verifications`, `/v1/attest/claims/*` |
| `/v1/cases`, `/v1/appeals`, `/v1/media`, `/v1/analytics`, `/v1/batches`, `/v1/capture-*` | the same resource under `/v1/attest/`, snake_case |
| `/v1/people/*`, `/v1/assistant/*` | `/v1/personal/*` |
| `/v1/trace/canary-sets` and every other hyphenated Trace path | snake_case: `/v1/trace/canary_sets` |
| `/v1/webhook-endpoints`, `/v1/pending-changes` | `/v1/webhook_endpoints`, `/v1/pending_changes` |
| product settings under `/v1/account/*` | `/v1/{product}/settings/*` |

**Intent tokens** carry the free claims only. How the person approved (the method, the biometric, the device tier, the agent's registration) comes from [`POST /v1/authorize/verifications`](https://provenanceauth.com/docs/api/verifications.md#post-v1-authorize-verifications) with your key; Provenance keeps it on its side by the token's `jti`.

| Claims | In the token |
| --- | --- |
| `iss`, `jti`, `sub`, `iat`, `exp`, `aud` | The issuer, the token, the subject and the times |
| `action_hash`, `payload_hash`, `order` | What the person approved |
| `confirmed`, `agent.name`, `display_summary` | When a person approved, and what they saw |
| `mandate_id`, `option_group_id`, `revises` | The grant, option group or earlier token it belongs to |
| `risk` | A coarse risk read at mint |

**Webhook events** are named `product.resource.event`, and existing endpoint subscriptions moved to the new names. The [webhooks guide](https://provenanceauth.com/docs/integrate/webhooks.md) lists every event.

| Before | Now |
| --- | --- |
| `approval.requested` | `mandate.approval.created` |
| `approval.resolved` | One event per outcome: `mandate.approval.approved`, `mandate.approval.declined`, `mandate.approval.expired`; for checkout approvals, `authorize.checkout_approval.approved`, `.declined`, `.expired` |
| `intent.denied` | `mandate.assessment.denied` |

**SDKs** follow the paths:

| Before | Now |
| --- | --- |
| `prov.intent.authorize()` | `prov.mandate.intents.create()` |
| `prov.intent.verify()` | `prov.mandate.assessments.create()` |
| `prov.mandates.grant()` | `prov.mandate.grants.create()` |
| `prov.claims.attest()` | `prov.attest.attestations.create()` |
|  | `prov.authorize.verifications.create()` (paid) and `prov.verify()` (free, no key) |

## Migrating from the beta API

The beta API changed shapes in one release. The SDKs moved to 1.0.0 with these changes; update raw HTTP integrations with the tables below.

**Error codes**

| Beta | Now |
| --- | --- |
| `missing_required_field` (422) | `parameter_missing` (400) |
| `invalid_field_value` (422) | `parameter_invalid` (400) |
| (500 on a malformed body) | `invalid_json` (400) |
| every `*_not_found` code, such as `claim_not_found` or `approval_not_found` | `resource_missing` (404, with `param`) |
| `attestation_not_found` on an unknown path | `route_not_found` (404) |
| `idempotency_conflict` (409) | `idempotency_key_reused` (400 `idempotency_error`) |
| `usage_limit_exceeded`, `screening_quota_exhausted` | `usage_limit_reached` (402) |
| `invite_rate_exceeded`, `invite_cooldown` | `rate_limit_exceeded` (429) |
| `no_manifest_found`, `signature_invalid`, `sensor_hash_mismatch`, `device_revoked`, `cert_unknown_ca` (200) | read the risk factors instead |
| types `invalid_request`, `not_found` | `invalid_request_error` |
| type `authorization_error` | `permission_error` |
| 503 `api_error` | `unavailable_error` |
| `session_expired` 410, `chunk_index_conflict` 422 | 401, 409 |
| `agent_suspended` 422, `disclosure_requires_human` 401 | 403 `permission_error` |

**Reasons and risk factors:** every value is lowercase (`POLICY_DENIED` is now `policy_denied`, `NO_MANIFEST` is now `no_manifest`). Decision-ledger records written before the change keep their original spelling.

**Shapes**

| Beta | Now |
| --- | --- |
| a resource's own `<resource>_id` (`approval_id` on an approval) | `id`, plus `object` |
| `{ data, pagination: { has_more, next_cursor, prev_cursor, total_count } }` and other list shapes | `{ object: "list", data, has_more, next_cursor }` |
| `limit` above 100 clamped | 400 `parameter_invalid` |
| delete responses in several shapes | `{ id, object, deleted: true }` |
| `X-Idempotent-Replayed` | `Idempotent-Replayed` |
| receipts as `{ receipt: <claims>, token }` (decisions, agreements, the receipt embed) or `{ claims, receipt: <JWS> }` (orders) | `{ object: "receipt", id, claims, token, verify_url }` everywhere |

**Paths**

| Beta | Now |
| --- | --- |
| `/v1/policy`, `/v1/policy/*` | `/v1/mandate/policies`, `/v1/mandate/policies/*` |
| `/v1/batch/verifications`, `/v1/batch/{id}` | `POST /v1/attest/batches`, `/v1/attest/batches/{id}` |
| `GET /v1/appeal`, `POST /v1/appeal` | `GET /v1/attest/appeals/context`, `POST /v1/attest/appeals` |
| `/v1/approval-link/{token}` | `/v1/mandate/approval_links/{token}` |
| `/v1/verifications/*` | `/v1/attest/claims/*` (set `case_type` on attest) |

Signed artifacts (intent tokens, receipts, manifests and sidecar readings) are unchanged, so tokens and receipts you already hold still verify. Only the JSON around a receipt changed.
