Rightshold™ Sign up

Answers · AI evidence

How do I bind an AI agent's payment receipt to what triggered it, the policy that allowed it, the payment details and its idempotency key, and reconcile against the provider before replaying a run?

Last updated

TL;DR: Write one receipt per payment that ties four things together: the trigger (the task, step and input that led the agent to pay, by id and hash), the policy decision (policy id and version, allow or deny, approval id), the payment itself (amount in minor units, currency, payee, provider and provider payment id) and the idempotency key the agent sent. Hash the canonical receipt, sign or chain it, and put the same idempotency key and receipt id in the payment's metadata so the two sides point at each other. Before you replay or resume a run, reconcile: for every payment step in the recorded run, look up the provider by idempotency key or metadata and compare status, amount, currency and payee with the receipt. Steps that already succeeded are replayed from the receipt, not paid again; mismatches and unknowns stop the replay and go to a person.

What should I check, step by step?

1. Give each payment step a stable receipt id and idempotency key, created when the agent commits to paying and saved before the first call to the provider.

  1. Record the trigger: task id, step id, the message or event that caused the payment, and a hash of the inputs the agent used (invoice, quote, Payment Required body).
  2. Record the decision: policy id and version, the allow or deny and its reason, the approval id, approver and expiry if one was needed, and the action hash the approval covered.
  3. Record the payment: provider, provider payment id (PaymentIntent, charge, transaction hash), amount in minor units, currency, payee, status and the time of the last status you saw.
  4. Hash the canonical receipt (RFC 8785 JSON or a fixed field order) and chain or sign it, so a later edit to any field shows.
  5. Write receipt_id and the idempotency key into the payment's own metadata or reference field, so you can find the payment from the receipt and the receipt from the payment.
  6. Before replaying or resuming, run a reconcile pass over every payment step: fetch the provider record, compare it with the receipt, and label each step matched, missing, mismatched or unknown.
  7. Replay matched steps from the receipt, retry missing steps only with the same idempotency key and a still-valid approval, and stop on mismatched or unknown.

Why does an agent payment receipt need the trigger, policy, payment and idempotency key?

Trigger without payment details tells you why the agent wanted to pay, but not what actually left the account.

How do I reconcile agent payments before replaying a run?

Durable-execution tools replay recorded results so finished work isn't redone: Temporal replays a workflow from its event history, and LangGraph's durable execution saves task results so they're reused when a run resumes. A payment that happened outside that record, or whose result was lost in a crash, needs an explicit check.

What should happen to each payment step after reconciliation?

Matched: the provider shows the payment as the receipt describes. Replay returns the recorded result; no new call to the provider.

What are the common failure modes?

The idempotency key is generated inside the HTTP call, so the replay sends a new key and the provider happily charges again.

How do I ask Rightshold about this (free, no key)?

Add the MCP server https://www.rightshold.com/mcp to Claude, Cursor, ChatGPT, Grok or VS Code, then ask: “Record a signed receipt for this agent payment: the trigger and inputs by hash, the policy decision and approval id, the provider payment id, amount, currency and payee, and the idempotency key.”

One-click setup

{
  "tool": "record_ai_run",
  "arguments": {
    "model": "<model or agent id that made the payment>",
    "provider": "<runtime or framework>",
    "prompt_sha256": "<sha256 of the trigger event + inputs the agent used>",
    "output_sha256": "<sha256 of the canonical payment receipt>",
    "params": {
      "task_id": "task_8841",
      "step_id": "pay-3",
      "policy_id": "pol_…",
      "policy_version": 4,
      "decision": "allow",
      "approval_id": "apr_…",
      "amount_minor": 2000,
      "currency": "USD",
      "payee": "api.vendor.example",
      "payment_provider": "stripe",
      "payment_id": "pi_…",
      "idempotency_key": "task_8841-pay-3"
    },
    "ran_at": "2026-11-07T07:00:00Z"
  }
}

Rightshold doesn't process payments or query your payment provider. It signs and timestamps the receipt fields and hashes you send; the reconcile lookup against Stripe, a wallet or a bank is your code. Not legal or financial advice.

What are the sources?

Related

Not legal advice. JSON · Markdown · All answers

Get a free API key in one call

No card and no email needed. 100 free credits; the license and policy checks stay free without a key.

curl -s -X POST https://www.rightshold.com/v1/accounts/signup -H "Content-Type: application/json" -d '{"accept_terms":true}'
export RIGHTSHOLD_API_KEY=rs_...   # the api_key from the reply (shown once)
curl -s https://www.rightshold.com/v1/licenses/check -H "Authorization: Bearer $RIGHTSHOLD_API_KEY" \
  -H "Content-Type: application/json" -d '{"license":"MIT","intended_use":{"commercial_use":true}}'