Skip to content

Docs

Give your agent a wallet

With a wallet of its own, your AI agent can pay for each price computation as it goes. It needs no account, no API key and no sign-up.

1. What the wallet does

Your agent pays for each compute call in USDC on Base, using x402, an open way to pay for a web request inside the request itself. One call costs 0.01 USDC. There is no account to open and no monthly bill.

The payment is settled only after the price has been computed. If the call fails before settlement, the payment is never settled and nothing is charged. The one case to watch is an answer of payment_settlement_unknown: settlement was attempted and the payment may have gone through, so follow the steps for it under Stay safe below.

Network
Base (eip155:8453)
Price per call
0.01 USDC
Paid to (Last Price wallet)
0x30F4f41158dBd194B51820E5633fCBa8eBD86ea4
The wallet your agent's payment lands in. Only pay this address.

2. Create a wallet for the agent

  • Make a new wallet just for the agent. Never give it your main wallet.
  • Keep only a small balance in it: enough for the calls you expect, not your savings.
  • Keep its private key in the agent's secret store, the same place you keep its other credentials. Never put the key in code, in a prompt, or in a file the agent can share.

Any wallet that can sign for an Ethereum style address works. A hosted agent wallet, where a provider holds the key and signs for the agent (for example a Coinbase CDP server wallet), works, and so does a plain EVM private key the agent holds itself.

3. Fund it with USDC on Base

Send USDC to the agent's address on the Base network. USDC on Ethereum mainnet or any other network will not work, even though it has the same name. The USDC this deployment accepts is the contract 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913.

The wallet does not need ETH for gas. The agent only signs a transfer authorization for the exact price, and the payment facilitator submits it on chain.

4. Let the agent pay

Every paid call is the same request sent twice:

  1. The agent sends the compute request with no key. The answer is 402 Payment Required, with the payment requirements: network, asset, amount and where to pay.
  2. The agent signs a payment for exactly that amount with its wallet.
  3. It sends the same request again with the signed payment, base64 encoded, in the X-PAYMENT header (x402 version 1) or the PAYMENT-SIGNATURE header (version 2).
  4. The price comes back with the settlement in the X-PAYMENT-RESPONSE header (or PAYMENT-RESPONSE in version 2), including the transaction.

To see the requirements for yourself, send the request with no payment:

curl -i -X POST https://api.last-price.ai/api/compute/price \
  -H 'content-type: application/json' \
  -d '{"context":{"product_type":"saas","current_price":49,"currency":"USD"}}'

An x402 client library does all four steps for the agent. In TypeScript, with the open source x402 packages:

// npm install @x402/fetch @x402/evm viem
import { wrapFetchWithPaymentFromConfig, decodePaymentResponseHeader } from "@x402/fetch"
import { ExactEvmScheme } from "@x402/evm"
import { privateKeyToAccount } from "viem/accounts"

// Read the key from the agent's secret store. Never put it in code or a prompt.
const account = privateKeyToAccount(process.env.AGENT_WALLET_KEY as `0x${string}`)

const fetchWithPayment = wrapFetchWithPaymentFromConfig(fetch, {
  schemes: [{ network: "eip155:8453", client: new ExactEvmScheme(account) }],
})

const res = await fetchWithPayment("https://api.last-price.ai/api/compute/price", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({"context":{"product_type":"saas","current_price":49,"currency":"USD"}}),
})
const result = await res.json()

const settlement = res.headers.get("PAYMENT-RESPONSE")
if (settlement) console.log("paid in", decodePaymentResponseHeader(settlement).transaction)

Each payment buys one call and cannot be used again. Paid calls run with the built-in and publicly listed pricing functions.

5. Spend less per call

Paying per call is the simplest way in. If your agent makes many calls and has a Last Price API key, these cost less. Nothing is ever charged automatically: each is one payment the agent signs.

Prepaid balance

With an API key that can compute, the agent sends POST /api/billing/topup with the amount, at least 10 USDC, and pays it once with x402. Calls then draw 0.008333 USDC each from the balance instead of 0.01 USDC. Larger top-ups earn a bonus: 10% from 100 USDC, 20% from 500 USDC.

A self-registered agent draws on the balance once its daily limit and any day pass are used up. Any other workspace draws on it only while balance billing is turned on.

Day pass

An agent that registered itself (the Agent Starter plan) can send POST /api/agents/allowance with its key and one payment of 2.5 USDC for 500 extra compute calls over 24 hours, used once its daily limit is reached. Unused pass calls end when you claim the workspace.

6. Stay safe

  • Cap the wallet. The balance is the most the agent can ever spend. Top it up in small amounts rather than leaving a large sum in it.
  • Check what it signs.Have the agent pay only when the amount and the address it is asked to pay match the price and the "Paid to" address on this page.
  • payment_settlement_unknown: the payment may have gone through. The agent must not sign a new payment for that call or send the same one again. Email support@last-price.ai with the payment_id from the answer and we will confirm what happened.
  • payment_settlement_failed: nothing was charged. If the answer says retryable: true (for example, the wallet was short of funds), top it up and send the same payment again, up to 3 settlement attempts in all. If it says retryable: false, that payment will not be accepted again: fix the cause, such as an empty wallet, and sign a new one.
  • Any other 503 with retryable: true, such as a facilitator that could not be reached, charged nothing. Send the same request again after the seconds in its Retry-After header.
  • topup_not_recorded: the top-up payment went through but the credit was not written yet. Do not pay again: it is credited automatically within about ten minutes. If it is not, email support@last-price.ai with the payment_id.

For help, email support@last-price.ai.