Skip to main content
POST
/
x402
/
pay
Pay External Service
curl --request POST \
  --url https://api.example.com/x402/pay \
  --header 'Content-Type: application/json' \
  --data '
{
  "url": "<string>",
  "method": "<string>",
  "headers": {},
  "body": "<string>"
}
'

Documentation Index

Fetch the complete documentation index at: https://docs.midasprotocol.org/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The x402 endpoint lets your agent pay any external service that supports the x402 protocol (HTTP 402 Payment Required). MIDAS acts as a proxy:
  1. Makes the HTTP request on your behalf
  2. If the service returns 402 Payment Required, MIDAS parses the payment requirements
  3. Signs an EIP-3009 transferWithAuthorization using your agent’s Base wallet
  4. Retries the request with the PAYMENT-SIGNATURE header
  5. Returns the service response to you
Protocol fees (1.5%) apply. Transaction limits based on your reputation tier apply.

Request

url
string
required
The target URL to call. Must be a valid HTTPS URL.
method
string
default:"GET"
HTTP method: GET, POST, PUT, PATCH, or DELETE.
headers
object
Optional headers to forward to the target service.
body
string
Request body for POST/PUT/PATCH requests. Max 50KB.

Example

curl -X POST https://api.midasprotocol.org/x402/pay \
  -H "Authorization: Bearer pp_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://api.example.com/premium-data",
    "method": "GET"
  }'

Response (no payment needed)

If the target service does not require payment, the response is proxied directly:
{
  "success": true,
  "statusCode": 200,
  "headers": { "content-type": "application/json" },
  "body": "{\"data\": \"...\"}"
}

Response (payment settled)

If the service returned 402 and MIDAS paid successfully:
{
  "success": true,
  "statusCode": 200,
  "headers": { "content-type": "application/json" },
  "body": "{\"data\": \"premium content\"}",
  "payment": {
    "amount": "0.01",
    "asset": "USDC",
    "network": "eip155:8453",
    "payTo": "0x...",
    "protocolFee": "0.00015"
  }
}

Response (payment failed)

{
  "success": false,
  "statusCode": 402,
  "headers": {},
  "body": "[...]",
  "error": "No compatible payment requirement found. MIDAS supports exact scheme on Base (eip155:8453) with USDC."
}

Supported Payment Schemes

SchemeNetworkAssetStatus
exact (EIP-3009)Base (eip155:8453)USDCSupported

Prerequisites

  • Your agent must have a blockchain wallet (automatically created at registration)
  • Sufficient USDC balance in your internal wallet
  • Transaction must be within your reputation tier limit

How It Works (Technical)

  1. MIDAS makes the initial HTTP request
  2. On 402 response, parses PAYMENT-REQUIRED header or response body
  3. Selects a compatible payment requirement (exact scheme, Base network, USDC)
  4. Decrypts the agent’s private key and signs an EIP-3009 TransferWithAuthorization
  5. Retries with both X-PAYMENT and PAYMENT-SIGNATURE headers
  6. On success, debits the agent’s internal USDC balance + 1.5% protocol fee