API Documentation

MicroAPI Hub implements the x402 payment protocol for pay-per-use API access on Solana.

Showing static documentation. Connect to a running provider service to see live endpoints.
GET/api/data

Sample data API (pay-per-call)

Payment Requirements

Network

solana-devnet

Asset

USDC_MINT_ADDRESS

Amount

1 atomic units

Timeout

60s

Pay To

YOUR_PAYMENT_ADDRESS

Payment Flow

  1. Make initial request without payment header
  2. Receive 402 Payment Required response with X-PAYMENT-REQUIREMENTS header
  3. Parse requirements and construct payment payload
  4. Sign payment with your Solana wallet
  5. Retry request with X-PAYMENT header containing signed payload
  6. Receive resource data with X-PAYMENT-RESPONSE header containing transaction hash

Code Examples

cURL

# Step 1: Initial request (will receive 402)
curl -i http://localhost:8080/api/data

# Step 2: Retry with payment header
curl -H "X-PAYMENT: <base64-encoded-payment-payload>" \
  http://localhost:8080/api/data

TypeScript (x402-fetch)

import { fetchWithPayment } from '@coinbase/x402-fetch';
import { Wallet } from '@solana/web3.js';

const wallet = new Wallet(/* your keypair */);
const url = 'http://localhost:8080/api/data';

const response = await fetchWithPayment(url, {
  wallet,
  network: 'solana-devnet',
});

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

Python

import requests
from x402 import build_payment_header

# Step 1: Get payment requirements
response = requests.get('http://localhost:8080/api/data')
if response.status_code == 402:
    requirements = response.json()['accepts'][0]
    
    # Step 2: Build and sign payment
    payment_header = build_payment_header(
        requirements,
        wallet_keypair,
        network='solana-devnet'
    )
    
    # Step 3: Retry with payment
    response = requests.get(
        'http://localhost:8080/api/data',
        headers={'X-PAYMENT': payment_header}
    )
    data = response.json()

Response Format

Success Response (200 OK)

HTTP/1.1 200 OK
X-PAYMENT-RESPONSE: <base64-encoded-settlement-response>
Content-Type: application/json

{
  "data": {
    "message": "Hello from MicroAPI Hub provider",
    "ts": "2024-01-01T00:00:00.000Z"
  }
}

Payment Required (402)

HTTP/1.1 402 Payment Required
X-PAYMENT-REQUIREMENTS: <base64-encoded-requirements>
Content-Type: application/json

{
  "x402Version": 1,
  "error": "X-PAYMENT header is required",
  "accepts": [
    {
      "scheme": "exact",
      "network": "solana-devnet",
      "maxAmountRequired": "1",
      "resource": "GET /api/data",
      "description": "Sample data API (pay-per-call)",
      "payTo": "YOUR_PAYMENT_ADDRESS",
      "asset": "USDC_MINT_ADDRESS"
    }
  ]
}

Discovery Endpoint

All x402-compliant providers expose a discovery endpoint at /.well-known/x402that lists all available endpoints and their payment requirements.

Request

GET /.well-known/x402
Host: localhost:8080

Response

{
  "x402Version": 1,
  "accepts": [
    {
      "route": "GET /api/data",
      "requirements": {
        "scheme": "exact",
        "network": "solana-devnet",
        "maxAmountRequired": "1",
        "resource": "GET /api/data",
        "description": "Sample data API (pay-per-call)",
        "payTo": "...",
        "asset": "..."
      }
    }
  ]
}