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

# Pay an endpoint from the managed wallet

> Use agentX402Pay to pay a Laso route or any external x402 endpoint from the managed wallet, and agentWalletTransfer to move USDC out.

`agentX402Pay` settles an x402 payment from the managed wallet and returns the endpoint's own response. It works in two modes: `route` for Laso's endpoints, `url` for anyone else's.

Set up the wallet first in the [overview](/guides/managed-agent-wallet).

## Pay a Laso route

```bash theme={null}
curl https://laso.finance/agentX402Pay \
  -H "Authorization: Bearer $LASO_ID_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"data":{"userId":"usr_...","route":"get-card","params":{"amount":5}}}'
```

Valid `route` values: `get-card`, `order-gift-card`, `order-intl-card`, `get-push-to-card`, `send-payment`. Free endpoints are not routes; call those directly with your Bearer token.

## Pay an external x402 endpoint

```bash theme={null}
curl https://laso.finance/agentX402Pay \
  -H "Authorization: Bearer $LASO_ID_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"data":{"userId":"usr_...","url":"https://api.example.com/v1/paid-endpoint","note":"Market data for the portfolio summary you asked for"}}'
```

Include a `note` in `url` mode: one sentence on why you are paying and who it is for. It is shown next to the charge in the owner's activity feed. Notes over 300 characters are truncated. `note` is refused with `route`, since Laso purchases are already labeled.

<Tip>
  Pin the price, asset, network, and receiver on every external payment. See
  [Guardrails](/guides/managed-wallet-guardrails).
</Tip>

## Request options

Both modes accept:

| Field    | Effect                                                      |
| -------- | ----------------------------------------------------------- |
| `params` | Added to the query string                                   |
| `method` | Defaults to `GET`; set `POST` for services expecting a body |
| `body`   | JSON body, used with `method: "POST"`                       |

## Read the response

The endpoint's response comes back wrapped:

```json theme={null}
{ "result": { "status": 200, "body": { ... }, "txHash": "..." } }
```

`txHash` is the Solana signature of the payment that settled, the same field name `agentWalletTransfer` returns. It is present whenever a payment settled and absent when nothing was paid.

<Note>
  **Confirm a payment with `txHash`, not with a balance read.** The wallet
  balance that `getAgentWallet` reports is updated by a chain webhook and can
  trail a settled payment by up to a minute. An unchanged balance right after a
  200 does not mean the payment failed.
</Note>

<Warning>
  **Check the inner `status`, not the HTTP code.** The callable returns HTTP 200
  whenever the call completed, including when the endpoint refused. Treat any
  inner `status` outside 200–299 as a failure.
</Warning>

On a non-2xx, `result.error` is one sentence naming the host, status, and reason, normalized from whatever field the service used.

Before signing anything, `agentX402Pay` compares the wallet's on-chain USDC balance to the price in the 402 challenge. An underfunded payment comes back as an inner 402 whose body is the standard x402 settlement-failure shape with `errorReason: "insufficient_funds"`, and nothing is signed:

```json theme={null}
{
  "result": {
    "status": 402,
    "body": {
      "success": false,
      "errorReason": "insufficient_funds",
      "errorMessage": "This payment costs 500.000000 USDC but wallet 9sZ… holds 9.860000 USDC.",
      "payer": "9sZ…",
      "network": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
      "x_laso_guidance": "…what to do next…"
    },
    "error": "laso.finance returned HTTP 402: insufficient_funds. This payment costs 500.000000 USDC but wallet 9sZ… holds 9.860000 USDC. Nothing was charged."
  }
}
```

Branch on `body.errorReason`. `settlement_failed` is reserved for a payment that was signed but could not settle on-chain for another reason.

An inner 402 almost always means the wallet could not cover the total. Laso fees are charged **on top of** the amount you request, so a wallet holding exactly \$2,000 cannot send a \$2,000 bank payment (it costs \$2,005.00). Nothing is charged for a failed payment, so retrying with a smaller amount is safe.

## Move funds out

`agentWalletTransfer` sends USDC from the managed wallet to any Solana address.

```bash theme={null}
curl https://laso.finance/agentWalletTransfer \
  -H "Authorization: Bearer $LASO_ID_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"data":{"userId":"usr_...","destinationAddress":"SOLANA_ADDRESS","amount":"5"}}'
```

Returns `{ "result": { "transferId": "...", "txHash": "...", "destinationAddress": "..." } }`.

## Next steps

<CardGroup cols={2}>
  <Card title="Guardrails" icon="shield-check" href="/guides/managed-wallet-guardrails">
    Refuse any external challenge that does not match what you agreed to pay.
  </Card>

  <Card title="Making a purchase" icon="credit-card" href="/guides/making-a-purchase">
    The two-step card flow you reach through `agentX402Pay`.
  </Card>
</CardGroup>
