Guides

Recipes

Real agent patterns. Copy, paste, adapt.

Domain purchase agent

Your Claude Code agent buys a domain on Cloudflare Registrar. Amount known in advance; silent auth.

// Agent pseudocode
const { id, last_four, expiration } = await agentpay.create_card({
  amount_cents: 1200,        // $12 domain price + a little buffer
  agent_id: "claude-code",
  purpose: "Buy mydomain.dev on Cloudflare Registrar"
})

// Reveal card number client-side using ephemeral key
const detail = await agentpay.get_card(id)
const { number, cvc } = await stripeJs.issuing.retrieveCard(
  detail.stripe_card_id,
  { ephemeralKeySecret: detail.ephemeral_key_secret }
)

// Now the agent uses { number, last_four, expiration, cvc } at the registrar.
// On successful purchase, our webhook handler captures the hold.

Budgeted research agent

Agent needs to hit paid APIs (Exa, SERP, Firecrawl). Set a $50 daily budget; use check_balance to avoid overspending.

const BUDGET_CENTS = 5000
const { held_cents } = await agentpay.check_balance()

if (held_cents >= BUDGET_CENTS) {
  return "Daily budget exhausted; will retry tomorrow"
}

const card = await agentpay.create_card({
  amount_cents: Math.min(500, BUDGET_CENTS - held_cents),
  agent_id: "research-bot",
  purpose: "Exa search queries"
})
// ... use the card ...

Human-in-the-loop high-value purchase

Agent needs to spend > $100. Policy requires approval; the agent queues and polls until the user approves.

const res = await agentpay.create_card({
  amount_cents: 15000,
  agent_id: "procurement-bot",
  purpose: "1-year domain + SSL bundle"
})

if (res.status === "PENDING_APPROVAL") {
  // Notify the user (email, Slack, whatever)
  console.log(`Waiting for approval: approval_id=${res.approval_id}`)

  // Poll or wait for a webhook. In this example: poll every 30s.
  while (true) {
    await sleep(30000)
    const approvals = await agentpay.list_approvals(`?status=APPROVED`)
    const found = approvals.data.find(a => a.id === res.approval_id)
    if (found) break
  }
}

Close-all safety switch

Something's wrong. Close every open card immediately and disable new issuance.

# Disable new cards
curl -X PUT $API/v1/policies/default \
  -H "Authorization: Bearer $KEY" \
  -d '{"approval_required": true}'

# Close every open card
curl -s "$API/v1/cards?status=OPEN" -H "Authorization: Bearer $KEY" \
  | jq -r '.data[].id' \
  | while read id; do
      echo "Closing $id"
      curl -s -X POST "$API/v1/cards/$id/close" -H "Authorization: Bearer $KEY"
    done

Bulk reconciliation — what did my agents spend this week?

Pull the last 100 cards and aggregate by agent_id. For real-time, subscribe to the card.created and hold.captured outbound webhooks on /webhooks.

const res = await fetch(`${API}/v1/cards?limit=100`, {
  headers: { Authorization: `Bearer ${key}` }
})
const { data } = await res.json()

const byAgent = data.reduce((acc, card) => {
  const id = card.agent_id ?? "unattributed"
  acc[id] = (acc[id] ?? 0) + card.amount_cents
  return acc
}, {})

console.table(byAgent)
// { "claude-code": 2400, "research-bot": 3000, ... }