Agent Developer Guide

Build autonomous AI agents that discover, purchase, and consume services on the402 platform.

Overview

the402 is an open marketplace where AI agents discover and purchase services using USDC micropayments via the x402 protocol. As an agent developer, you can:

  • Browse a catalog of data APIs, automated tools, and human-delivered services
  • Pay per-request with USDC on Base L2 — no accounts, no API keys needed for purchases
  • Purchase fixed-price services instantly, or open conversational threads for variable-priced services
  • Track async jobs through their full lifecycle
  • Verify delivery and trigger escrow release
  • Subscribe to recurring service plans for automatic access to bundled services
  • Purchase and download digital products (templates, datasets, plugins)

Want guided help? Paste this prompt into Claude and it will walk you through building your agent step by step.

Quickstart

Get your agent calling paid APIs in under 5 minutes. Copy, paste, run.

Option A: Node.js with x402 (full crypto-native flow)

// npm install x402 @coinbase/cdp-sdk
import { createPaymentHeader } from "x402/client";
import { CdpClient } from "@coinbase/cdp-sdk";

const cdp = new CdpClient();
const account = await cdp.evm.createAccount();
console.log("Fund this address with USDC on Base:", account.address);

// the402Fetch — handles x402 payment automatically
async function the402Fetch(url, account, options = {}) {
  const res = await fetch(url, options);
  if (res.status !== 402) return res;
  const { x402Version, accepts } = await res.json();
  const payment = await createPaymentHeader(account, x402Version || 1, accepts[0]);
  return fetch(url, { ...options, headers: { ...options.headers, "X-PAYMENT": payment } });
}

// After funding, discover and purchase services:
const catalog = await fetch("https://api.the402.ai/v1/services/catalog?q=ssl+check");
const { services } = await catalog.json();

const resp = await the402Fetch(
  `https://api.the402.ai/v1/services/${services[0].id}/purchase`,
  account,
  { method: "POST", body: JSON.stringify({ site_url: "https://example.com" }) }
);
console.log(await resp.json());
// { job_id: "job_abc123", status: "created" }

Option B: Any language with pre-funded balance (no crypto dependencies)

If you've already registered and deposited USDC, you can call paid endpoints from any language with just an HTTP header — no x402 SDK needed.

# Works from any language — just add the X-BALANCE-AUTH header
curl -X POST "https://api.the402.ai/v1/services/svc_xxx/purchase" \
  -H "X-BALANCE-AUTH: sk_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{"site_url": "https://example.com"}'
# Python example
import requests

resp = requests.post(
  "https://api.the402.ai/v1/services/svc_xxx/purchase",
  headers={"X-BALANCE-AUTH": "sk_your_api_key_here"},
  json={"site_url": "https://example.com"}
)
print(resp.json())

Which option? Use Option A if your agent is in JavaScript/TypeScript and you want the full x402 flow. Use Option B from any language once you've registered and deposited a balance — it's just an HTTP header, no crypto libraries required. Or use Option C (MCP Server) for zero-code access from Claude Desktop, Cursor, or Windsurf.

Option C: MCP Server (zero code)

The fastest way to start — no code, no wallet, no SDK. Add one JSON config to Claude Desktop, Cursor, or Windsurf and get all 30 the402 tools natively in your AI assistant.

Browse-only (no API key)

Search the catalog and discover services immediately:

// Claude Desktop: ~/Library/Application Support/Claude/claude_desktop_config.json
// Cursor: ~/.cursor/mcp.json
{
  "mcpServers": {
    "the402": {
      "command": "npx",
      "args": ["-y", "@the402/mcp-server"]
    }
  }
}

Full access (with API key)

Add your API key to unlock purchasing, threads, balance, referrals, and more. Purchases deduct from your pre-funded balance — no wallet signing needed.

{
  "mcpServers": {
    "the402": {
      "command": "npx",
      "args": ["-y", "@the402/mcp-server"],
      "env": {
        "THE402_API_KEY": "sk_your_api_key_here"
      }
    }
  }
}

What you can do

  • Search & discover — browse the full service catalog, get service details, check platform info
  • Purchase services — buy fixed-price services and digital products from your balance
  • Negotiate via threads — open inquiries, send messages, accept proposals, verify delivery
  • Subscribe to plans — list plans, subscribe, manage subscriptions
  • Track finances — check balance, view transaction history
  • Earn referrals — get your referral code, track earnings, withdraw

Get an API key: Register via x402 (POST /v1/register, $0.01) or sign up at the402.ai/dashboard. Then deposit USDC to your balance for MCP purchases. View on npm

Connect Your Agent

Give your agent this one URL and it can discover every service on the platform:

Service Catalog https://api.the402.ai/v1/services/catalog
Machine Discovery https://api.the402.ai/.well-known/the402.json

That endpoint is free, no auth required, and returns every available service with pricing, input schemas, and purchase endpoints. Your agent fetches it, picks a service, and pays via x402. Three steps:

// 1. Discover services (free)
const { services } = await (await fetch("https://api.the402.ai/v1/services/catalog")).json();

// 2. Pick a service and purchase it (the402Fetch handles payment)
const resp = await the402Fetch(
  `https://api.the402.ai/v1/services/${service.id}/purchase`,
  account,
  { method: "POST", body: JSON.stringify(brief) }
);

// 3. Done. No registration, no API keys.

No setup required for purchases. Your agent just needs a wallet with USDC on Base. Payment IS authentication — the x402 protocol handles everything.

What Requires Registration?

Registration ($0.01 one-time fee) unlocks additional platform features. Here's what you can do with and without it:

Feature No Registration Registered ($0.01)
Browse service catalogYes (free)Yes (free)
Purchase servicesYes (x402)Yes (x402 or balance)
Check job/thread statusYes ($0.001 x402)Yes (free with API key)
Thread conversations & messagingYes ($0.001 x402)Yes (free with API key)
Pre-funded balance (zero-latency)--Yes
Subscribe to service plans--Yes
Download digital products--Yes
Reputation score--Yes

Setup & Wallet

Your agent needs a wallet with USDC on Base to make purchases. The x402 SDK handles the payment flow automatically.

1. Install dependencies

npm install x402 @coinbase/cdp-sdk

2. Create an account

Use CDP (Coinbase Developer Platform) to create a managed account, or bring your own. The account needs USDC on Base.

// Using CDP SDK for a managed account
import { CdpClient } from "@coinbase/cdp-sdk";

const cdp = new CdpClient();
const account = await cdp.evm.createAccount();

// Fund with USDC on Base
console.log(`Account: ${account.address}`);
// Reuse later: cdp.evm.getAccount({ address });

3. Register on the platform (optional)

Registration is not required for core workflows. Payment IS authentication — your wallet proves your identity on every request, and the platform auto-creates a participant record on your first x402 payment. Explicit registration is only needed if you want an API key for pre-funded balances (zero-latency purchases) or free resource polling. The endpoint is idempotent — calling it again for an existing wallet returns your existing credentials (200) instead of an error.

const resp = await the402Fetch(
  "https://api.the402.ai/v1/register",
  account,
  {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      name: "My Agent",
      type: "agent",
      description: "Autonomous WordPress maintenance agent",
    })
  }
);
const { api_key } = await resp.json();
// Save api_key for authenticated operations

Testing & Sandbox

Test your integration without spending real money using Base Sepolia testnet.

1. Get testnet USDC

Visit faucet.circle.com to get free testnet USDC on Base Sepolia.

2. Run the API locally

# Clone and run the API on testnet
git clone https://github.com/the402/the402-api
cd the402-api
npm install

# Set testnet config in .dev.vars
# NETWORK=base-sepolia
# PAY_TO=0xYourTestWallet

npx wrangler dev --port 8787

3. Point your agent at localhost

// Use localhost instead of api.the402.ai
const catalog = await fetch("http://localhost:8787/v1/services/catalog?q=ssl+check");
const { services } = await catalog.json();

const resp = await the402Fetch(
  `http://localhost:8787/v1/services/${services[0].id}/purchase`,
  account,
  { method: "POST", body: JSON.stringify({ site_url: "https://example.com" }) }
);

Testnet facilitator: When running on base-sepolia, the API uses the public x402 testnet facilitator at https://x402.org/facilitator automatically. No CDP keys needed for testnet.

Discovering Services

There are three ways to discover services, depending on your agent's entry point.

Option 1: Bazaar entry point ($0.001)

If your agent arrives via Bazaar or wants a single-call bootstrap, use POST /v1/discover. It returns the full service catalog plus a getting-started guide with platform context — everything an agent needs in one response.

const resp = await the402Fetch(
  "https://api.the402.ai/v1/discover",
  account,
  { method: "POST" }
);
const { services, guide } = await resp.json();

Option 2: Machine-readable manifest (free)

Fetch GET /.well-known/the402.json for a structured discovery manifest with API base URL, available endpoints, and catalog link. Useful for agent frameworks that look for well-known files.

Option 3: Service catalog (free)

Browse the service catalog directly. The catalog is free — no payment required.

// Browse all services
const resp = await fetch("https://api.the402.ai/v1/services/catalog");
const { services } = await resp.json();

// Filter by category
const wpServices = await fetch(
  "https://api.the402.ai/v1/services/catalog?category=wordpress"
);

// Filter by service tier
const dataApis = await fetch(
  "https://api.the402.ai/v1/services/catalog?service_type=data_api"
);
const humanSvcs = await fetch(
  "https://api.the402.ai/v1/services/catalog?service_type=human_service"
);

// Search by keyword (full-text search with relevance ranking)
const seoServices = await fetch(
  "https://api.the402.ai/v1/services/catalog?q=seo"
);

// Combine search + filters + pagination
const wpAudits = await fetch(
  "https://api.the402.ai/v1/services/catalog?q=audit&category=wordpress&limit=10"
);

// Each service includes:
// - id, name, description
// - price (fixed or min/max range)
// - service_type: "data_api", "automated_service", or "human_service"
// - pricing_model: "fixed" or "quote_required"
// - fulfillment_type: "instant", "automated", or "human"
// - endpoint: the URL to purchase or request a quote

Pricing models: Services with pricing_model: "fixed" can be purchased directly. Services with pricing_model: "quote_required" need you to request a quote first — the provider reviews your brief and responds with a price.

Catalog filters: ?q= (full-text search across name, description, category, tags), ?category=, ?service_type= (data_api, automated_service, human_service), ?max_price=, ?provider=. Pagination: ?limit= (max 100), ?offset=. Results include total count for paging.

API Key Rotation

If your API key is compromised or you want to rotate it, use POST /v1/participants/rotate-key ($0.001 via x402). The x402 wallet signature proves ownership — only the wallet that registered can rotate its key. Your old key is invalidated immediately.

const resp = await the402Fetch(
  "https://api.the402.ai/v1/participants/rotate-key",
  account,
  { method: "POST" }
);
const { api_key } = await resp.json();
// New API key — old one is now invalid

Pre-Funded Balance

For high-frequency agents, skip per-request x402 signing by pre-funding a USDC balance. Deposit once via x402, then use the X-BALANCE-AUTH header for zero-latency requests.

1. Deposit USDC

const depositResp = await the402Fetch(
  "https://api.the402.ai/v1/balance/deposit?amount=10.00",
  account,
  { method: "POST" }
);
// $10.00 deposited via x402 — credited to your balance

2. Use balance for requests

// Include X-BALANCE-AUTH instead of letting x402 handle payment
const resp = await fetch("https://api.the402.ai/v1/services/svc_xxx/purchase", {
  method: "POST",
  headers: { "X-BALANCE-AUTH": apiKey, "Content-Type": "application/json" },
  body: JSON.stringify({ site_url: "https://example.com" })
});
// Cost deducted from balance — no on-chain transaction

3. Check your balance

const balance = await fetch("https://api.the402.ai/v1/balance", {
  headers: { "X-API-Key": apiKey }
});
// { balance_usd: 9.999, total_deposited_usd: 10, total_spent_usd: 0.001 }

Fallback: If your balance is insufficient for a request, it automatically falls through to standard x402 payment. You can mix both methods freely.

Human services require x402: Services with service_type: "human_service" must be purchased via x402 — pre-funded balance payments return 400. This ensures USDC is pre-sent to the escrow contract by the facilitator before the job is dispatched.

Service Threads (Recommended)

The primary way to interact with services. Open a thread, negotiate with the provider, accept their price, and track delivery — all in one conversation.

// 1. Open a thread about a service ($0.001)
const resp = await the402Fetch(
  `https://api.the402.ai/v1/services/${serviceId}/inquire`,
  account,
  { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ message: "I need..." }) }
);
const { thread_id } = await resp.json();

// 2. Check thread for provider response (x402 or API key)
const thread = await (await the402Fetch(
  `https://api.the402.ai/v1/threads/${thread_id}`,
  account
)).json();

// 3. When status is "quoted", accept and pay
await the402Fetch(
  `https://api.the402.ai/v1/threads/${thread_id}/accept`,
  account, { method: "POST" }
);

// 4. Track delivery, then verify when complete
await the402Fetch(
  `https://api.the402.ai/v1/threads/${thread_id}/verify`,
  account, { method: "POST" }
);

No registration needed: Thread endpoints (GET /v1/threads, GET /v1/threads/:id, POST /v1/threads/:id/messages) accept either an API key or an x402 micropayment ($0.001). Unregistered agents can manage threads using the same wallet that opened the inquiry — no need to call /v1/register first.

Encrypted credentials: You can send encrypted credentials via thread messages (type: 'credential'). These are AES-256-GCM encrypted at rest and automatically deleted after thread completion.

Thread expiry: Threads in 'inquiry' state expire after 7 days. Quoted threads expire after 72 hours. Fixed-price purchases also auto-create a thread for conversation tracking.

Direct Purchase (Fixed-Price)

For fixed-price services, send a POST to the purchase endpoint with your brief. The x402 SDK handles the payment automatically.

// Assumes the402Fetch and account are set up (see Quickstart)

const resp = await the402Fetch(
  "https://api.the402.ai/v1/services/svc_abc123/purchase",
  account,
  {
    method: "POST",
    body: JSON.stringify({
      site_url: "https://example.com",
      issue_description: "Plugin conflict causing white screen",
      severity: "high",
    })
  }
);

const { job_id, status_url } = await resp.json();
// job_id: "job_abc123"
// status_url: "/v1/jobs/job_abc123"

Quote Flow (Legacy)

Legacy: This flow still works but is deprecated. Use Service Threads instead for a better experience with built-in messaging and credential handling.

For services with pricing_model: "quote_required", you request a quote, wait for the provider to respond with pricing, then accept or decline.

1
Request a quote

Send your brief to the quote endpoint. Costs $0.001 to prevent spam.

2
Provider reviews and responds

The provider receives your brief, assesses the work, and responds with a price.

3
Accept or decline

Check the quote status. If the price works, accept and pay. A job is created automatically.

Step 1: Request a quote

const quoteResp = await the402Fetch(
  "https://api.the402.ai/v1/services/svc_xyz/quote",
  account,
  {
    method: "POST",
    body: JSON.stringify({
      site_url: "https://example.com",
      changes: [{
        page_url: "/about",
        description: "Update team bios and add new member",
      }]
    })
  }
);

const { quote_id, check_url } = await quoteResp.json();
// quote_id: "qt_abc123"
// status: "pending" — waiting for provider response

Step 2: Poll for provider response

// Check quote status (free, no payment needed)
const statusResp = await fetch(
  "https://api.the402.ai/v1/quotes/qt_abc123"
);
const quote = await statusResp.json();

// When status is "quoted", the provider has responded:
// {
// status: "quoted",
// quoted_price_usd: 45,
// platform_fee_usd: 2.25,
// agent_total_usd: 47.25,
// provider_notes: "Can complete in 12 hours",
// expires_at: "2025-03-01T..."
// }

Step 3: Accept and pay

const acceptResp = await the402Fetch(
  "https://api.the402.ai/v1/quotes/qt_abc123/accept",
  account,
  { method: "POST" }
);

const { job_id, status_url } = await acceptResp.json();
// Payment of $47.25 is made automatically via x402
// A job is created and dispatched to the provider

Tracking Jobs

After purchasing a service (directly or via quote), you get a job ID. Poll the job status to track progress.

// Free for job owner with X-API-Key
const statusResp = await fetch(
  "https://api.the402.ai/v1/jobs/job_abc123",
  { headers: { "X-API-Key": api_key } }
);
const job = await statusResp.json();
created dispatched in_progress completed verified released

Agents can also dispute jobs from dispatched, in_progress, or completed states.

When a job reaches completed, the provider has finished the work and submitted deliverables. Review the deliverables, then verify to release payment.

If you used Service Threads to purchase, your thread carries the full conversation and status updates. You can track via the thread directly rather than polling the job endpoint separately.

Verifying Delivery

Once a job is completed, verify delivery to release the escrowed funds to the provider.

const verifyResp = await the402Fetch(
  "https://api.the402.ai/v1/jobs/job_abc123/verify",
  account,
  { method: "POST" }
);
// Escrow released to provider
// If you don't verify within 48 hours, auto-verify kicks in

Auto-verify: If you don't verify after completion, the platform auto-verifies and releases payment. Timing varies by service tier: instant and automated services verify immediately, and human services auto-verify after 48 hours. This protects providers from unresponsive agents.

Disputing a Job

If you're unsatisfied with a delivery, you can dispute the job. This pauses escrow release and flags the job for admin review.

const disputeResp = await the402Fetch(
  "https://api.the402.ai/v1/jobs/job_abc123/dispute",
  account,
  {
    method: "POST",
    body: JSON.stringify({
      reason: "Deliverables don't match the brief — pages were not updated"
    })
  }
);
// Costs $0.005 per dispute

You can dispute jobs in the dispatched, in_progress, or completed states. The reason must be 10-2000 characters.

What happens next: The platform admin reviews the dispute and resolves it — either releasing payment to the provider or refunding your escrow. The dispute reason is posted to the job message thread for full transparency.

Subscriptions

Providers create recurring subscription plans that bundle one or more services at a monthly or annual price. When you subscribe, active subscriptions automatically bypass x402 payment for covered services — no per-call payment needed.

Discover Plans

GET /v1/plans free

Browse available subscription plans. Returns plan name, description, interval, bundled service IDs, and pricing.

provider optional — Filter by provider wallet

Subscribe

POST /v1/plans/:planId/subscribe varies

Subscribe and pay the first billing period via x402 or pre-funded balance. Price is the plan amount plus 5% platform fee.

How Access Works

Once subscribed, requests to any service bundled in your plan skip x402 payment entirely. Just include your X-BALANCE-AUTH or X-API-Key header as usual — the platform checks your active subscriptions automatically.

Manage Subscriptions

GET /v1/subscriptions free

List your subscriptions. Requires X-API-Key header.

status optional — Filter: active, paused, cancelled, past_due, expired
POST /v1/subscriptions/:id/cancel free

Cancel subscription. Access continues until the end of the current billing period.

POST /v1/subscriptions/:id/pause free

Pause auto-renewal. Access continues until period end, then expires.

POST /v1/subscriptions/:id/resume free

Resume a paused subscription. Fails if the current period has already expired.

Auto-renewal: Active subscriptions auto-renew via cron every 30 minutes. The system deducts from your pre-funded AgentBalance. If balance is insufficient, the subscription enters past_due with up to 3 retries over a 72-hour grace period before expiring. Keep your balance funded to avoid service interruptions.

Digital Products

Providers sell downloadable files — templates, datasets, plugins, guides — as one-time purchases. Buy via x402 or pre-funded balance and download the file.

Browse Products

GET /v1/products free

Search the product catalog. Supports full-text search via FTS5 with porter stemming.

q optional — Full-text search query
category optional — Filter by category
provider optional — Filter by provider wallet

Purchase & Download

POST /v1/products/:productId/purchase varies

Purchase a product via x402 or pre-funded balance. Returns a purchase record. Prevents duplicate purchases (409 if already owned).

GET /v1/products/:productId/download free

Download a purchased product file. Requires X-API-Key header. Returns 403 if download limit reached.

GET /v1/purchases free

List your product purchases. Requires X-API-Key header.

Pricing: Product prices include a 5% platform fee. Some products may have a download limit per purchase — check the download_limit field in the product details.

Evaluating Providers

Every provider on the402 earns a multi-dimensional reputation score (0–100) based on real job history. Use these scores to choose the best provider for your agent's needs.

Reputation in the Catalog

Each service in the catalog includes provider reputation data:

  • provider_reputation — composite score (0–100)
  • provider_dimensions — breakdown across four dimensions: quality, speed, reliability, communication
  • provider_confidence — confidence level (0.0–1.0), based on job volume
  • provider_is_new — true if the provider has limited history (confidence < 0.33)
  • provider_completed_jobs — total completed jobs
  • provider_completion_rate — percentage of jobs delivered successfully

Filtering & Sorting

Use query parameters on GET /v1/services/catalog to filter by reputation:

  • ?sort=reputation — sort by provider reputation (highest first)
  • ?min_reputation=75 — only providers scoring 75+
  • ?min_confidence=0.5 — only providers with meaningful job history
  • ?include_new=false — exclude new providers with limited track record

Three-Level Reputation

The service detail endpoint (GET /v1/services/:id) returns reputation at three levels, each with dimensions, composite score, confidence, and job counts:

  • Service-level — scores for this specific service only
  • Service-type-level — scores across all services of the same type (data_api, automated_service, or human_service)
  • Provider-level — aggregated across all provider activity

Score tiers: 0–39 poor, 40–59 new, 60–74 fair, 75–89 good, 90–100 excellent. New providers with no history default to 75. Dimension weights vary by service type — data APIs weight speed highest, human services weight quality highest.

Dedicated Reputation Endpoint

GET /v1/reputation/:wallet $0.005

Look up any wallet's full reputation profile including dimensional breakdown, confidence, and per-service-type scores.

Complete Example

Here's a full flow — discover a service, request a quote, accept, track the job, and verify delivery.

import { createPaymentHeader } from "x402/client";
import { CdpClient } from "@coinbase/cdp-sdk";

const cdp = new CdpClient();
const account = await cdp.evm.createAccount();
const BASE = "https://api.the402.ai";

// the402Fetch — handles x402 payment automatically
async function the402Fetch(url, account, options = {}) {
  const res = await fetch(url, options);
  if (res.status !== 402) return res;
  const { x402Version, accepts } = await res.json();
  const payment = await createPaymentHeader(account, x402Version || 1, accepts[0]);
  return fetch(url, { ...options, headers: { ...options.headers, "X-PAYMENT": payment } });
}

// 1. Discover services
const catalog = await fetch(`${BASE}/v1/services/catalog?category=wordpress`);
const { services } = await catalog.json();
const service = services.find(s => s.name === "WordPress Content Change");

// 2. Request a quote
const quoteResp = await the402Fetch(
  `${BASE}/v1/services/${service.id}/quote`,
  account,
  { method: "POST", body: JSON.stringify(brief) }
);
const { quote_id } = await quoteResp.json();

// 3. Poll until quoted
let quote;
do {
  await new Promise(r => setTimeout(r, 60_000));
  quote = await (await fetch(`${BASE}/v1/quotes/${quote_id}`)).json();
} while (quote.status === "pending");

// 4. Accept if within budget
if (quote.status === "quoted" && quote.agent_total_usd <= maxBudget) {
  const acceptResp = await the402Fetch(
    `${BASE}/v1/quotes/${quote_id}/accept`,
    account, { method: "POST" }
  );
  const { job_id } = await acceptResp.json();

  // 5. Track and verify
  let job;
  do {
    await new Promise(r => setTimeout(r, 300_000));
    job = await (await fetch(`${BASE}/v1/jobs/${job_id}`, { headers: { "X-API-Key": api_key } })).json();
  } while (job.status !== "completed");

  await the402Fetch(`${BASE}/v1/jobs/${job_id}/verify`, account, { method: "POST" });
}

Error Handling

Common error scenarios and how to handle them:

400 Quote required

Trying to purchase a quote_required service directly. Use the quote endpoint instead.

402 Payment Required

Normal x402 flow — the SDK handles this automatically. If you see this, your wallet may need more USDC.

404 Quote expired

Quotes expire after 72 hours. Request a new one.