Skip to main content
HomeLanding pagesHow to build a paid AI agent
LANDING PAGE

How to build a paid AI agent

8 min read·Last updated June 2, 2026

Create the agent with client.agents.create so it has a wallet, expose its work behind an HTTP route, and gate that route with createX402Plugin or createX402Middleware from @blockchain0x/x402. An unpaid request gets a 402; a paid one runs and settles in USDC on Base. Confirm earnings with the payment.received webhook. That is a paid agent, built from zero.

What you will build

An AI agent that earns, built from zero. It has its own wallet, it exposes a service over HTTP, and that service is gated so callers pay in USDC on Base before they get a result. By the end you have the whole thing assembled: create the agent, build the work, put a price on it, and confirm the money arrives.

This is the from-scratch build. If you already have an agent and only want to start charging, how-to-monetize-ai-agent skips the setup. The payment API product page is the broader reference.

The shape of a paid agent

Before the steps, the shape, because it is simpler than it sounds. A paid agent is three things stacked: a wallet to receive into, a service that does work, and a paywall in front of that service.

The wallet is the identity and the account; you create it once. The service is whatever your agent does that is worth paying for, an answer, a generation, a lookup, exposed on an HTTP route. The paywall is the x402 server adapter sitting in front of that route, returning a 402 to unpaid callers and verifying payment on the retry. That is the entire architecture. Everything else, the model the agent uses, how it reasons, how it is deployed, is unchanged from a free agent. You are not building a payments system; you are putting one component in front of a route.

Prerequisites

  • A Blockchain0x account.
  • A sk_test_ API key, plus the agent's wallet address (payToAddress) and a paymentRequestId for the priced route once the agent is created.
  • Node 18 or newer. The SDK targets >=18.
BASH
export B0X_API_KEY=sk_test_...
export B0X_PAYTO_ADDRESS=0x...      # the agent's wallet, receives USDC
export B0X_PRICE_REQUEST_ID=pr_...  # payment-request id for the priced route

Create the agent and its wallet

Start by creating the agent, which provisions its wallet.

TYPESCRIPT
import { createClient } from "@blockchain0x/node";

const client = createClient({ apiKey: process.env.B0X_API_KEY! });
const agent = await client.agents.create({ name: "research-agent" });
console.log(agent.id, agent.network); // agt_..., "testnet"

The wallet is bound to this agent; a wallet.deployed webhook fires when it is live. The full wallet walkthrough is in how-to-add-wallet-to-my-agent. Copy the wallet address into B0X_PAYTO_ADDRESS; that is where earnings land.

Build the service it sells

The service is just your agent's work behind an HTTP handler. Keep this part exactly as you would build any agent endpoint.

TYPESCRIPT
async function runResearchAgent(body) {
  // your agent: call the model, use tools, produce the result a caller pays for
  return { answer: await think(body.question) };
}

There is nothing payment-specific here, and that is the point. Build the best version of the work first. The paywall goes in front of it next, without touching it.

Make it worth paying for

The hardest part of a paid agent is not the payment, it is being worth the price. A caller pays once on faith and pays again only if the first result was good, so the quality bar matters more than the rail.

Ask what a caller could not easily get for free. If your agent wraps a free public API with a thin prompt, there is little reason to pay it, and gating it just adds friction. If it produces a researched answer, a generated asset, or an analysis that takes real work to reproduce, that is worth paying for. Aim the paid route at that, and keep anything cheap or commodity free. A useful test before you charge: would you pay your own price for the result the agent returns on a representative input? If the honest answer is no, improve the work before you put a price on it. The payment rail is easy to add later; the reputation you lose shipping a weak paid agent is expensive to win back.

Gate it with x402

Put the server adapter in front of the route. An unpaid request gets a 402; a paid one reaches runResearchAgent.

TYPESCRIPT
import Fastify from "fastify";
import { createX402Plugin } from "@blockchain0x/x402/server/fastify";

const app = Fastify();
await app.register(createX402Plugin, {
  sdk: client,
  defaultNetwork: "testnet",
  pricing: {
    "POST /agent/research": {
      amountUsdc: "0.05",
      payToAddress: process.env.B0X_PAYTO_ADDRESS!,
      paymentRequestId: process.env.B0X_PRICE_REQUEST_ID!,
    },
  },
});

app.post("/agent/research", async (req) => runResearchAgent(req.body)); // runs only once paid
app.get("/agent/capabilities", async () => listCapabilities());        // free: discovery
await app.listen({ port: 8080 });

Express works the same way with createX402Middleware. Pricing is per route, so the paid work is on its own path and discovery stays free on an unpriced one. The adapter verifies the caller's X-Payment header by calling paymentRequests.settle, so only a confirmed payment runs your handler.

Get paid and test end to end

The agent now earns. To act on revenue as it arrives, verify the payment.received webhook:

TYPESCRIPT
import { webhooks } from "@blockchain0x/node";
// inside a raw-body webhook route:
const result = webhooks.verify({ headers: req.headers, rawBody: req.body, secret: process.env.B0X_WEBHOOK_SECRET! });
if (result.ok && result.eventType === "payment.received") recordEarning(JSON.parse(req.body.toString("utf8")));

Test the whole thing on Base Sepolia before going live. Call the priced route with no payment and confirm the 402; pay it from a test wallet (the pay side is createX402Client) and confirm runResearchAgent runs and returns; watch the payment.received event land. When the unpaid and paid paths both behave, swap to a sk_live_ key for Base mainnet and re-check the price and wallet address on the live agent.

Help buyers find it

A paid agent earns nothing if no one can reach it, and most buyers will not be humans browsing, they will be other agents and applications discovering capabilities programmatically. So make the agent discoverable the way they look.

Keep a free capabilities route that lists what the agent does and the shape of its inputs, so a calling agent can inspect it before paying. Give the agent a verified public profile, since a counterparty checks identity before sending money to an unknown address. And describe the paid route clearly: its price, what it returns, and on which network. The easier you make it for a calling agent to understand the offer and trust the payee, the more first calls convert. Distribution for a paid agent is less about marketing copy and more about being legible to machines: a clear free capability surface, a trustworthy identity, and a priced route that quotes itself cleanly in its 402.

Common pitfalls

Three traps when building a paid agent.

Building the paywall before the service. Get the work right first, then gate it. A paywall in front of a service that does not yet deliver value just collects refunds and complaints.

Gating discovery. If callers must pay to learn what the agent does, most never reach the paid route. Keep capabilities and health on free paths.

No spend limit if the agent also buys. A paid agent that buys upstream data is on both sides of the ledger. Set a spend limit on its wallet so its own costs cannot run away while it earns.

What to ship today

Create the agent, build one route that does real work, gate it with the adapter at a starting price, and confirm an unpaid call gets a 402 while a paid one runs and fires payment.received. That is a paid agent end to end. Tune the price on real conversion data, the way how-to-monetize-ai-agent describes. Production pricing for the platform is on the pricing page.

FAQ

Frequently asked questions.

What makes an agent paid versus free?

A paid agent puts a price in front of the work it does. Mechanically, an HTTP route the agent serves is gated by the x402 server adapter, so a caller must settle a USDC payment before the route runs. Nothing about the agent's reasoning changes; you are adding a paywall in front of a route, not rebuilding the agent.

Do callers need an account to pay my agent?

No. With x402 any caller whose runtime speaks the protocol pays per request with no signup and no stored card. Your agent earns from callers it has never onboarded: other agents, applications, or human-backed runtimes. That open, no-account model is the whole reason a paid agent can reach a wide market.

How is this different from monetizing an existing agent?

Same mechanism, different starting point. This guide builds a paid agent from zero, including creating the wallet and the service. If you already have an agent and want to start charging, how-to-monetize-ai-agent covers the decision and the gating without the from-scratch setup.

Which network and token does it settle in?

USDC, 6 decimals, on Base. Use a sk_test_ key for Base Sepolia (eip155:84532) while building, and a sk_live_ key for Base mainnet (eip155:8453) when you ship. The fee on the agent's profile is set by tier. The only scheme is exact-usdc.

Can a paid agent also pay for things?

Yes, with one wallet. An agent that buys upstream data and sells a finished answer both pays and gets paid through the same wallet: the pay side uses createX402Client, the receive side uses the server adapter. Set a spend limit so its own costs stay bounded while it earns.

Create your free agent wallet in 5 minutes.

First payment confirmed in under ten minutes. Free to start.