Skip to content

External agent cards (Mercury)

If your business banks with Mercury, you can create agent cards in Mercury’s app and link them to a Xaalis agent wallet. Xaalis then watches each linked card: it records every charge Mercury reports and tells you by webhook and email. It can also freeze a card, at your request, at the agent’s, or by an automatic rule you set. Unfreezing happens only in Mercury’s app.

Xaalis agent card External card (Mercury)
Issued by Xaalis Mercury, in your Mercury account
Whose money a USD card wallet you fund through Xaalis your Mercury account; Xaalis holds, moves and converts nothing
Card number and limits set through Xaalis; the number is shown to the owner in the dashboard created, limited and revealed in Mercury’s app
Before a charge Xaalis approves or declines it (declarations, card policy) Xaalis is not asked; Mercury decides
After a charge an authorization (cau_…) and a hold in the wallet a recorded charge (echg_…) and a notification
Freeze POST /v1/agent_cards/{id}/freeze you, the agent or an automatic rule (below)
Unfreeze none: issue a new card only in Mercury’s app
Ids card_… ecard_…

The difference that matters: Xaalis cannot stop a Mercury charge before it happens. Watching and automatic freezes react after Mercury reports a charge. To limit what a charge can be, set the card’s limits in Mercury.

Linking a card moves no money and changes nothing in the wallet’s balance. A Mercury card can be linked to any of your agent wallets (aw_…); the wallet only tells Xaalis which agent the card belongs to.

Caller Can
The owner: an unrestricted secret key (sk_test_…, sk_live_…) list linkable cards, link and unlink, freeze, read and change automatic rules, read charges
The agent’s wallet key (ak_…) read its own wallet’s charges, freeze its own wallet’s cards (details)

Restricted keys and OAuth tokens answer 403 forbidden on every owner endpoint. The dashboard has no external-cards screen yet: use the API.

  1. In Mercury’s app, create an agent card and set its spending limit.

  2. List the Mercury cards you can link. Cards are masked (no number, expiry or CVC); agent cards come first, and cards already linked are left out:

    Terminal window
    curl https://sandbox-api.xaalis.org/v1/mercury/cards \
    -H "Authorization: Bearer $XAALIS_API_KEY"

    Each card has Mercury’s id (a UUID), last4, nickname, is_agent_card, status and spend_limit.

  3. Link one to a wallet with POST /v1/external_agent_cards. It takes an Idempotency-Key:

    Terminal window
    curl https://sandbox-api.xaalis.org/v1/external_agent_cards \
    -H "Authorization: Bearer $XAALIS_API_KEY" -H "Idempotency-Key: link-infra-card" \
    -H "Content-Type: application/json" \
    -d '{"wallet_id":"aw_…","issuer_card_id":"0b6f2f8e-4c1d-4b8a-9a77-3f7d2e1c9a10"}'

It answers 201 with an external_agent_card:

{
"object": "external_agent_card", "id": "ecard_…", "wallet_id": "aw_…", "issuer": "mercury",
"issuer_card_id": "0b6f2f8e-4c1d-4b8a-9a77-3f7d2e1c9a10", "livemode": false, "last4": "1234",
"nickname": "Infra agent", "is_agent_card": true, "status": "active",
"spend_limit": { "amount": 50000, "currency": "USD", "interval": "monthly" },
"linked": true, "freeze_pending": false,
"unfreeze_instructions": "Unfreeze agent cards only in Mercury's app.", "created_at": "2026-11-11T10:42:00.000Z"
}
Field Meaning
status Mercury’s status as Xaalis last saw it: active, frozen, cancelled, inactive, expired, suspended or singleUseConsumed
spend_limit the limit set in Mercury, in cents (50000 = $500.00), or null
linked false once you unlink it
freeze_pending true while a freeze is asked for but Mercury hasn’t confirmed it (Freeze a card)

Rules:

  • The wallet must be yours, in the same mode (test or live), and active; a disabled wallet answers 409 invalid_state.
  • A Mercury card is linked once, ever. A card that was linked before, even if it is unlinked now, answers 409 invalid_state: its charges stay attributed to the first wallet. For another agent, create a new card in Mercury.
  • The same Idempotency-Key with the same body returns the same link; with a different body it answers 409 idempotency_conflict.

GET /v1/external_agent_cards?wallet_id=aw_… lists a wallet’s links, unlinked ones included, with limit and starting_after. Today the order is not by date; the next API release lists newest first by created_at. DELETE /v1/external_agent_cards/{id} unlinks a card: Xaalis stops watching it, its past charges stay readable, and calling it again returns the same unlinked card. Unlinking is refused with 409 invalid_state while a freeze is pending.

  • Mercury notifies Xaalis of card transactions. Xaalis never trusts the notification itself: it reads the transaction back from Mercury before recording anything. It can also check linked cards on a schedule, so a missed notification is caught later.
  • Only card charges on a linked card are recorded, as one external_card_charge (echg_…) per Mercury transaction, however many times Mercury reports it. Charges made before you linked the card can show up too.
  • A new charge sends agent_card.external_charge. When its status, amount, currency, merchant name or category changes, agent_card.external_charge.updated is sent, once per change; a report that changes nothing sends nothing.
  • Each owner also gets an email, unless payout emails are turned off in the dashboard’s notification settings.
  • Owners who use the Xaalis WhatsApp assistant also get a message there, while their chat with it is open (WhatsApp’s 24-hour window). The message says your Xaalis balance doesn’t change, and it offers no way to unfreeze.

Read them — you: GET /v1/external-card-wallets/{wallet_id}/charges. The agent: GET /v1/agent/external_card_charges. Both take limit and starting_after. Today they come in a stable order that is not by date and a charge has no timestamp, so page through to the end rather than reading the first page as the latest charges. The next API release lists newest first and adds created_at to each charge: the time Xaalis first saw it, not Mercury’s own time.

{
"object": "external_card_charge", "id": "echg_…", "wallet_id": "aw_…", "card_id": "ecard_…",
"amount": -1234, "currency": "USD", "merchant_name": "Example Registrar", "merchant_category": "5734",
"status": "pending", "issuer": "mercury", "last4": "1234"
}
Field Meaning
amount a signed integer in the minor unit of currency (cents for USD), exactly as Mercury reports it. Xaalis does not yet confirm which sign Mercury uses for a debit, so don’t read “spent” or “refunded” from it.
currency the merchant’s currency when Mercury reports one, otherwise USD. It is not converted, and it is not XOF
merchant_name display text from the card network; it doesn’t prove where the card was used
merchant_category the merchant category code (MCC), or null
status pending, sent, cancelled, failed, reversed or blocked

Three ways to freeze a linked card:

  • You: POST /v1/external_agent_cards/{id}/freeze, with an Idempotency-Key.
  • The agent: POST /v1/agent/external_cards/{id}/freeze with its wallet key, for its own wallet’s cards only.
  • A rule: an automatic freeze rule after a charge breaks it.

What happens:

  1. Xaalis records the freeze request first, then asks Mercury to freeze the card.
  2. When Mercury confirms (frozen, or the card is cancelled), the call answers 200 with the card, and Xaalis sends agent_card.external_frozen, emails the owners and tells them on WhatsApp as above.
  3. If Mercury doesn’t confirm, the call answers 503 provider_error and the card shows freeze_pending: true. Xaalis keeps retrying in the background until Mercury confirms. A 503 here does not mean nothing happened; calling freeze again is safe and retries at once.

Freezing an already frozen card checks Mercury again: if someone reactivated it in Mercury’s app, Xaalis freezes it again and notifies you; otherwise nothing new is sent. A cancelled card is returned as it is, and an unlinked card answers 404. A freeze stops later charges; it doesn’t reverse a charge already made.

There is no unfreeze in the Xaalis API. Unfreeze the card in Mercury’s app; the card’s unfreeze_instructions says so.

Each wallet has rules that are off by default. Read and change them with GET / PATCH /v1/external-card-wallets/{wallet_id}/policy:

Field Meaning
enabled false by default; nothing is frozen automatically until you set true
mcc_allowlist up to 100 merchant category codes (4 digits). Empty means no category rule
max_charge_amount the largest charge allowed, in the minor unit of currency, or null for no amount rule
currency the currency of max_charge_amount; USD by default
Terminal window
curl -X PATCH https://sandbox-api.xaalis.org/v1/external-card-wallets/aw_…/policy \
-H "Authorization: Bearer $XAALIS_API_KEY" -H "Content-Type: application/json" \
-d '{"enabled":true,"mcc_allowlist":["5734","4816"],"max_charge_amount":5000,"currency":"USD"}'

A PATCH replaces the whole set: a field you leave out goes back to its default. When enabled is true, a spending card charge (a negative amount) that is pending or sent asks for a freeze if:

  • mcc_allowlist isn’t empty and the charge’s category isn’t in it (a charge with no category counts as outside);
  • max_charge_amount is set and the amount is larger in size, or in another currency than currency.

That freeze works like yours: same 503 handling, same webhook. The rule reacts to a charge Mercury has already reported, so it can’t block that charge, and it never approves anything.

A wallet key (ak_test_…, ak_live_…) can:

  • read the charges on its wallet’s cards: GET /v1/agent/external_card_charges;
  • freeze one of its wallet’s linked cards: POST /v1/agent/external_cards/{id}/freeze, with an Idempotency-Key. It finds the card’s id in the card_id of its charges. Another wallet’s card answers 404.

Both work even after you disable the wallet, so an agent you have stopped can still freeze its own card. The key can’t list linkable cards or linked cards, link or unlink, change the rules, read other wallets, or unfreeze. No API returns a Mercury card number, expiry date or CVC, to an agent or to you.

Test keys always use a mock Mercury: a test request never reaches Mercury. Today, at https://sandbox-api.xaalis.org, that mock has no cards and the sandbox has no endpoint to add one, so:

  • GET /v1/mercury/cards answers an empty list, and there is no card to link yet;
  • charge lists stay empty and no agent_card.external_* webhook is sent in test mode;
  • you can still test access and the rules on a test agent wallet: GET / PATCH /v1/external-card-wallets/{id}/policy, GET /v1/external_agent_cards?wallet_id=…, and a restricted key getting 403.

The sandbox cannot link a card today. Build your webhook handler from the payloads in Webhooks. On the live API, https://api.xaalis.org, test keys answer 403 forbidden.

The next releases of the MCP server, the @xaalis/ai-tools catalog, the Python SDK’s AI toolkit and the xaalis CLI add two tools for the agent’s key: xaalis_agent_list_mercury_card_charges (its charges) and xaalis_agent_freeze_mercury_card (freeze one of its cards). The CLI also gets xaalis mercury charges, cards and freeze. None of them links, unlinks or unfreezes a card, and the PHP SDK has none. Until then, call the HTTP endpoints above.

Event When
agent_card.external_charge Mercury reported a new charge on a linked card
agent_card.external_charge.updated a recorded charge changed: status, amount, currency, merchant name or category
agent_card.external_frozen Xaalis froze a linked card and Mercury confirmed it

Payloads are in Webhooks.

Live external cards are limited and not generally available. Until Xaalis has switched them on for your account, every live external-card call answers 403 forbidden. When they are on:

  • the owner links cards, changes the rules and freezes with an unrestricted sk_live_ key;
  • the agent’s ak_live_ key reads its charges and freezes its own cards, as in the sandbox.

Unlike Xaalis agent cards, an unrestricted sk_live_ key can manage external cards, including turning automatic freezes off. Never give it to an agent: an agent gets its wallet key only.

See also: Agent cards · Agent wallets · Webhooks · Idempotency