Set up the x402 payment layer

To integrate AI trading signals with x402, you need to bridge your existing API endpoints with the x402 payment protocol. This setup allows your AI agents to authenticate and pay for data automatically, turning a standard HTTP request into a transactional event. The core mechanism relies on the server returning a 402 Payment Required status code when a request is made without valid payment credentials.

Follow these steps to connect your trading signal API to the x402 protocol using the Coinbase Developer Platform (CDP).

1
Create a Coinbase Developer Platform (CDP) project

Start by setting up your environment. Log in to the Coinbase Developer Platform and create a new project. This project will serve as the container for your API keys and payment configurations. Ensure you have the necessary permissions to manage wallets and execute transactions on the Base network, as this is the primary chain for x402 transactions.

2
Configure your API to return 402 responses

Modify your trading signal API endpoints to enforce payment. When an unauthenticated request hits your server, it should not return a 401 or 403. Instead, return a 402 Payment Required status code. Include the Pay header in the response, which contains the payment details, such as the required amount in USDC and the destination wallet address. This header tells the agent exactly what to pay to access the data.

3
Implement the x402 middleware

Integrate an x402 middleware library into your backend. This middleware intercepts incoming requests and checks for the Pay header. If the header is present, the middleware validates the transaction on the blockchain. If the transaction is confirmed, the request proceeds to your trading logic. If not, the server returns the 402 response with the payment instructions.

4
Test with an x402-compatible agent

Use an x402-compatible AI agent to test the integration. Tools like the x402 Bazaar can help you discover and interact with x402-enabled services. Send a test request from your agent to your API. The agent should automatically detect the 402 response, execute the USDC payment, and retry the request with the valid payment proof. Verify that your trading signal is returned successfully after the payment is confirmed.

Once these steps are complete, your API will be ready to accept payments from AI agents. This setup ensures that only paying agents can access your valuable trading data, creating a sustainable revenue model for your service.

Format signal responses for agent consumption

After the agent pays via x402, the response must be immediate and machine-readable. AI agents lack the patience for human-friendly pages or complex authentication flows. They expect a raw data payload they can parse instantly to execute trades.

Use structured JSON for reliability

JSON is the standard for agent consumption because it maps directly to object-oriented languages like Python and JavaScript. Structure your trading signals with clear keys: timestamp, symbol, action (buy/sell), and price. Avoid nested complexity or ambiguous field names. Agents parse JSON faster than they can render HTML, reducing latency between payment and execution.

Keep payloads lean

Every millisecond counts in trading. Strip unnecessary metadata, comments, or pretty-printing whitespace from your response. A compact JSON payload ensures the agent receives the signal quickly, minimizing the window between payment confirmation and market action. If your endpoint returns a large CSV file, consider breaking it into smaller, tokenized chunks or providing a direct download link within the JSON response.

Handle errors gracefully

If the payment is invalid or the signal is unavailable, return a standard HTTP 402 or 400 error with a concise JSON body explaining the issue. Agents need to know immediately if something went wrong so they can retry or alert a human operator. Do not return HTML error pages; agents cannot parse them.

Handle 402 responses and retries

When your AI agent requests a paid trading signal, the server may return a 402 Payment Required status. This isn't an error; it's the protocol's way of saying, "I have the data, but you need to pay first." The response body contains the specific payment instructions, including the amount, currency (usually USDC), and the blockchain network required for the transaction.

Step 1: Parse the Payment Instructions

Extract the payment details from the 402 response. The server typically returns a JSON payload specifying the amount, currency, and chain. For example, you might see:

JSON
{
  "amount": "0.05",
  "currency": "USDC",
  "chain": "base",
  "recipient": "0x123..."
}

This tells your agent exactly what to sign and where to send the funds. Do not guess the parameters; rely on the server's explicit instructions.

Step 2: Sign and Send the Payment

Using your agent's wallet, sign a transaction for the specified amount on the indicated chain. The x402 protocol relies on on-chain payment proofs. Once the transaction is broadcast, wait for a single block confirmation to ensure the payment is not reverted. This confirmation is crucial for preventing double-spending and ensuring the server recognizes the payment.

Step 3: Attach the Payment Proof

After the payment is confirmed, generate a signature that proves the transaction occurred. This signature is usually a cryptographic proof linking the payment transaction hash to the original request. Attach this proof to a new Authorization header or as a specific X-Payment-Proof header in your retry request. The server needs this to verify that the payment was made by the same agent that made the request.

Step 4: Retry the Original Request

Resend the original request with the payment proof attached. If the server validates the proof, it will return a 200 OK with the trading signal data. If the proof is invalid or expired, the server may return another 402, prompting you to repeat the payment process. Always log these interactions for debugging and cost tracking.

For more details on the protocol structure, refer to the official x402 documentation.

List your endpoint on x402 Bazaar

Once your trading signal endpoint is live and responding to x402 payment requests, the next step is discovery. The x402 Bazaar acts as a machine-readable search engine for agents, allowing them to find and verify your API without manual configuration.

You register your service through the CDP Facilitator. This process involves submitting your endpoint's metadata, including its payment schema and available signal types, so the Bazaar can index it correctly.

1
Prepare your endpoint metadata

Ensure your endpoint returns the required x402 headers and payment instructions. You will need your API URL, the specific payment methods you accept (e.g., USDC on Base), and a description of the trading signals offered.

2
Access the CDP Facilitator

Navigate to the official Coinbase Developer Platform documentation for the x402 Bazaar. Use the provided Facilitator interface to begin the registration process. This is the central hub for cataloging x402-enabled services.

3
Submit your service registration

Enter your endpoint details into the registration form. Be precise with your metadata; agents rely on this information to determine if your signal matches their trading strategy. Include any necessary authentication tokens or rate limit information.

4
Verify and publish

After submission, the Bazaar will index your service. Verify that your endpoint is discoverable by testing a search query through the Bazaar interface. Once confirmed, your trading signal endpoint is live for AI agents to consume.

Before launching, ensure your endpoint is robust. Agents may retry requests or test endpoints before committing to paid signals.

Monitor settlements and revenue

Once your x402 endpoints are live, the next challenge isn't handling requests—it's verifying that payments actually landed. Because x402 settles USDC on-chain, you need a system to match incoming transactions with the signal requests your API processed. Without this reconciliation layer, you risk double-servicing requests or missing revenue from failed wallet interactions.

Start by listening to the blockchain for USDC transfers to your endpoint's payment address. The x402 V2 standard supports multi-chain settlements, so ensure your monitoring tool tracks the specific chain (like Base or Solana) your endpoint is configured for. When a transaction occurs, extract the paymentId from the transaction metadata. This ID is your primary key for matching the payment to the specific AI signal request in your database.

To visualize potential earnings, you can track the live value of these settlements. This helps you contextualize revenue per signal, especially if you adjust pricing based on market volatility. Finally, implement a status check in your API response. If the blockchain confirms the USDC transfer, return the signal data. If the payment is pending or missing, return a 402 status code as defined by the x402 protocol. This ensures that only paid requests trigger your most resource-intensive AI models, keeping your operational costs aligned with your revenue.

Common x402 integration: what to check next

Developers often hit specific friction points when wiring x402 endpoints for AI trading signals. Below are the most frequent protocol-level questions, sourced from official documentation and the broader Eco ecosystem.