> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentcard.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Ophelia

> Use Agentcard with Ophelia to let your agent book tables on OpenTable and Resy with your users' cards.

[Ophelia](https://www.opheliaos.com) books restaurant tables on OpenTable and Resy through one API. When a venue needs a card to hold the table, Ophelia pauses the booking and hands you the venue's card request. You post that request to Agentcard, the user approves it with their passkey, and their device puts their real card into the request. You hand the processor's answer back to Ophelia, and the venue holds the table. The card number never reaches you or Ophelia.

| Provider | What the venue does with the card | Order of steps |
| - | - | - |
| OpenTable | Holds the table and charges the card only under its no-show policy. | Card approval first, then the venue's SMS code when the venue asks for one. |
| Resy | Saves the card on file to hold the table and charges nothing. | SMS code first, then card approval. |

A slot that needs no card confirms without pausing for payment. Every slot Ophelia returns says in `terms.card_required` whether it needs one.

## What you need

1. Production client credentials for your company, exchanged for an access token ([Create an access token](https://docs.agentcard.com/api-reference/access-tokens/create.md)). Agentcard refuses an API key here, and sandbox cards cannot pay a live venue.
2. A user connected to your company with a card in the Vault ([Adding a card](https://docs.agentcard.com/vault/adding-a-card.md), [Check for stored cards](https://docs.agentcard.com/vault/checking-for-stored-cards.md)).
3. An Ophelia v1 key, live or test, from the [Ophelia dashboard](https://dashboardopheliaos.com).
4. A way to reach the diner within minutes, for the approval link and for the venue's SMS code.

Every booking is a real reservation, on test keys too. Cancel the ones you make while testing.

## Create the booking

Send `"payment_collection": "agentcard_external"` and no card fields. The billing fields in `metadata` are what the venue's processor checks against the card, so send the user's real postal code and country.

```bash theme={null}
curl -X POST "https://api.opheliaos.com/v1/bookings" \
  -H "Authorization: Bearer $OPHELIA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "vertical": "dining",
    "venue_id": "ven_aabc6799",
    "availability_id": "avail_45fbe9c68dbca831",
    "datetime": "2026-10-24T21:30:00-07:00",
    "party_size": 2,
    "customer": {
      "name": "Maria Garcia",
      "email": "maria.garcia@gmail.com",
      "phone_number": "+1XXXXXXXXXX"
    },
    "payment_collection": "agentcard_external",
    "metadata": { "billing_postal_code": "19713", "billing_country": "US" }
  }'
```

Ophelia answers with the booking. Read `status` every few seconds with `GET /v1/bookings/{id}`. Within about a minute an OpenTable booking reads `requires_action` with `next_action.type` set to `payment_authorization`:

```json theme={null}
{
  "id": "bkg_2o_OxbzbzcNtHQxQR-f-MQ",
  "object": "booking",
  "status": "requires_action",
  "provider": "opentable",
  "next_action": {
    "type": "payment_authorization",
    "expires_at": "2026-10-22T19:09:17Z",
    "agentcard_request": {
      "merchant": "Gary Danko",
      "checkout_origin": "https://www.opentable.com",
      "psp": "spreedly",
      "mode": "token",
      "request": {
        "url": "https://core.spreedly.com/v1/payment_methods/restricted.json?from=iframe&v=1.191",
        "method": "POST",
        "headers": { "content-type": "application/json", "spreedly-environment-key": "..." },
        "body": "..."
      }
    }
  }
}
```

`agentcard_request` is the body of [Create a checkout authorization](https://docs.agentcard.com/api-reference/vault/authorizations-create.md) without the `user`. The `request` inside it is the venue's own card request with a placeholder card in the body; the user's device swaps the real card in. `expires_at` is Ophelia's deadline, 15 minutes from the pause.

Branch on `next_action.type` every time you read the booking. A Resy booking asks for the venue's SMS code first: `next_action.type` reads `otp`, and you post the code the diner received as `{"otp_code": "123456"}` to `/continue`. Ophelia's guide covers that step.

## Create the checkout authorization

Copy `agentcard_request` unchanged, add `user`, and post it with your access token.

```bash theme={null}
curl -X POST https://api.agentcard.sh/api/v2/checkout/authorizations \
  -H "Authorization: Bearer $ORG_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "user": "usr_df990f5fe85e14dae53abdd2",
    "merchant": "Gary Danko",
    "checkout_origin": "https://www.opentable.com",
    "psp": "spreedly",
    "mode": "token",
    "request": { "url": "https://core.spreedly.com/v1/payment_methods/restricted.json?from=iframe&v=1.191", "method": "POST", "headers": { "content-type": "application/json", "spreedly-environment-key": "..." }, "body": "..." }
  }'
```

```json theme={null}
{
  "id": "cauth_9fda17b693373dd657d33cc9",
  "object": "checkout_authorization",
  "status": "awaiting_approval",
  "execution_mode": "user_approval",
  "merchant": "Gary Danko",
  "psp": "spreedly",
  "mode": "token",
  "amount": null,
  "card": { "id": "vc_0a75b9a1e79c306934b910a7", "brand": "mastercard", "last4": "6305" },
  "interval": 2,
  "expires_at": "2026-10-22T19:09:29Z",
  "approvalUrl": "https://app.agentcard.sh/a/cauth_9fda17b693373dd657d33cc9.Y3PU..."
}
```

A hold carries no amount, so `amount` is null and the approval screen shows the venue's name without a price. Tell the user what they approve: the venue keeps their card on file and charges it only under its no-show policy. Ophelia returns that policy in the slot's `terms`, with the fee and the cancellation cutoff.

## Send the user the approval link

Send `approvalUrl` to the user wherever you already talk to them: a chat thread, an iMessage, an email, your app ([Choose a platform](https://docs.agentcard.com/vault/platforms/overview.md)). The user opens the link, sees `Gary Danko`, and confirms with Face ID, Touch ID, fingerprint, or their master password. Their device sends the real card to the venue's processor, and Agentcard stores the processor's answer on the authorization.

## Hand the answer back to Ophelia

Read the authorization every `interval` seconds until `status` leaves `awaiting_approval`.

```bash theme={null}
curl https://api.agentcard.sh/api/v2/checkout/authorizations/cauth_9fda17b693373dd657d33cc9 \
  -H "Authorization: Bearer $ORG_TOKEN"
```

On `approved`, the authorization carries `response`: the processor's answer, with the card already turned into a token.

```json theme={null}
{
  "id": "cauth_9fda17b693373dd657d33cc9",
  "status": "approved",
  "replay_attempted": true,
  "response": {
    "status": 201,
    "headers": { "content-type": "application/json" },
    "body": "{\"transaction\":{\"succeeded\":true,\"transaction_type\":\"AddPaymentMethod\",\"state\":\"succeeded\",\"payment_method\":{\"token\":\"...\",\"card_type\":\"master\",\"last_four_digits\":\"6305\"}}}"
  }
}
```

Post the `response` object to Ophelia as `psp_response`, and nothing else from the authorization.

```bash theme={null}
curl -X POST "https://api.opheliaos.com/v1/bookings/bkg_2o_OxbzbzcNtHQxQR-f-MQ/continue" \
  -H "Authorization: Bearer $OPHELIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "psp_response": {
      "status": 201,
      "headers": { "content-type": "application/json" },
      "body": "{\"transaction\":{...}}"
    }
  }'
```

Ophelia finishes the venue's card step and answers with the booking. On OpenTable the answer took eight seconds in a live run:

```json theme={null}
{
  "id": "bkg_2o_OxbzbzcNtHQxQR-f-MQ",
  "object": "booking",
  "status": "confirmed",
  "provider": "opentable",
  "confirmation": {
    "confirmation_code": "2109824225",
    "message": "Reservation confirmed for 2026-10-24 at 9:30 PM",
    "terms": {
      "card_required": true,
      "card_policy": "hold",
      "cancellation_fee": { "amount_cents": 5000, "currency": "USD", "per": "guest" },
      "cancellation_cutoff_hours": 24
    }
  }
}
```

A `202` means Ophelia is still working: read `GET /v1/bookings/{id}` until the booking reads `confirmed` or `failed`. A `requires_action` means another step; branch on `next_action.type` again. A malformed `psp_response` gets `400` and the booking stays paused, so fix the body and post it again before `expires_at`.

## Abandon the payment

When the user declines, or the authorization reads `declined` or `expired`, tell Ophelia to stop.

```bash theme={null}
curl -X POST "https://api.opheliaos.com/v1/bookings/bkg_2o_OxbzbzcNtHQxQR-f-MQ/continue" \
  -H "Authorization: Bearer $OPHELIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "psp_abort": true, "decline_code": "user_declined" }'
```

The booking fails with `error_code` set to `payment_declined`, and the venue holds nothing.

Stop at Ophelia's deadline, not Agentcard's. Both windows last 15 minutes, but Agentcard's starts when you create the authorization, after Ophelia's pause, so it outlives Ophelia's. Leave 30 seconds for your own `/continue` call. When Ophelia's `expires_at` passes, cancel the authorization so the user cannot approve a payment that can no longer complete ([Cancel a checkout authorization](https://docs.agentcard.com/api-reference/vault/authorizations-cancel.md)), and read what the cancel returns before you do anything else.

* `200` with `cancelled: true`: the user's approval link stops working and no card was sent. Start a new booking.
* `409` with `outcome_unknown`: the user's device has already started sending the card, so the attempt is still running. Read the authorization every `interval` seconds until it leaves `awaiting_approval`. When it reads `approved`, the card reached the venue's processor, so check with the venue before you book again.

A `psp_response` that arrives after `expires_at` gets `400`, and the booking fails with `payment_outcome_unknown`. The card can still have reached the venue, so check with the venue before you book again.

## When the booking fails

A failed booking reads `status: "failed"` with an `error_code` and an `error_message`. A `400` from `/continue` carries only an `error` message, so read the booking to learn which case happened.

| `error_code` | What happened | What to do |
| - | - | - |
| `payment_declined` | You sent `psp_abort`. | Start a new booking if the user still wants the table. |
| `payment_approval_expired` | Ophelia got no answer before `expires_at`. | Start a new booking. If the user had approved, check with the venue first. |
| `payment_outcome_unknown` | Ophelia cannot tell whether the card step finished, usually because the answer came late. | The card can have reached the venue. Check with the venue before you book again. |
| `payment_replay_failed` | Ophelia could not apply the processor's answer to the venue's checkout. | The processor can hold the card. Check with the venue before you book again. |
| `card_declined` | The venue's processor declined the user's card. | Tell the user, and start a new booking with another card. |
| `payment_setup_failed` | Ophelia could not prepare the card step for this venue. | Offer another venue or time. Contact Ophelia if it repeats. |

Two refusals come at create, before a booking exists. `409 vault_unavailable` means the venue cannot be paid through Agentcard, so offer another venue or time. `503 agentcard_disabled` means Agentcard payments are off for your Ophelia account, so contact Ophelia.

On the Agentcard side, an authorization that reads `declined` or `expired` sent no card. Abandon the booking with `psp_abort` as shown above.

## Know what Agentcard read back

The venue's request stores the card for later and charges nothing at approval. The authorization's `settlement` therefore reads `unknown` with reason `no_processor_reference` and `final: true`: Agentcard holds no reference at the processor to read back, and the booking's `confirmation_code` is the proof that the hold is in place. The [`checkout_authorization.approved`](https://docs.agentcard.com/webhooks/checkout-authorizations/checkout_authorization-approved) event fires when the user approves, so you can wait on it instead of reading the authorization every few seconds. The event does not carry `response`, so read the authorization once when it arrives and post its `response` to Ophelia as `psp_response`. A later cancellation of the booking leaves the authorization as it is; nothing remains to cancel once the user has approved.

## Test it

Ophelia has no sandbox for card holds, and Agentcard's sandbox cards cannot pay a live venue. Test with production credentials, a real card in the Vault, and a slot a few days out at a venue whose availability reads `card_required: true`. Cancel the booking with `POST /v1/bookings/{id}/cancel` as soon as it confirms. OpenTable cancels at the venue. A confirmed Resy booking stays confirmed, so cancel it in the diner's Resy account.

Ophelia's own guide, [AgentCard payments](https://www.opheliaos.com/docs/payments/agentcard), covers the booking side in full: webhooks, timing, and every error code.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.