402 Payment Required response. Instead of API keys or subscription plans, each call costs a small USDC amount, paid on Stellar. Nebula’s x402_fetch tool handles the entire payment cycle autonomously — your agent calls a URL, Nebula detects any payment requirement, signs and submits the USDC payment, and retries the request with proof of payment attached. No human approval needed between steps.
How x402 works
When your agent callsx402_fetch, Nebula follows this sequence:
Receive payment terms
If the server requires payment, it responds with
HTTP 402 and a machine-readable payload describing the required amount, asset (USDC), and payment address.Sign and submit the payment
Nebula checks your configured spending limit, then signs and broadcasts a USDC payment on Stellar. This step is subject to your
MAX_PER_CALL cap — if the payment amount exceeds the cap, the tool returns an error instead of paying.Retry with payment proof
Nebula retries the original request with a signed payment header attached, proving the payment was made.
Making an x402 payment
Tell your agent to callx402_fetch with the target URL:
url parameter and handles everything else automatically.
x402_fetch always uses GET. If the API you are calling requires a different method, check the API’s documentation — some x402-gated APIs provide separate endpoints for paid data retrieval.Spending limits
Everyx402_fetch payment is checked against your spending caps before the payment is signed:
MAX_PER_CALL— the maximum USDC your agent can spend in a single call. Set this to at least the highest payment amount you expect to encounter.MAX_PER_DAY— the rolling 24-hour cap across all agent payments. x402 payments count toward this total alongside transfers and MPP session budgets.
POLICY_CONTRACT_ID), those limits take precedence over the env var values. See the On-Chain Policy guide for details.
Prerequisites
x402_fetch pays APIs using USDC on Stellar. Before your first payment you need:
- A USDC trustline on your wallet — your Stellar account must opt in to hold USDC before it can receive or spend it.
- A funded USDC balance — the payment amount is deducted from your wallet’s USDC balance at the time of the call.
- Enough XLM for fees — Stellar transactions require a small XLM fee (a fraction of a cent). Your wallet always needs a small XLM reserve.
Setup checklist
Fund your XLM balance
On testnet, ask your agent to request testnet tokens:Nebula returns a Friendbot link that credits your wallet with test XLM. On mainnet, fund your wallet through an exchange or a Stellar-compatible wallet app.
Add a USDC trustline and get test USDC
Go to the Circle testnet faucet and request test USDC for your wallet’s public address. The faucet also establishes the trustline automatically.To find your public address:
Set MAX_PER_CALL high enough
Open your MCP config and set Give yourself a comfortable margin — you can always lower the cap later. Restart Claude after changing the config.
MAX_PER_CALL to a value that covers the maximum payment you expect to make in one call. For example, if you expect APIs to charge up to 0.10 USDC per request, set:Checking your spending history
After making x402 payments, you can review cumulative spend against your daily cap:MPP Sessions
For high-frequency micropayments, open an MPP channel instead of paying per-request with x402.
On-Chain Policy
Enforce spending caps with a Soroban contract rather than environment variables.