Skip to content

04Actions · What is it attempting?

An action is one consequential step an agent wants to take: a refund, a deletion, a deploy, an email. The agent asks Gasket before doing it, gets a decision in the same response, and reports the outcome after. Pick a path to see every state and event it produces.
  1. requestedaction.requested · agentPOST /v1/actions
  2. pending_approvalapproval.requested · policy · rule 2
  3. authorizedapproval.approved · a person, in the dashboard
  4. succeededaction.succeeded · agentPOST /v1/actions/:id/result

The contract

  1. 01RequestPOST /v1/actions with the agent, the service, the operation, and optionally an amount, input and idempotency key. Each new request costs one usage unit; repeats with the same key are free.
  2. 02DecisionThe response carries the status: authorized, denied or pending_approval, with the rule and policy version that decided it.
  3. 03ExecutionYour agent performs the operation itself, with its own access, only when the status is authorized. Gasket never calls the system on its behalf today.
  4. 04ResultPOST /v1/actions/:id/result with succeeded or failed (and output or error). That closes the record.
  5. 05PollingGET /v1/actions/:id returns the current status, for example while a person decides. Free, and it applies expiry on read.

The whole integration

Wrap the consequential call. That’s it: no SDK, no agent framework requirement.

refund.ts
async function refundWithGasket(charge: string, amount: number) {
  const res = await fetch("https://usegasket.xyz/api/v1/actions", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.GASKET_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      agent_id: process.env.GASKET_AGENT_ID,
      service: "stripe",
      operation: "refund.create",
      amount,
      input: { charge },
      idempotency_key: `refund-${charge}`,
    }),
  });
  const action = await res.json();
  if (action.status !== "authorized") return action; // denied or waiting on a person

  try {
    const refund = await stripe.refunds.create({ charge, amount });
    await report(action.id, { status: "succeeded", output: { refund: refund.id } });
  } catch (e) {
    await report(action.id, { status: "failed", error: String(e) });
  }
}
Actions in the docs →