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

# x402_pay — Pay an x402 Resource at a Known USDC Price

> Pay an x402-gated URL directly with a known USDC amount. Use when your agent has already parsed the 402 challenge and extracted the exact price.

`x402_pay` makes a direct USDC payment to an x402-gated resource when you already know the exact amount required. This is typically used after your agent has already received and parsed an HTTP 402 challenge and has extracted the price and facilitator address from it. Unlike `x402_fetch`, this tool does not issue a preliminary GET request — it goes straight to payment.

## When to use `x402_pay` vs `x402_fetch`

| Scenario                                                            | Recommended tool |
| ------------------------------------------------------------------- | ---------------- |
| You want to fetch a URL and let Nebula handle any 402 automatically | `x402_fetch`     |
| You have already received a 402 response and parsed the exact price | `x402_pay`       |
| You are building a custom payment flow that inspects 402 challenges | `x402_pay`       |

In most cases, `x402_fetch` is simpler. Reach for `x402_pay` only when your agent is explicitly orchestrating a multi-step payment negotiation.

## Parameters

<ParamField path="url" type="string" required>
  The URL of the x402-gated resource you are paying for. This should match the URL from the original 402 challenge.
</ParamField>

<ParamField path="amount_usdc" type="number" required>
  The exact USDC amount to pay, as specified in the 402 challenge. Must be a positive finite number.
</ParamField>

<ParamField path="facilitator" type="string">
  The facilitator address extracted from the 402 challenge header. Facilitators route and attest payments on behalf of the payee. When provided, the Hub includes this address in the payment envelope. When omitted, the Hub uses its default facilitator.
</ParamField>

## Response

### Success

```json title="Success response" theme={null}
{
  "status": "ok",
  "data": {
    "tx_hash": "f71c4a9...b330",
    "amount_paid_usdc": 0.25,
    "payee": "GBKUD4NQFPZ4TPIJCZ5YGZQ5K4XQZBLK7RQFVTX7QWZLOEXAMPLEADDR",
    "facilitator": "GFACILITATOREXAMPLEADDRESSSTELLAR7QWZLOEXAMPLEADDR"
  }
}
```

<ResponseField name="status" type="string">
  Always `"ok"` on success.
</ResponseField>

<ResponseField name="data.tx_hash" type="string">
  The Stellar transaction hash confirming the on-chain payment.
</ResponseField>

<ResponseField name="data.amount_paid_usdc" type="number">
  The USDC amount that was paid.
</ResponseField>

<ResponseField name="data.payee" type="string">
  The Stellar address of the resource owner who received the payment.
</ResponseField>

<ResponseField name="data.facilitator" type="string">
  The facilitator address used for this payment, if applicable.
</ResponseField>

### Error

```json title="Error response" theme={null}
{
  "status": "error",
  "reason": "Insufficient USDC balance: have 0.10, need 0.25"
}
```

## Policy interaction

Like `x402_fetch`, payments submitted via `x402_pay` count toward your per-transaction and daily USDC spend caps. The Hub validates the requested `amount_usdc` against your active policy before broadcasting the transaction.

## Example

```json title="Tool call" theme={null}
{
  "tool": "x402_pay",
  "input": {
    "url": "https://api.example.com/premium-report",
    "amount_usdc": 0.25,
    "facilitator": "GFACILITATOREXAMPLEADDRESSSTELLAR7QWZLOEXAMPLEADDR"
  }
}
```

```json title="Response" theme={null}
{
  "status": "ok",
  "data": {
    "tx_hash": "f71c4a9b2e3d...b330",
    "amount_paid_usdc": 0.25,
    "payee": "GBKUD4NQFPZ4TPIJCZ5YGZQ5K4XQZBLK7RQFVTX7QWZLOEXAMPLEADDR",
    "facilitator": "GFACILITATOREXAMPLEADDRESSSTELLAR7QWZLOEXAMPLEADDR"
  }
}
```
