# Cards for agents

A registered agent gets a virtual card. The card is issued through the card processor's Issuing (Stripe), on the agent's customer's own card account. When a merchant charges it, the processor asks Skerry, and the agent's spend policies decide in the moment.

Status: preview, off by default, built from the processor's Issuing documentation (docs.stripe.com/issuing/agents, read 17 November 2026) and not run against it. Every call answers 409 `capability_off` (capability `agent_cards`) until three things are true:
- `SKERRY_AGENT_CARDS_ENABLED=true` for the deployment.
- The processor's key is set.
- The processor has enabled Issuing on the customer's account, which only the processor can do.

Until then, every authorisation the processor asks about is declined.

Skerry holds no card numbers. The processor keeps the number, the expiry and the security code. What Skerry keeps is the processor's id for the card, its last four digits and the limits set on it.

## Operations

| Operation | Scope | Idempotency-Key | Moves money | What it does |
|---|---|---|---|---|
| `POST /agents/{id}/cards` | `agents:write` | optional | no | Issue the agent a virtual card through the card processor's Issuing, on its customer's own card account, with at least one spending limit (`spending_limits: [{ amount, interval }]`), optional `allowed_categories` or `blocked_categories`, and `payment_count` to cancel it after that many payments. |
| `GET /agents/{id}/cards` | `agents:read` | none | no | The agent's cards, active, frozen and canceled. |
| `GET /agents/{id}/cards/{card_id}` | `agents:read` | none | no | One card, with its latest authorisations: the merchant, the amount, whether it was approved, and the policy or the reason that decided. |
| `POST /agents/{id}/cards/{card_id}/freeze` | `agents:write` | none | no | Freeze a card: every authorisation is declined until it is unfrozen. |
| `POST /agents/{id}/cards/{card_id}/unfreeze` | `agents:write` | none | no | Unfreeze a frozen card. |
| `POST /agents/{id}/cards/{card_id}/cancel` | `agents:write` | none | no | Cancel a card at the processor. |
| `POST /agents/{id}/cards/{card_id}/ephemeral-keys` | `agents:write` | none | no | An ephemeral key for reading the card's number and security code from the processor's Issuing Elements. |

## Issuing a card

```text
POST /agents/agt_…/cards
Idempotency-Key: 6c1d…

{ "currency": "usd",
  "spending_limits": [ { "amount": 5000, "interval": "per_authorization" }, { "amount": 50000, "interval": "monthly" } ],
  "allowed_categories": [ "computer_software_stores" ],
  "payment_count": 10,
  "label": "Research subscriptions",
  "billing_address": { "line1": "1 Main St", "city": "Austin", "state": "TX", "postal_code": "78701", "country": "US" } }
```

**Request fields:**
- **Spending limits:** at least one is required, so no card is issued without a bound. The interval is `per_authorization`, `daily`, `weekly`, `monthly`, `yearly` or `all_time`. The processor applies these limits itself, whatever Skerry answers.
- **Categories:** `allowed_categories` or `blocked_categories` (not both) take the processor's merchant category names.
- **`payment_count`:** cancels the card after that many payments, using the processor's lifecycle controls.
- **`billing_address`:** the first card of a customer needs it. The processor keeps it on the cardholder.

The cardholder is the customer itself, one per customer and environment, made with that first card.

**Who may issue:**
- The agent must act for a customer: it must be registered with a `customer_id`.
- The customer must have a card account (onboarded for card payments).
- The agent's own credential may issue and manage its own cards, and no other agent's.

## Each authorisation

When a merchant charges the card, the processor sends `issuing_authorization.request` to `/hooks/stripe/{mode}` and waits two seconds for the answer. Skerry declines when:
- the card is frozen or canceled;
- the agent, or an agent it was delegated from, is suspended or revoked;
- the currency is not the card's;
- the agent's spend policies refuse the payment.

The policies check each authorisation as `agent_payment.create`, with the merchant's name as the merchant and its network id as the payee. These are the same limits, lists and daily and monthly totals that bound the agent's other payments. An agent with no policy is refused, because a card is always spent under one. A payment a policy would hold for a person is declined: no person can decide in two seconds.

An approved authorisation counts against the policies' totals at once. If it is later reversed or expires, that amount is given back. What the merchant finally took is recorded from `issuing_transaction.created`. The same authorisation asked about twice gets the same answer.

Every decision is kept with the card (`GET /agents/{id}/cards/{card_id}` shows the latest 25) and sent as the event `agent_card.authorization`. Its fields:
- `approved`;
- `decline_code`, such as `limit_exceeded`, `merchant_not_allowed`, `approval_required`, `card_inactive` or `agent_inactive`;
- the policies it ran under.

## Reading the card number

The number never passes through Skerry. The agent, or a page it runs, gets it from the processor with an ephemeral key:

1. The processor's client library (Stripe.js, Issuing Elements) makes a nonce for the card.
2. `POST /agents/{id}/cards/{card_id}/ephemeral-keys` with that `nonce` and the `api_version` the library uses answers with the key's `secret`, the processor's card id and the account.
3. The library reads the number with them.

## Freezing and canceling

- `freeze` sets the card inactive at the processor, and every authorisation is declined until `unfreeze`.
- `cancel` is final.
- A card the processor freezes or cancels on its own (for example when `payment_count` is reached) is updated here from `issuing_card.updated`.

Each change is sent as `agent_card.updated`.

## Settings

| Setting | What it does |
|---|---|
| `SKERRY_AGENT_CARDS_ENABLED` | `true` switches the feature on for the deployment. |
| `SKERRY_STRIPE_TEST_SECRET_KEY`, `SKERRY_STRIPE_LIVE_SECRET_KEY` | The processor's keys (existing). |
| The processor's Connect webhook | Must send `issuing_authorization.request`, `issuing_authorization.created`, `issuing_authorization.updated`, `issuing_transaction.created` and `issuing_card.updated` to `/hooks/stripe/{mode}`. |

## Not offered

- Physical cards.
- The processor's shared payment tokens made from an Issuing card (its programmatic checkout, a private preview).
- Card disputes.
- Changing a card's limits after it is issued: cancel it and issue another.
- An authorisation whose amount is captured higher than approved is recorded and not counted again.
