HomeDocsx402 Payments

x402 Payment Protocol

The x402 protocol enables pay-per-request API access using Solana payments. Access premium resources by paying with SOL - no subscription required.

How x402 Works

1

Request

Call a paid endpoint

2

402 Response

Get payment details

3

Pay

Send SOL payment

4

Access

Get your resource

Base URL

https://x402.acceso.dev

All x402 payment endpoints use this base URL

GET/resource

Access any paid resource via x402 protocol

Headers

HeaderValueDescription
X-Payment<payment_token>Payment proof token from wallet

Example Request

curl -X GET \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  "https://x402.acceso.dev/resource"

Example Response

// If payment required (402 Payment Required):
{
  "error": "Payment Required",
  "payment": {
    "amount": "0.001",
    "currency": "SOL",
    "recipient": "AccesoPaymentWallet...",
    "memo": "x402_resource_access"
  }
}

// If payment accepted (200 OK):
{
  "success": true,
  "data": { ... }  // Resource data
}
POST/v1/x402/create-payment

Create a payment intent for resource access

Request Body

NameTypeRequiredDescription
resourceIdstringYesID of the resource to access
amountnumberYesAmount in SOL
payerstringYesPayer wallet address

Example Request

curl -X POST \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "resourceId": "example_value",
  "amount": 0.001,
  "payer": "example_value"
}' \
  "https://x402.acceso.dev/v1/x402/create-payment"

Example Response

{
  "success": true,
  "data": {
    "paymentId": "pay_abc123...",
    "amount": 0.001,
    "currency": "SOL",
    "recipient": "AccesoPaymentWallet...",
    "memo": "x402_pay_abc123",
    "expiresAt": "2025-12-14T12:05:00.000Z"
  }
}
POST/v1/x402/verify-payment

Verify a payment transaction

Request Body

NameTypeRequiredDescription
paymentIdstringYesPayment intent ID
signaturestringYesSolana transaction signature

Example Request

curl -X POST \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "paymentId": "example_value",
  "signature": "example_value"
}' \
  "https://x402.acceso.dev/v1/x402/verify-payment"

Example Response

{
  "success": true,
  "data": {
    "verified": true,
    "paymentToken": "x402_token_xyz789...",
    "expiresAt": "2025-12-14T13:00:00.000Z"
  }
}
GET/v1/x402/payments

List your payment history

URL Parameters

NameTypeRequiredDescription
limitnumberNoMax results (default: 50)
statusstringNoFilter: pending, completed, expired

Example Request

curl -X GET \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  "https://x402.acceso.dev/v1/x402/payments"

Example Response

{
  "success": true,
  "data": [
    {
      "paymentId": "pay_abc123...",
      "amount": 0.001,
      "currency": "SOL",
      "status": "completed",
      "createdAt": "2025-12-14T12:00:00.000Z"
    }
  ]
}
GET/v1/x402/balance

Check your prepaid x402 credit balance

Example Request

curl -X GET \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  "https://x402.acceso.dev/v1/x402/balance"

Example Response

{
  "success": true,
  "data": {
    "balance": 0.05,
    "currency": "SOL",
    "lastDeposit": "2025-12-13T10:00:00.000Z"
  }
}
POST/v1/x402/deposit

Add funds to your x402 prepaid balance

Request Body

NameTypeRequiredDescription
amountnumberYesAmount in SOL to deposit
signaturestringYesDeposit transaction signature

Example Request

curl -X POST \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "amount": 0.001,
  "signature": "example_value"
}' \
  "https://x402.acceso.dev/v1/x402/deposit"

Example Response

{
  "success": true,
  "data": {
    "newBalance": 0.15,
    "depositAmount": 0.10,
    "transactionId": "dep_xyz789..."
  }
}

JavaScript Integration Example

import { Connection, PublicKey, Transaction } from '@solana/web3.js';

async function accessPaidResource(resourceUrl, wallet) {
  // 1. Try to access resource
  const response = await fetch(resourceUrl);
  
  if (response.status === 402) {
    // 2. Payment required - get payment details
    const { payment } = await response.json();
    
    // 3. Create and send payment transaction
    const connection = new Connection('https://api.mainnet-beta.solana.com');
    const tx = await createPaymentTx(wallet, payment);
    const signature = await wallet.sendTransaction(tx, connection);
    
    // 4. Verify payment and get token
    const verifyRes = await fetch('https://x402.acceso.dev/v1/x402/verify-payment', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ 
        paymentId: payment.paymentId, 
        signature 
      })
    });
    
    const { data: { paymentToken } } = await verifyRes.json();
    
    // 5. Access resource with payment token
    return fetch(resourceUrl, {
      headers: { 'X-Payment': paymentToken }
    });
  }
  
  return response;
}