# Get Started with x402 Payments

## 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="/files/rnvp8UkdPDvhJP0KVdSv" 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

{% content-ref url="/pages/FF7zwFXkzDKksLlG6vfB" %}
[API Endpoints](/products/api-endpoints.md)
{% endcontent-ref %}

***

## 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="/files/0g6OUxKThbi7bYw34vy9" 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/mcp` 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>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.dapplooker.com/get-started/get-started-with-x402-payments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
