Set up the x402 seller environment

To integrate x402 endpoints for AI trading signals, you first need to establish a seller environment capable of accepting payments. This process relies on the Coinbase Developer Platform (CDP) to generate the API keys and credentials required for your endpoint to recognize and validate x402-compliant requests.

x402 Endpoints for AI Trading Signals
1
Create a CDP Account

If you don't already have one, sign up for a Coinbase Developer Platform account. This account serves as the central hub for managing your API keys and monitoring transaction activity. The platform provides the necessary infrastructure to interact with the x402 protocol securely.

2
Generate API Credentials

Navigate to the API keys section within your CDP dashboard and generate a new set of credentials. You will need these keys to authenticate your server when it communicates with the x402 payment gateway. Store these keys securely, as they grant access to your seller environment.

x402 Endpoints for AI Trading Signals
3
Configure Your Endpoint

Update your AI trading signal endpoint to include x402 headers in incoming requests. Your server must be configured to parse these headers, verify the associated wallet signature, and confirm that the payment has been settled on the Base network before delivering the signal data.

x402 Endpoints for AI Trading Signals
4
Test the Integration

Use the CDP sandbox or a testnet wallet to send a simulated payment request to your endpoint. Verify that your server correctly rejects requests without valid x402 headers and successfully processes those with settled USDC payments. This step ensures your integration is robust before going live.

Configure the HTTP 402 Response Logic

To integrate x402 endpoints for AI trading signals, your API must first signal that payment is required. When an AI agent or user hits your endpoint without valid credentials or payment, the server returns a 402 Payment Required status code. This isn't just an error; it's a structured invitation to pay.

The response body must include specific metadata that tells the agent exactly how much to pay, in which currency (usually USDC), and where to send it. Once the agent pays, it receives a payment receipt (often a signed transaction hash or token) and retries the request with this proof attached in the Authorization header.

Here is the step-by-step process to implement this logic in your trading signal API.

1
Detect Unauthenticated Requests

Before checking for payment, verify if the request is authenticated. If your trading API requires a token or signature, check for it first. If the request is missing or invalid, proceed to return the 402 response. This ensures you only charge for access, not for basic connectivity checks.

2
Construct the 402 Response Body

The core of x402 is the metadata in the response body. You must return a JSON object containing paymentUri (where to send the payment), amount (the price in USDC or other stablecoin), and currency (the asset type). For example, if your signal costs $0.01, your response body should look like this:

JSON
JSON
{
  "paymentUri": "https://pay.example.com/checkout?amount=0.01&currency=USDC",
  "amount": "0.01",
  "currency": "USDC"
}

This tells the AI agent exactly what to do next.

3
Set the Correct HTTP Headers

Along with the 402 status code, include headers that help the agent parse the payment details. The Content-Type should be application/json. Some implementations also use a custom header like x-payment-required to make debugging easier. Ensure your response is concise; the agent needs to parse this quickly before initiating the payment transaction.

4
Verify Payment on Retry

When the agent retries the request, it will include the payment receipt in the Authorization header (e.g., Bearer <payment_token>). Your backend must now verify this token. Check that the transaction is confirmed on the blockchain (e.g., Base or Solana) and that the amount matches the required price. If valid, return the trading signal data with a 200 OK status.

By following this sequence, you ensure that your AI trading signals are monetized automatically without manual intervention. The x402 protocol handles the payment flow, allowing your API to focus on delivering accurate market data.

Implement the client payment flow

Once your AI trading signal endpoint returns a 402 Payment Required status, the client software must handle the transaction autonomously. This flow relies on the x402 protocol, which embeds payment instructions directly into the HTTP response headers. The client detects the blockage, executes the USDC transfer, and retries the request with proof of payment attached.

1
Detect the 402 response and parse payment instructions

When the agent’s request hits the API, a successful 402 response includes specific headers like x-pay-type and x-pay-uri. The client must intercept this status code rather than treating it as an error. It then parses the x-pay-uri to extract the payment destination, the required amount in USDC, and the chain ID. This step ensures the agent knows exactly what to pay and where, using the standardized format defined in the x402 V2 specification [src-serp-8].

2
Execute the USDC transfer via the agent’s wallet

With the payment details parsed, the client initiates a transaction using the AI agent’s integrated wallet. Since x402 supports multi-chain operations, the client verifies that the USDC is on the correct network (e.g., Base or Solana) before signing the transaction. The transfer is a simple on-chain payment to the address specified in the header. Because these are stablecoin payments, the transaction settles quickly and at negligible cost, allowing for high-frequency trading signal access [src-serp-2].

3
Attach the payment receipt to the retry request

After the transaction is confirmed on-chain, the client generates a payment receipt. This receipt is attached to the subsequent HTTP request using the Authorization header or a specific x402 payment header, depending on the endpoint’s configuration. The client then retries the original request for the trading signal. The server validates the receipt against the blockchain, and if the payment is verified, it returns the 200 OK response with the requested data.

This automated loop allows your AI agent to purchase trading signals without human intervention. By treating payments as a standard part of the HTTP lifecycle, you enable scalable, pay-per-use access to high-value market data.

Validate signals with x402 V2 standards

Before connecting your AI trading agents to live markets, you must ensure your implementation strictly follows the x402 V2 protocol. This version standardizes how networks and assets are identified, creating a single payment format that works across chains without requiring custom logic for each integration.

The V2 upgrade shifts x402 from a single-chain experiment to a multi-chain default. Your endpoints must now handle stablecoins and tokens across Base, Solana, and other L2s seamlessly. If your validation logic still relies on legacy, chain-specific identifiers, your agents will fail to pay for data or, worse, send payments to the wrong network.

Check multi-chain compatibility

Verify that your signal provider’s API accepts payments via the standardized V2 headers. This includes confirming that the x-payment-asset and x-payment-chain headers match the supported networks listed in the official x402 documentation. Your code should dynamically adjust these headers based on the user’s wallet, rather than hardcoding a single chain.

Verify standardized asset IDs

x402 V2 uses a unified format for asset identification to prevent ambiguity. Ensure your trading bot resolves token addresses correctly across different chains. For example, a USDC contract on Base is different from one on Solana, but the V2 protocol handles the routing automatically if your client library is up to date. Test this by sending a micro-transaction to a testnet endpoint to confirm the signal is delivered upon payment.

Confirm HTTP-native payment flow

The core advantage of x402 is instant, automatic stablecoin payments directly over HTTP. Validate that your integration does not require off-chain settlement steps or manual wallet approvals for every signal request. The payment should be embedded in the API call itself, allowing your AI agent to retrieve liquidity data or trade signals immediately after the transaction is confirmed.

Test the autonomous payment loop

This section verifies that your AI agent can request a trading signal, pay the x402 endpoint, and receive the data without human intervention. We will simulate a complete transaction cycle to ensure the payment logic and data delivery work as expected.

x402 Endpoints for AI Trading Signals
1
Set up the test environment

Before testing, ensure your AI agent has the necessary credentials. This includes a valid wallet address, sufficient stablecoin balance (USDC on Base is recommended for low fees), and the endpoint URL for your trading signal service. Verify that your x402-compliant API is running and ready to accept requests.

x402 Endpoints for AI Trading Signals
2
Send the initial request

Your AI agent should send an HTTP GET or POST request to the trading signal endpoint. At this stage, the server should respond with a 402 Payment Required status code. This response must include an x-x402-payment-url header or a JSON body containing the payment details, such as the amount, currency, and the blockchain network to use.

3
Execute the onchain payment

Using the payment details from the previous step, your agent initiates a transaction on the specified blockchain. For example, if the endpoint requires 0.01 USDC on Base, the agent will sign and broadcast the transaction from its wallet. Ensure the agent waits for the transaction to be confirmed on-chain before proceeding. This step confirms the agent can interact with the blockchain autonomously.

x402 Endpoints for AI Trading Signals
4
Verify payment and receive data

Once the payment is confirmed, your agent sends a second request to the endpoint, often including the transaction hash or signature as proof of payment. The server validates the payment and, if successful, returns a 200 OK status along with the trading signal data. This final step confirms the entire loop is functional: request, payment, and data delivery.

Frequently asked questions about x402