# x402 Standard: Enabling Seamless Open Payment Integration

## Overview

> **x402** is the open payment standard that enables services to charge for access to their APIs and content directly over HTTP. It is built around the **HTTP 402 Payment Required** status code and allows clients to programmatically pay for resources **without accounts, sessions, or credential management**.
>
> With x402, any web service can require payment before serving a response — using **crypto-native payments** for speed, privacy, and efficiency.
>
> **We** integrates x402 to enable **AI agents and wallets** to access on-chain analytics and insights seamlessly, with **built-in authentication and pay-per-call support** using wallet-based payments.

## What is x402?

**x402** is an emerging open standard developed by **Coinbase** for **AI-native API access**.

It defines how AI agents and applications can securely **authenticate, authorize, and pay** for API calls using crypto wallets instead of traditional API keys or credit cards.

In short, x402 is:

* A **crypto-based API gateway** standard.
* Designed for **agentic workloads** — enabling APIs to be called directly by AI models or smart wallets.
* Built around **verified identities** and **per-call metered billing** using on-chain settlements.

## Why x402?

| Benefit                          | Description                                                                                                          |
| -------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| **Crypto-native authentication** | No API keys — access is verified via signed requests or delegated wallet credentials.                                |
| **On-chain billing & metering**  | Pay for API usage via tokens or smart contract credits.                                                              |
| **Agent compatibility**          | AI agents and dApps can directly call APIs through their wallet identity.                                            |
| **Unified access layer**         | Works seamlessly across multiple providers that support the x402 protocol (e.g., Coinbase, OpenAI agents, Virtuals). |
| **Security & trust**             | No shared secrets or keys in backend configs — access is cryptographically validated.                                |

This makes x402 ideal for **AI agents**, **autonomous analytics services**, and **dApps** that need dynamic, authenticated access to **data APIs**.

***

## How We Supports x402

The **AI Data APIs** natively support **x402 headers and payment flows**, allowing secure, wallet-based access to paid API endpoints.

<figure><img src="https://411387007-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmieVdsFLVYWfiCpr2WSr%2Fuploads%2FWoVR2DcF2F0UckHFMBOg%2Fimage.png?alt=media&#x26;token=52acb2f5-d744-4767-bf3a-1ddf4e3d82d2" alt=""><figcaption></figcaption></figure>

#### **High-level workflow**

1. **Initial request:**

   The agent or user makes a request to the API endpoint (e.g., `/v1/ask-loky`).
2. **Payment challenge:**

   If payment is required, the API responds with a **`402 Payment Required`** status and includes **payment instructions** in the response body.
3. **Payment authorization:**

   The client (AI agent, wallet, or automated service) completes the payment using an **x402-compatible wallet or SDK**, which signs the payment payload as proof of payment.
4. **Retry with proof:**

   The client retries the same request, now including the **`X-PAYMENT`** header containing the **cryptographic proof of payment**.
5. **Verification and response:**

   The server verifies the payment via the x402 facilitator. Once validated, the API returns the **requested on-chain data or AI insights** securely.

***

## Supported APIs with x402

{% hint style="info" %}
<https://docs.dapplooker.com/data-apis-for-ai/api-endpoints>
{% endhint %}

***

## Technical details

This section explains how developers can integrate **x402** with AI Data APIs using **Node.js**, including authentication, payments, and rate limits.

<figure><img src="https://411387007-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmieVdsFLVYWfiCpr2WSr%2Fuploads%2FYomVyAYmJqeik8El7Ib1%2Fimage.png?alt=media&#x26;token=d185f99b-0149-41ed-83ab-f3e52302691b" alt=""><figcaption></figcaption></figure>

Integration with **x402** using **Node.js** is simple and can be summarized in **3 steps**:

1. **Install `x402-fetch`.**
2. **Create a wallet client (EVM).**
3. **Use the wrapper to make paid API requests** — payment flows are handled automatically.

Here’s Node.js example to make requests using `x402-fetch` (see the official [documentation](https://x402.gitbook.io/x402/getting-started/quickstart-for-buyers) for examples in other languages).

### **Prerequisites**

Before starting, ensure you have:

* A **crypto wallet with USDC** (any EVM-compatible wallet)
* **Node.js** and **npm**
* Service to access to a **endpoint requiring x402 payment**

### **1. Install Dependencies**

```bash
npm install x402-fetch
```

***

### **2. Create a Wallet Client (EVM)**

```jsx
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { baseSepolia } from "viem/chains";

// Load private key from environment variable
const account = privateKeyToAccount(process.env.PRIVATE_KEY!);
```

***

### **3. Make Paid Requests Automatically (x402-fetch)**

```jsx
import { wrapFetchWithPayment, decodeXPaymentResponse } from "x402-fetch";

// Wrap native fetch with x402 payment support
const fetchWithPayment = wrapFetchWithPayment(fetch, account);

const response = await fetchWithPayment(
	"<https://api.dapplooker.com/v1/trending>", 
	{
	  method: "GET",
	}
);

const body = await response.json();
console.log(body);

const paymentResponse = decodeXPaymentResponse(
  response.headers.get("x-payment-response")!
);
console.log(paymentResponse);
```

{% hint style="info" %}
The client handles 402 Payment Required responses automatically, completes the payment flow, and retries the request with the correct X-PAYMENT header.
{% endhint %}

***

### **4. Authentication**

* **Wallet-based** — no API keys required.
* **X-PAYMENT header** contains cryptographic proof of payment.
* Supported wallets: **Coinbase Smart Wallet**, **Virtuals Agent Wallet**, or any x402-compliant client.
* Stateless authentication — no sessions or credential storage needed.

***

### **5. Rate Limits**

* Default **rate limits per wallet/account** apply.
* Excessive unpaid or failed requests may trigger temporary throttling.

***

## References

* 🔗 [x402 Open Payment Standard](https://x402.gitbook.io/x402)
* 🔗 [Quickstart for Buyers / Users](https://x402.gitbook.io/x402/getting-started/quickstart-for-buyers)
* 🔗 [DappLooker AI APIs](https://docs.dapplooker.com/data-apis-for-ai/api-endpoints)

***

## Examples & Use Cases

### 1. **AI Agent Calling APIs**

An on-chain AI agent receives a user query like

> “Analyze recent liquidity inflow for $VIBES.”

The agent:

* Signs a request via its x402 wallet.
* Calls `POST /api/v1/ask-loky` with `x402-authorization`.
* Receives structured analytics data.

### 2. **Virtuals ACP Agent Integration**

Virtuals ACP buyer agents use the APIs via x402 for authenticated data delivery inside the Agent Commerce Protocol (ACP).

***

## FAQ

<details>

<summary>Do I need an API key if I’m using x402?</summary>

No — x402 replaces traditional API key authentication.

</details>

<details>

<summary>Can I use x402 with any EVM wallet?</summary>

Only wallets or agents that implement the x402 signing spec (currently Coinbase Smart Wallet,&#x20;

</details>
