Skip to content
Anlyon
Esc
↑↓navigate↵open⌘Jpreview
On this page

Bound approvals and previews

Show a reviewer the exact request a governed action will send, and make sure an approval runs that request and nothing else.

A preview is the exact request a governed action will send: the normalized request, the resolved target, the action and adapter versions, the impact against your limits, the provider state observed at review, and an expiry. An approval of a governed action is an approval of one preview. Anlyon hashes the preview into a bindingDigest, stores it on the approval, and recomputes it immediately before dispatch. Any difference refuses the write.

Why bind an approval to the exact request

An approval that says “refund order 4417” is only as good as the request that runs after it. If the agent can change the amount, the recipient list or the target after a person says yes, the approval protected nothing.

  • Risk. The reviewer approves bytes, not a summary. A request that differs from what was reviewed is refused before it reaches the provider, and the receipt says why.
  • Effort. You do not build a diff view, a snapshot store or a compare-before-send step. The preview is typed data your app or the console can render.
  • Cost. A preview is a read. It never writes to the provider, so reviewing costs nothing at the destination.

This applies to every governed action: an action with an adapter (stripe.refund, github.file_update, resend.email_send) and an action that carries a declaration (impact, verify or governed: true). The preview is always on. It has no opt-out.

How it works

  1. Preview. Your code, or Anlyon on its own when you invoke without one, normalizes the input, resolves the target, reads the provider where an adapter can (never writes), and stores the preview with its bindingDigest.
  2. Gate. If the action requires approval or a policy says so, the invocation parks and an approval is created with the preview’s digest. The approval expires no later than the preview does.
  3. Decide. A person on your team (or, for a policy with decidedBy: end_user, the end user in your app) approves or denies.
  4. Dispatch. In one transaction, Anlyon recomputes the digest from the stored effect, checks the approval, the action version, the halt switch, the requesting key, current policy, dependencies and your limits, then sends the write. Any check that fails refuses the effect with nothing sent.

Create a preview and invoke it

Creating a preview needs actions:invoke. Reading one needs actions:read. Both are in the default scope set.

import { Client } from '@anlyonhq/sdk';

const agent = new Client({ apiKey: process.env.ANLYON_API_KEY! });

const input = { path: 'data/status.txt', content: 'status: green\n', message: 'Mark green' };

// Read-only. Lasts 1 hour unless you pass ttlSeconds (60 to 604800).
const { data: preview } = await agent.actions.preview('update-fixture', input, { ttlSeconds: 900 });

for (const block of preview!.blocks) console.log(block.type, block.title);
console.log(preview!.bindingDigest, preview!.expiresAt);

// Send the same input. preview.request is the normalized request, not the input.
const { data: invocation } = await agent.actions.invoke('update-fixture', input, { previewId: preview!.id });
console.log(invocation!.status, invocation!.approvalId); // pending_approval and an apr_ id when gated
curl -s -X POST https://api.anlyon.com/api/v2/actions/update-fixture/previews \
  -H "Authorization: Bearer $ANLYON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "input": { "path": "data/status.txt", "content": "status: green\n", "message": "Mark green" }, "ttlSeconds": 900 }'

curl -s -X POST https://api.anlyon.com/api/v2/actions/update-fixture/invoke \
  -H "Authorization: Bearer $ANLYON_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: mark-green-2026-10-27" \
  -d '{ "input": { "path": "data/status.txt", "content": "status: green\n", "message": "Mark green" }, "previewId": "prv_01JABCDEF" }'
import os
from anlyon import Client

agent = Client(api_key=os.environ["ANLYON_API_KEY"])

data = {"path": "data/status.txt", "content": "status: green\n", "message": "Mark green"}
preview = agent.actions.preview("update-fixture", data, ttl_seconds=900).data

invocation = agent.actions.invoke("update-fixture", data, preview_id=preview["id"]).data
print(invocation["status"], invocation["approvalId"])

The preview response is 201. Its main fields:

{
  "success": true,
  "data": {
    "id": "prv_01JABCDEF",
    "action": { "id": "act_01JABCDEF", "name": "update-fixture", "versionId": "acv_01JABCDEF" },
    "adapter": { "type": "github.file_update", "version": "1" },
    "environment": { "id": "6f1c0e2a-5b7d-4c1e-9a43-2d8b7f0e1a55", "name": "Production", "kind": "production" },
    "impact": [{ "dimension": "resource_mutations", "amount": 1 }],
    "allowances": [{ "limitId": "lim_01JABCDEF", "name": "Fixture edits", "available": 19, "requested": 1, "sufficient": true }],
    "blocks": [{ "type": "text_diff", "title": "data/status.txt", "path": "data/status.txt", "before": "status: red\n", "after": "status: green\n" }],
    "evidenceObservedAt": "2026-10-27T09:00:00.000Z",
    "expiresAt": "2026-10-27T09:15:00.000Z",
    "expired": false,
    "bindingDigest": "4c1d8e0f6a2b9d7e3f5a1c8b0e6d4f2a9b7c5e3d1f0a8b6c4e2d0f9a7b5c3e1d",
    "supersedes": null,
    "effectId": null,
    "endUserId": null
  }
}

A governed invocation gets a preview whether or not you create one first. Creating one yourself lets you show it before you ask, and lets you invoke with previewId so a changed request is refused at admission. API reference: Preview a governed invocation, Get a preview.

What a preview shows

A preview is typed data, never provider HTML. Its blocks are:

  • fields: label and value pairs, such as the environment (name and kind), target account, resource, action version, adapter, what success means, when the evidence was observed, and when the preview expires.
  • text_diff: before and after text for one path, for file changes. truncated says when it was cut.
  • impact: the quantities the operation consumes. The separate allowances array shows each applicable limit at review time, with requested and sufficient.
  • limitations: each guarantee labelled for what it is: guarantee, freshness, unsupported or irreversible.

allowances are as of review. Capacity is checked again at dispatch, and an approval holds no allowance.

The preview of a declared action

Anlyon has no adapter for the API behind a declared action, so the preview is the request itself, built from the action definition and the input. The provider is not read, and nothing is written. The request shows the method, the URL, each header, the body and the read-back. Secret references stay as {{secret:NAME}} placeholders, so the reviewed request and its digest never hold a credential.

{
  "adapter": { "type": "http.declared", "version": "1" },
  "impact": [{ "dimension": "emails", "amount": 1, "bound": "exact" }],
  "request": { "headers": { "Authorization": "Bearer {{secret:MAILER_TOKEN}}" } }
}

Let your user approve their own request

When your agent acts for one of your users, the preview records whose account it read in endUserId. An invoke with that preview must name the same end user, and only a call for that end user, or one naming none, can read it.

A policy with decidedBy: end_user, or a workspace default that sends unmatched calls to the user, puts the approval in that user’s own list instead of your team’s inbox. Your app shows it and relays the answer. The binding works exactly as for a team approval: the user approves one preview, and only that request runs.

import { Client } from '@anlyonhq/sdk';

// Your server, with a key that has end-users:approvals. user.id is your own id for the signed-in user.
const anlyon = new Client({ apiKey: process.env.ANLYON_API_KEY! });

const { data: pending } = await anlyon.endUsers.approvals.list(user.id, { status: 'pending' });

const { data: decided } = await anlyon.endUsers.approvals.decide(user.id, pending![0].id, {
  decision: 'approve',
  reason: 'Approved in the app by the account owner.',
});
console.log(decided!.invocation?.status);
curl -s "https://api.anlyon.com/api/v2/end-users/user_4417/approvals?status=pending" \
  -H "Authorization: Bearer $ANLYON_API_KEY" \
  -H "Anlyon-End-User: user_4417"

curl -s -X POST https://api.anlyon.com/api/v2/end-users/user_4417/approvals/apr_01JABCDEF/decide \
  -H "Authorization: Bearer $ANLYON_API_KEY" \
  -H "Anlyon-End-User: user_4417" \
  -H "Content-Type: application/json" \
  -d '{ "decision": "approve" }'
import os
from anlyon import Client

anlyon = Client(api_key=os.environ["ANLYON_API_KEY"])
user_id = "user_4417"  # your own id for the signed-in user

pending = anlyon.end_users.approvals.list(user_id, status="pending").data
decided = anlyon.end_users.approvals.decide(user_id, pending[0]["id"], decision="approve").data

end-users:approvals is a privileged scope that no key receives by default. An approval of another end user, or one your team decides, answers 404. See Approvals and policies and Act for your users.

What each kind of action guarantees

All four execute exactly the reviewed request. They differ on stale-state protection, and the preview’s limitations block says so:

Exact request Stale-state protection
github.file_update Yes Atomic. The write sends the blob SHA shown at review, and GitHub refuses it (409) if the file changed since. The effect is failed with the stale version recorded as evidence, and the newer content is not overwritten.
stripe.refund Yes Not atomic. The adapter sends no compare-and-set on a payment intent. The account is re-checked immediately before dispatch, and the adapter relies on Stripe to refuse a refund above what remains refundable. The refundable amount shown is as of review. The preview labels this freshness.
resend.email_send Yes None. As of 2026-10-03, Resend has no conditional send. Nothing about the recipients or the domain is checked atomically with the write.
A declared action Yes None. Anlyon does not know the API’s preconditions. The provider’s state is not checked between review and dispatch.

Refresh a preview that is out of date

Refreshing re-reads the provider for the same input and the same action version into a new preview that supersedes the old one. Its binding differs, so an approval of the old preview never carries over. A refresh never moves the review to a newer action version: if the action changed, invoking with the refreshed preview is refused with PREVIEW_MISMATCH, and you need a new preview.

const { data: fresh } = await agent.actions.refreshPreview('prv_01JABCDEF', { ttlSeconds: 600 });
console.log(fresh!.id, fresh!.supersedes); // a new prv_ id, and prv_01JABCDEF
curl -s -X POST https://api.anlyon.com/api/v2/actions/previews/prv_01JABCDEF/refresh \
  -H "Authorization: Bearer $ANLYON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "ttlSeconds": 600 }'
fresh = agent.actions.refresh_preview("prv_01JABCDEF", ttl_seconds=600).data

Refreshing needs actions:invoke. API reference: Refresh a preview.

What invalidates an approval

Three different mechanisms can stop a reviewed operation, and the receipt says which one acted.

The request changed. An invocation that names a previewId and sends a different destination, resource, amount or content is refused at admission with 409 PREVIEW_MISMATCH. No effect is created and nothing is sent.

Anlyon’s own state changed. Dispatch is refused, nothing is sent, and the receipt grades refused, when:

  • the action was edited after review (action_changed)
  • the preview expired (preview_expired). An approval never outlives its preview. Invoking with an expired previewId is refused earlier, with 409 PREVIEW_EXPIRED.
  • the approval itself expired before anyone decided (approval_expired)
  • a secret the action references is missing, or its host or placement binding no longer allows the request, or the end user’s account is no longer connected (credential_unavailable)
  • the environment is halted, the requesting key was revoked, or a policy now denies
  • the impact limits no longer have room, even if they did at review
  • the stored preview, effect and approval no longer agree on the digest (binding_mismatch)

The provider’s state changed. This is caught by the provider, where the provider has a conditional write. For GitHub, the write carries the reviewed blob SHA and GitHub refuses it. The receipt grades failed, not refused, because Anlyon did send the request.

Duplicate approval callbacks cannot run the operation twice. Consuming the approval and claiming dispatch are one conditional database write.

See When approval expires or changes for every refusal reason and what the caller sees.

Errors you may see

Status and code When What to do
409 PREVIEW_MISMATCH The invocation differs from the reviewed preview: request, action, action version, adapter, end user or binding. The message says which. Create a new preview for the request you mean to send, and have it approved.
409 PREVIEW_EXPIRED The preview passed its expiresAt. Create a new preview, or refresh the old one.
409 PREVIEW_ALREADY_USED A preview binds one effect, and this one already has one. Create a new preview for a second operation.
409 END_USER_NOT_CONNECTED, END_USER_RECONNECT_REQUIRED The preview is for an end user whose account is missing or needs a reconnect. Send the user the connectUrl from the response. See end-user connections.
404 The preview id is not in this key’s environment, or belongs to another end user. Use the key and end user that created it.

How it behaves

  • The approval binds the exact request. For stripe.refund the refundable amount shown is as of review, and the adapter re-checks the account before dispatch.
  • A change at GitHub is caught by GitHub. The write carries the reviewed blob SHA, GitHub refuses a mismatch, and the receipt grades failed.
  • The preview of a declared action shows the request. The provider is not read at review, so the preview describes the request and not the resource it will change.
  • An action with no declaration and no adapter is approved on its request snapshot. See Approvals and policies.
  • A credential is checked again at dispatch. A secret revoked or rebound after review, or an end user who disconnected, refuses the dispatch.
  • Who decides is set by role and policy. In the console, members with the admin, member or approver role in the approval’s environment can decide a team approval. An API key needs approvals:decide. A key never decides an approval it requested, and a person does not decide their own request unless they are the one member who can decide in that environment.

Was this page helpful?