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.devAll x402 payment endpoints use this base URL
GET
/resourceAccess any paid resource via x402 protocol
Headers
| Header | Value | Description |
|---|---|---|
| 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-paymentCreate a payment intent for resource access
Request Body
| Name | Type | Required | Description |
|---|---|---|---|
| resourceId | string | Yes | ID of the resource to access |
| amount | number | Yes | Amount in SOL |
| payer | string | Yes | Payer 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-paymentVerify a payment transaction
Request Body
| Name | Type | Required | Description |
|---|---|---|---|
| paymentId | string | Yes | Payment intent ID |
| signature | string | Yes | Solana 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/paymentsList your payment history
URL Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| limit | number | No | Max results (default: 50) |
| status | string | No | Filter: 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/balanceCheck 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/depositAdd funds to your x402 prepaid balance
Request Body
| Name | Type | Required | Description |
|---|---|---|---|
| amount | number | Yes | Amount in SOL to deposit |
| signature | string | Yes | Deposit 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;
}