Virtual cards for AI agents: pay only what a person approved

Give an AI agent a card that can only pay what a person approved: ask first with the amount, then issue a single-use Stripe Issuing card for exactly that, and check each authorization against the approval.

· 9 min read

Give an AI agent a virtual card only after a person has approved the purchase, and only for that purchase. The agent asks first, with the amount and the merchant. When a person (or a rule a workspace owner wrote in advance) approves, your server issues a single-use Stripe Issuing card capped at exactly the approved amount. A real-time authorization webhook then checks each charge against the approval and declines anything else, and the card is cancelled after one payment or when nobody used it in time.

A card limit on its own is a ceiling nobody is asked about. With €500 a month on the agent’s card, it can spend €480 on the wrong thing and the card will approve it, because €480 is under the limit. Cards are one of three places to limit what an agent spends; the map of AI agent spending controls covers the other two. This page is the card, wired so that it can only pay what a person said yes to.

Three ways to give an agent a card

Three ways to give an AI agent a card: who sees the purchase first, the most one mistake costs, and what still gets through
OptionWho sees the purchase firstMost one mistake costsWhat still gets through
A standing card with a monthly limitWho sees the purchase firstNobody. The limit was set once, weeks ago.Most one mistake costsWhatever is left of the monthly limit.What still gets throughAny wrong purchase that fits under the limit and the merchant categories.
A single-use card per taskWho sees the purchase firstNobody, unless your own code asks someone.Most one mistake costsThe amount the agent chose when it made the card.What still gets throughA wrong purchase, at the amount the agent picked.
Approval first, then a card for that amountWho sees the purchase firstA person, or a rule a workspace owner wrote in advance.Most one mistake costsThe amount that was approved, at the merchant that was approved.What still gets throughVery little: tips or fees a merchant posts later, and force posts. See below.

The third setup moves the decision before the card exists. The card stops being a budget the agent spends from and becomes a receipt for one approved purchase.

How it works

  1. Once, before the first card: in the Stripe Dashboard’s Issuing settings, set the timeout setting to decline. It decides whether an authorization your endpoint does not answer within 2 seconds is approved or declined. Autopilot (a public preview) is only on if you asked Stripe support to configure it; if you did, ask support what its rules decide for these cards, because Stripe says it can approve on your behalf when your endpoint fails.
  2. The agent calls your payment service: “buy a year of a PDF tool from Acme Software for €42.00”. It never holds the Stripe key and never sees the card number.
  3. Your service asks VariantGate with payment.purchase, the amount, the currency and the merchant, and waits for the answer.
  4. A person approves in the inbox, Slack or email, or an owner’s rule answers at once. Anything but an approval: no card.
  5. Your service creates a single-use virtual card with a spending limit of exactly the approved amount, and records which approval it belongs to.
  6. At checkout Stripe asks your authorization endpoint. It approves only a charge that matches the approval, after reading the request from VariantGate again.
  7. The card cancels itself after one payment, and a sweep cancels any card not used within 30 minutes. VariantGate hears “succeeded” only once Stripe reports the capture.

What Stripe Issuing gives you

Every control below comes from Stripe’s own documentation and API reference, checked 23 November 2026.

Stripe Issuing controls used for approval-first agent cards, what Stripe documents and how this setup uses each
OptionWhat Stripe documentsUse it here for
spending_controls.spending_limitsWhat Stripe documentsA list of amount and interval pairs, in the card’s currency and smallest unit. The intervals in Stripe’s API are per_authorization, daily, weekly, monthly, yearly and all_time. Date-based intervals start at midnight UTC.Use it here forper_authorization and all_time, both set to the approved amount, so the card can never move more than that in total.
allowed_categories / blocked_categoriesWhat Stripe documentsAllow only the listed merchant categories, or block the listed ones. The two cannot be combined.Use it here forLock the card to the kind of shop the person approved, when you know it.
allowed_merchant_countriesWhat Stripe documentsAllow or block merchants by country (ISO 3166 alpha-2 codes such as IE).Use it here forOptional: keep the card to the countries you buy from.
lifecycle_controlsWhat Stripe documentslifecycle_controls.cancel_after.payment_count cancels a virtual card after that many payments. Set to 1 it makes a single-use card.Use it here forOne approval, one payment. The card cancels itself after it.
Real-time authorizationsWhat Stripe documentsStripe sends issuing_authorization.request to your endpoint and waits 2 seconds for {"approved": true} or false, with a Stripe-Version header. Without an answer in time, your timeout settings (or Autopilot, if configured) decide.Use it here forCheck each charge against the stored approval and read the request again.
Card statusWhat Stripe documentsstatus: canceled declines every authorization with card_canceled. It is permanent.Use it here forClose the card once it has paid, or when nobody used it in time.
  • Spending controls run before the real-time authorization and can decline a charge before your endpoint hears of it.
  • Without spending_limits, a new card gets a default of 500 USD a day, and every authorization has a fixed limit of 10,000 USD.
  • To use Issuing for agents you apply in the Stripe Dashboard or contact Stripe. Local commercial issuing is offered in 24 countries: the US, the UK, Canada and 21 EU countries. A virtual card costs 0.10 USD in the US, 0.10 GBP in the UK and 0.10 EUR in the EU.

Step 1: ask first, with the amount and the merchant

Both clients use the same agent key. That matters: in VariantGate only the key that asked can read the answer, and any other key gets a 404. So the service that asks is the one that later checks authorizations. The second client gives up after one second, for reasons in step 3.

import { ApprovalClient } from "@variantgate/agent";
import Stripe from "stripe";

// The stripe-mock settings are only for the test run; drop them in production.
const mock = process.env.STRIPE_MOCK_PORT;
const local = { host: "localhost", port: Number(mock), protocol: "http" as const };
export const stripe = new Stripe(
  process.env.STRIPE_SECRET_KEY ?? "",
  mock ? local : {}
);

const options = {
  agent: "procurement-bot",
  apiUrl: process.env.VARIANTGATE_API_URL ?? "https://api.variantgate.com",
  key: process.env.VARIANTGATE_KEY ?? "",
};
export const approvals = new ApprovalClient(options);

// Stripe gives the authorization webhook 2 seconds, so this client gives up
// on VariantGate after 1. A timeout throws, and the caller declines.
export const quickApprovals = new ApprovalClient({
  ...options,
  fetch: (input, init) =>
    fetch(input, { ...init, signal: AbortSignal.timeout(1000) }),
});
import type { Decision } from "@variantgate/agent/types";
import { approvals } from "./clients.js";

export interface Purchase {
  amount: string; // "42.00"
  currency: "EUR";
  item: string;
  merchant: string;
}

/** Asks first, with the amount and the merchant, and waits for the answer. */
export async function askToBuy(purchase: Purchase): Promise<Decision> {
  const asked = await approvals.ask(
    {
      action: "payment.purchase",
      amount: purchase.amount,
      currency: purchase.currency,
      details: { item: purchase.item, merchant: purchase.merchant },
      summary: `Buy ${purchase.item} from ${purchase.merchant} for ${purchase.amount} ${purchase.currency}`,
    },
    30
  );
  // Waits until a person decides or the request expires (15 minutes by
  // default). Still pending at the end means withdrawn, never approved.
  return approvals.waitForDecision(asked);
}

The merchant goes in details, which the person deciding sees. Small, routine purchases do not need a person each time: on Pro, a rule such as “always allow payment.purchase up to €50, €300 a week” answers them at once, and everything above goes to the inbox. The approval limit calculator helps pick that line, and spending limits for AI agents explains how per-payment caps, budgets and two-person approval fit together.

Step 2: issue a card for exactly the approved amount

The card records which approval it belongs to. In the example it lives in memory; in production it is a table with a unique key on the request id.

/** One approval, and the one card issued for it. */
export interface IssuedCard {
  amount: number; // approved amount, in minor units
  authorizedBy: string | null; // the authorization approved for the purchase
  canceled: boolean;
  capturedBy: string | null; // the transaction that moved the money
  cardId: string | null;
  currency: string; // lower case, as Stripe writes it
  merchant: string; // lower case, matched against the authorization
  requestId: string;
  settled: boolean; // outcome reported to VariantGate
  useBy: number; // after this time the card is cancelled
}

/**
 * In memory for the example. In production use a table with a unique key on
 * request_id, and updates that set a field only where it is still null.
 */
const cards = new Map<string, IssuedCard>();

export function claim(card: IssuedCard): boolean {
  if (cards.has(card.requestId)) return false;
  cards.set(card.requestId, card);
  return true;
}

export const release = (requestId: string) => cards.delete(requestId);

export const find = (requestId: string) => cards.get(requestId);

export const findByCard = (cardId: string) =>
  [...cards.values()].find((card) => card.cardId === cardId);

export function markAuthorized(requestId: string, authorizationId: string) {
  const card = cards.get(requestId);
  if (!card || card.authorizedBy !== null) return false;
  card.authorizedBy = authorizationId;
  return true;
}

export const all = () => [...cards.values()];
import type { Decision } from "@variantgate/agent/types";
import type Stripe from "stripe";
import { stripe } from "./clients.js";
import { claim, type IssuedCard, release } from "./store.js";

const CARDHOLDER = process.env.STRIPE_AGENT_CARDHOLDER ?? ""; // ich_...
const CARD_CURRENCY = "eur"; // the currency of your Issuing balance
const USE_WITHIN_MS = 30 * 60 * 1000;
const MONEY = /^(\d{1,7})(?:\.(\d{1,2}))?$/;

/** "42.5" becomes 4250. Anything else throws, so nothing is issued. */
export function toMinorUnits(amount: string): number {
  const match = MONEY.exec(amount);
  if (!match) throw new Error("approved amount is not a plain decimal");
  return Number(match[1]) * 100 + Number((match[2] ?? "").padEnd(2, "0"));
}

type Category = Stripe.Issuing.CardCreateParams.SpendingControls.AllowedCategory;

/** One approval, one single-use card for exactly the approved amount. */
export async function issueCard(decision: Decision, categories?: Category[]) {
  const merchant = decision.details.merchant;
  if (!decision.allowed || decision.changed || typeof merchant !== "string") {
    throw new Error("not approved as asked: no card");
  }
  const currency = (decision.currency ?? "").toLowerCase();
  if (currency !== CARD_CURRENCY) throw new Error("other currency: no card");
  const amount = toMinorUnits(decision.approved_amount ?? "");
  const card: IssuedCard = {
    amount,
    authorizedBy: null,
    canceled: false,
    capturedBy: null,
    cardId: null,
    currency,
    merchant: merchant.toLowerCase(),
    requestId: decision.id,
    settled: false,
    useBy: Date.now() + USE_WITHIN_MS,
  };
  // Claim before the first await, so two calls cannot issue two cards.
  if (!claim(card)) throw new Error("this approval already has a card");
  const created = await createCard(card, categories).catch((error) => {
    // Nothing was issued: free the approval. A retry reuses the same
    // idempotency key, so it cannot make a second card either.
    release(card.requestId);
    throw error;
  });
  card.cardId = created.id;
  return created.id;
}

function createCard(card: IssuedCard, categories?: Category[]) {
  const { amount, currency, requestId } = card;
  return stripe.issuing.cards.create(
    {
      cardholder: CARDHOLDER,
      currency,
      lifecycle_controls: { cancel_after: { payment_count: 1 } },
      metadata: { variantgate_request: requestId },
      spending_controls: {
        ...(categories ? { allowed_categories: categories } : {}),
        spending_limits: [
          { amount, interval: "per_authorization" },
          { amount, interval: "all_time" },
        ],
      },
      status: "active",
      type: "virtual",
    },
    { idempotencyKey: `variantgate-card-${requestId}` }
  );
}
  • The limit is approved_amount, never the amount the agent asked for. A person may approve a narrower version; this code then issues nothing (changed is true) and the agent asks again.
  • The claim happens before the first await, and the idempotency key is the request id, so a retry or a second call cannot turn one approval into two cards.
  • Any doubt throws before a card exists: an amount that is not a plain decimal, a currency your Issuing balance does not use, no merchant.

Then the payment service pays, not the agent. Stripe returns the full number and CVC of a virtual card only in live mode and only when you ask for them with expand, and recommends the Dashboard or Issuing Elements over the API for PCI-DSS reasons. The service fills in the merchant’s checkout itself, for example in the browser session it runs for the agent. The number and CVC never reach the model, its context or a log.

Step 3: check every authorization

The card’s limit is one lock. The authorization endpoint is the second. Inside it, any error, any mismatch and a slow VariantGate all answer {"approved": false}. What it cannot cover is Stripe not hearing from it at all: then the timeout setting from the first step decides, or Autopilot if you have it.

import type Stripe from "stripe";
import { quickApprovals, stripe } from "./clients.js";
import { find, markAuthorized } from "./store.js";

const SECRET = process.env.STRIPE_AUTH_WEBHOOK_SECRET ?? ""; // whsec_...
const STRIPE_VERSION = "2026-11-18.endive"; // the API version you use
// Merchants test a card with tiny authorizations (Stripe names 1 USD or less),
// so one that small does not count as the purchase.
const CARD_CHECK = 100;

/** The synchronous endpoint Stripe calls for issuing_authorization.request. */
export async function POST(request: Request): Promise<Response> {
  const body = await request.text();
  let event: Stripe.Event;
  try {
    const signature = request.headers.get("stripe-signature") ?? "";
    event = stripe.webhooks.constructEvent(body, signature, SECRET);
  } catch {
    return new Response("bad signature", { status: 400 });
  }
  let approved = false;
  if (event.type === "issuing_authorization.request") {
    // Any error in here, including a slow VariantGate, declines. If Stripe
    // gets no answer at all, your timeout settings or Autopilot decide.
    approved = await shouldApprove(event.data.object).catch(() => false);
    // Log ids only: never the card number, CVC or the whole event.
    console.info("authorization", { approved, id: event.data.object.id });
  }
  return Response.json(
    { approved },
    { headers: { "Stripe-Version": STRIPE_VERSION } }
  );
}

async function shouldApprove(auth: Stripe.Issuing.Authorization) {
  const requestId = auth.card.metadata.variantgate_request;
  const card = requestId ? find(requestId) : undefined;
  const pending = auth.pending_request;
  if (!card || !pending || card.cardId !== auth.card.id) return false;
  if (card.authorizedBy !== null || Date.now() > card.useBy) return false;
  // Compare with what was stored at approval, not with the event alone.
  const sameMoney =
    pending.currency === card.currency &&
    pending.merchant_currency === card.currency &&
    pending.amount > 0 &&
    pending.amount <= card.amount;
  const name = (auth.merchant_data.name ?? "").toLowerCase();
  if (!sameMoney || !name.includes(card.merchant)) return false;
  // A webhook is never a permission: read the request again now. This also
  // declines while the workspace or this agent is paused.
  const decision = await quickApprovals.check(card.requestId);
  if (!decision.allowed || decision.outcome !== null) return false;
  if (pending.amount <= CARD_CHECK) return true;
  return markAuthorized(card.requestId, auth.id);
}

What it checks, and why

  • The amount and currency are compared with what was stored at approval, not taken from the event on its own.
  • The merchant name must contain the merchant the person approved. If a shop’s name on the authorization does not match, the charge is declined and the agent asks again: the cautious failure.
  • A webhook is never a permission, so the endpoint reads GET /v1/requests/{id} again. While the workspace or this agent is paused from the emergency stop, allowed is false, so a card already handed out stops working until an owner resumes.
  • Stripe waits 2 seconds. The quick client gives VariantGate one, and a timeout throws, which declines. Watch request_history.reason on issuing_authorization.created for webhook_timeout or webhook_error: those are decisions your endpoint did not make.
  • A merchant may first send a tiny authorization to check the card. Stripe’s lifecycle controls do not count an uncaptured one of 1 USD or less toward payment_count, and allow only that many of them. The endpoint likewise approves one of 100 minor units or less when every other check passes, but does not count it as the purchase, so the real charge still goes through.

Step 4: cancel the card and report the outcome

An approved authorization is not yet money moved: the merchant may reverse it or never capture it. So the outcome comes from issuing_transaction.created, which Stripe sends to your regular webhook endpoint, since the authorization endpoint only receives authorization requests.

import type Stripe from "stripe";
import { stripe } from "./clients.js";
import { findByCard } from "./store.js";

// Your regular webhook endpoint, not the authorization one: Stripe sends only
// authorization requests to that.
const SECRET = process.env.STRIPE_EVENTS_WEBHOOK_SECRET ?? ""; // whsec_...

/** Records the capture: the moment money really moved on the card. */
export async function POST(request: Request): Promise<Response> {
  const body = await request.text();
  let event: Stripe.Event;
  try {
    const signature = request.headers.get("stripe-signature") ?? "";
    event = stripe.webhooks.constructEvent(body, signature, SECRET);
  } catch {
    return new Response("bad signature", { status: 400 });
  }
  if (event.type === "issuing_transaction.created") {
    const transaction = event.data.object;
    const cardId =
      typeof transaction.card === "string" ? transaction.card : transaction.card.id;
    const card = findByCard(cardId);
    if (card && transaction.type === "capture" && card.capturedBy === null) {
      card.capturedBy = transaction.id;
    }
  }
  return new Response(null, { status: 204 });
}

An approval in VariantGate does not expire once given, so the card needs its own deadline. The sweep cancels cards that were captured (if the single-use control has not already) and cards nobody used within 30 minutes. It reports succeeded after a capture, failed for an unused card or one still not captured 7 days after its deadline, and treats a 409 as already reported. One card failing does not stop the rest.

import { ApprovalApiError } from "@variantgate/agent/errors";
import type { Outcome } from "@variantgate/agent/types";
import { approvals, stripe } from "./clients.js";
import { all, type IssuedCard } from "./store.js";

// Stripe says a purchase usually settles 1 to 2 days after authorization.
const CAPTURE_WITHIN_MS = 7 * 24 * 60 * 60 * 1000;

/** Run every minute. One card failing does not stop the others. */
export async function sweep(now = Date.now()) {
  for (const card of all()) {
    try {
      await settle(card, now);
    } catch (error) {
      const reason = error instanceof Error ? error.message : "unknown";
      console.error("settle failed", { reason, request: card.requestId });
    }
  }
}

async function settle(card: IssuedCard, now: number) {
  if (card.cardId === null || card.settled) return;
  const done = card.capturedBy !== null || now > card.useBy;
  if (done && !card.canceled) {
    // "canceled" is permanent. A single-use card may have done it already.
    const current = await stripe.issuing.cards.retrieve(card.cardId);
    if (current.status !== "canceled") {
      await stripe.issuing.cards.update(card.cardId, { status: "canceled" });
    }
    card.canceled = true;
  }
  if (card.capturedBy !== null) {
    await report(card, "succeeded", `captured in ${card.capturedBy}`);
  } else if (card.authorizedBy === null && now > card.useBy) {
    await report(card, "failed", "card not used in time, cancelled");
  } else if (now > card.useBy + CAPTURE_WITHIN_MS) {
    await report(card, "failed", "authorized but never captured");
  }
}

async function report(card: IssuedCard, outcome: Outcome, note: string) {
  try {
    await approvals.reportOutcome(card.requestId, outcome, note);
  } catch (error) {
    // 409: the outcome was already reported, by an earlier run.
    if (!(error instanceof ApprovalApiError && error.status === 409)) throw error;
  }
  card.settled = true;
}

Where a card limit can still be exceeded

Stripe’s documentation names a few ways money can move past these controls. Reconcile against the approval rather than assume the card held:

  • Tips and fees can be posted later and exceed a spending limit.
  • Spending totals are best effort, with up to 30 seconds of delay. The single-use control and the authorizedBy check cover that gap here.
  • Force posts must be processed under network rules, even after a single-use card was cancelled. You may need to dispute them.
  • With Stripe Autopilot on your own card ranges (BINs), Stripe can decline while the card network approves. Stripe then holds no funds, but they might still be captured.
  • A purchase settles into a transaction usually 1 to 2 days after the authorization. Compare the settled amount with the approved one when it arrives.

What we ran, and what we did not

We type-checked all seven files above with TypeScript 7.0.2, the stripe package 23.2.0 (API version 2026-11-18.endive) and @variantgate/agent 0.11.0. We then ran them against stripe-mock, Stripe’s mock server, which checks request parameters against Stripe’s OpenAPI specification: creating a cardholder, the card with its lifecycle and spending controls and idempotency key, reading it, and cancelling it. stripe-mock refused a made-up interval and a made-up merchant category, so the parameter shapes and values here are ones Stripe’s specification accepts. After that refused create, the approval was free again and the next attempt issued the card.

We fed both endpoints signed test events made with the stripe package. The authorization endpoint declined a charge over the approved amount, one at another merchant, one in another currency, one while the workspace was paused, one while VariantGate took 1.5 seconds to answer, and a second purchase on the same card. It approved a 1.00 card check without counting it, then the matching charge, and refused a bad signature with a 400. The sweep reported succeeded only after the capture event, treated a second report’s 409 as already settled, reported an unused card as failed, and carried on past a card whose report failed. VariantGate was a local stand-in answering in the API’s shapes. We did not run the “authorized but never captured” branch.

stripe-mock does not keep state or enforce limits, so none of this shows a live card declining, and it cannot show what your timeout setting or Autopilot does. Live behaviour needs a Stripe account with Issuing. With the Stripe CLI, stripe listen forwards events to your machine and stripe trigger issuing_authorization.request sends a test authorization request.

Where to go next

Sources

  1. Stripe Docs: Issuing for agents (single-use cards, real-time authorizations with a 2-second default timeout, apply in the Dashboard)
  2. Stripe Docs: Issuing spending controls (the spending_controls parameters, default limits, best-effort aggregation, tips and fees posted later)
  3. Stripe Docs: Issuing lifecycle controls (cancel_after.payment_count, what counts as a payment, force posts after cancellation)
  4. Stripe Docs: Issuing real-time authorizations (the JSON response, Stripe-Version header, 2-second timeout settings, Autopilot)
  5. Stripe Docs: Virtual cards with Issuing (retrieving number and CVC, PCI-DSS, cost per virtual card)
  6. Stripe API reference: Create a card (lifecycle_controls, metadata, spending_controls, status)
  7. Stripe API reference: Update a card (status canceled is permanent)
  8. Stripe Docs: Use Stripe Issuing in different countries (local commercial issuing in 24 countries)
  9. stripe-mock: Stripe's mock HTTP server, which answers from Stripe's OpenAPI specification

Give your agents somewhere to ask.

Free for 100 requests a month. Sign in with your email and have a first request waiting a few minutes from now.

Start free