x402 Payment Integration: Autonomous Micropayments for AI Agents

Treza now supports the x402 protocol — AI agents can discover, access, and pay for secure enclave services using instant USDC micropayments on Base. No API keys, no subscriptions, no human in the loop.

Alex Daro
Alex Daro
x402 Payment Integration: Autonomous Micropayments for AI Agents

AI agents are getting more capable by the week. They can write code, browse the web, manage infrastructure, and make decisions. But when it comes to paying for services, most agents still depend on pre-provisioned API keys and human-managed billing accounts.

The x402 protocol, created by Coinbase, changes this. It brings back the HTTP 402 Payment Required status code — the one that's been reserved since 1997 but never had a standard implementation — and gives it a real payment layer built on stablecoins.

We've integrated x402 into the Treza platform. Here's what it means and how it works.

The Problem: Agents Can't Pay for Things

Today, if an AI agent wants to use an API, someone has to:

  1. Create an account on the service
  2. Generate an API key
  3. Enter credit card details
  4. Configure billing limits
  5. Inject the API key into the agent's environment

This process is manual, fragile, and fundamentally incompatible with autonomous agents that spin up, do work, and shut down on their own.

The Solution: Pay-Per-Request with x402

x402 turns API access into a simple economic transaction. When an agent hits a paid endpoint:

  1. The server responds with 402 Payment Required — including the price, accepted currency (USDC), and recipient address
  2. The agent signs a payment authorization
  3. The agent retries the request with a Payment-Signature header
  4. The server verifies the payment via a facilitator, returns the data, and settles the USDC transfer on-chain

No accounts. No API keys. No invoices. The agent pays exactly what the service costs, per request, in real-time.

How Treza Uses x402

We've added x402 payment gating to two of our attestation endpoints:

| Endpoint | Price | What it does | |----------|-------|-------------| | GET /api/enclaves/{id}/attestation | $0.001 | Retrieve the enclave's attestation document with PCR measurements | | POST /api/enclaves/{id}/attestation/verify | $0.01 | Full cryptographic verification with compliance checks |

When an agent calls these endpoints without payment, it receives a 402 response with everything it needs to construct a payment:

{
  "accepts": [{
    "scheme": "exact",
    "price": "0.001",
    "network": "eip155:8453",
    "payTo": "0x..."
  }],
  "description": "Retrieve enclave attestation document"
}

The agent signs a USDC transfer, attaches it to the retry, and gets the data. Settlement happens on Base (Coinbase's L2) — fast and cheap.

Enclaves as Payment Wallets

Here's where it gets interesting. Treza enclaves generate private keys inside the hardware-isolated TEE. Those keys never leave the enclave boundary. We've built an adapter that lets the enclave act as an x402 payment wallet:

import { TrezaClient, createEnclaveFetch } from '@treza/sdk';
 
const treza = new TrezaClient({
  baseUrl: 'https://app.trezalabs.com',
});
 
const paidFetch = await createEnclaveFetch(treza, {
  enclaveId: 'enc_abc123',
  verifyAttestation: true,
});
 
// This automatically pays on 402 — signed inside the enclave
const response = await paidFetch(
  'https://app.trezalabs.com/api/enclaves/enc_abc123/attestation'
);

The agent doesn't need an external wallet. The enclave is the wallet. Fund it with USDC on Base, and it handles payments autonomously with hardware-grade key security.

Before each payment, the SDK can optionally verify the enclave's attestation — cryptographic proof that the code, kernel, and signing certificate haven't been tampered with. If attestation fails, the payment is rejected before any funds move.

The Full Agent Flow

An autonomous agent using Treza with x402 follows this lifecycle:

  1. Discover — Find Treza via the MCP Registry, OpenAPI spec, or x402 Bazaar
  2. Deploy — Spin up an enclave with the SDK or CLI
  3. Verify — Check the enclave's attestation to confirm code integrity
  4. Fund — Send USDC to the enclave's signing address on Base
  5. Use — Call paid APIs with automatic x402 payment handling
  6. Manage — Pause, resume, or terminate based on demand

No human needed after step 4.

Why This Matters

x402 solves three problems at once:

For API providers: Monetize endpoints without building auth systems, billing infrastructure, or rate limiting. Price per request, settle in stablecoins, done.

For AI agents: Access services without pre-provisioned credentials. Discover what's available, check the price, pay, and move on.

For the ecosystem: A standard payment layer means agents can compose services from multiple providers in a single workflow — paying each one exactly what it charges, on-chain, in real-time.

Combined with Treza's TEE infrastructure, this creates a model where agents can operate with both financial autonomy and hardware-grade security. The private keys that sign payments are as protected as the code running in the enclave.

Get Started

The x402 integration is live in @treza/sdk v0.1.1 and the Treza Platform API.

x402 is currently available on Base Sepolia (testnet) and Base mainnet. To enable it on your Treza deployment, set X402_ENABLED=true in your environment.


Treza builds privacy infrastructure for crypto and finance. Deploy workloads in hardware-secured enclaves with cryptographic proof of integrity. Learn more.

Ready to get started?

Get in touch to learn how Treza can help your team build privacy-first applications.