Skip to content

Protocol Reference

This page documents the full x402 protocol specification, including HTTP headers, payload formats, facilitator API endpoints, and error codes.


Payment Requirements (402 Response)

When a server endpoint requires payment, it responds with HTTP status 402 Payment Required. The response body contains the payment requirements that the client must satisfy.

HTTP Status

HTTP/1.1 402 Payment Required

Response Body

FieldTypeDescription
x402VersionnumberThe x402 protocol version. Currently 1.
errorstringA human-readable description of why payment is required.
acceptsobject[]An array of accepted payment options. The client can choose any one.

accepts[] Object

Each entry in the accepts array describes one acceptable payment method:

FieldTypeDescription
schemestringThe payment scheme identifier (e.g., "exact").
networkstringThe blockchain network (e.g., "solana", "solana-devnet").
maxAmountRequiredstringThe maximum payment amount in the token's smallest unit (e.g., USDC has 6 decimals, so "100000" = 0.10 USDC).
assetstringThe token mint address or contract address of the payment asset.
payTostringThe recipient wallet address that should receive the payment.
resourcestringThe URL path of the resource being purchased.
descriptionstringA human-readable description of what the payment is for.
mimeTypestringThe MIME type of the resource that will be returned after payment.
outputSchemaobject | nullAn optional JSON Schema describing the structure of the response body.
maxTimeoutSecondsnumberThe maximum number of seconds the server will wait for payment settlement.
extraobject | nullOptional additional metadata specific to the payment scheme or network.

Example 402 Response

json
{
  "x402Version": 1,
  "error": "Payment required to access this resource.",
  "accepts": [
    {
      "scheme": "exact",
      "network": "solana",
      "maxAmountRequired": "100000",
      "asset": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
      "payTo": "9aUn5swQzUTRanaaTwmszxiv89cvFwUCjEBv1vZCoT1u",
      "resource": "/api/premium-data",
      "description": "Access to premium data endpoint",
      "mimeType": "application/json",
      "outputSchema": null,
      "maxTimeoutSeconds": 60,
      "extra": null
    }
  ]
}

Payment Proof (X-PAYMENT Header)

After receiving a 402 response, the client constructs a payment proof and includes it in the X-PAYMENT header when retrying the request.

Format

The X-PAYMENT header value is a Base64-encoded JSON string with the following structure:

FieldTypeDescription
x402VersionnumberThe x402 protocol version. Must match the version in the 402 response.
schemestringThe payment scheme being used (e.g., "exact").
networkstringThe blockchain network (e.g., "solana").
payloadobjectThe scheme-specific payment payload.

Solana Payload (Exact Scheme)

For the exact scheme on Solana, the payload object contains:

FieldTypeDescription
transactionstringA Base64-encoded partially-signed Solana transaction. The client signs the transaction as the payer, and the facilitator co-signs and submits it.

Example X-PAYMENT Header Value (Before Base64 Encoding)

json
{
  "x402Version": 1,
  "scheme": "exact",
  "network": "solana",
  "payload": {
    "transaction": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA..."
  }
}

Example Request with Payment

GET /api/premium-data HTTP/1.1
Host: example.com
X-PAYMENT: eyJ4NDAyVmVyc2lvbiI6MSwic2NoZW1lIjoiZXhhY3QiLC4uLn0=

Settlement Response (X-PAYMENT-RESPONSE Header)

After the server verifies and settles a payment, the response includes the X-PAYMENT-RESPONSE header with settlement details.

Fields

FieldTypeDescription
successbooleanWhether the payment was successfully settled.
errorReasonstring | nullA description of why the payment failed, or null if successful.
transactionstringThe on-chain transaction signature or hash.
networkstringThe network the transaction was settled on (e.g., "solana").
payerstringThe wallet address of the payer.

Example X-PAYMENT-RESPONSE Header Value

json
{
  "success": true,
  "errorReason": null,
  "transaction": "5UfDuX7hXrPtMGBb8efPkLszrgMfCnWdAhAkQbpSTmvHBMDy3UY...",
  "network": "solana",
  "payer": "7vto3C4YGhBrFsxVBu8TNaEL1gCDgMJwqBn2CnAFaJE2"
}

HTTP Status Codes

Status CodeMeaningDescription
200SuccessPayment was verified and settled. The response body contains the requested resource. The X-PAYMENT-RESPONSE header contains settlement details.
402Payment RequiredThe resource requires payment. The response body contains payment requirements.
400Bad RequestThe payment payload is invalid, malformed, or does not meet the server's requirements.
500Server ErrorAn unexpected error occurred during verification or settlement.

Facilitator API

The facilitator exposes HTTP endpoints for verifying and settling payments. The SVM Facilitator is hosted at https://facilitator.svmacc.tech.

POST /verify

Validates a payment payload without submitting it on-chain.

Request:

json
{
  "payload": "eyJ4NDAyVmVyc2lvbiI6MSwic2NoZW1lIjoiZXhhY3QiLC4uLn0=",
  "requirements": {
    "scheme": "exact",
    "network": "solana",
    "maxAmountRequired": "100000",
    "asset": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "payTo": "9aUn5swQzUTRanaaTwmszxiv89cvFwUCjEBv1vZCoT1u",
    "resource": "/api/premium-data",
    "description": "Access to premium data endpoint",
    "mimeType": "application/json",
    "outputSchema": null,
    "maxTimeoutSeconds": 60,
    "extra": null
  }
}

Response (success):

json
{
  "isValid": true,
  "invalidReason": null,
  "payer": "7vto3C4YGhBrFsxVBu8TNaEL1gCDgMJwqBn2CnAFaJE2"
}

Response (failure):

json
{
  "isValid": false,
  "invalidReason": "insufficient_funds",
  "payer": "7vto3C4YGhBrFsxVBu8TNaEL1gCDgMJwqBn2CnAFaJE2"
}

POST /settle

Submits a verified payment to the Solana network for on-chain settlement.

Request:

json
{
  "payload": "eyJ4NDAyVmVyc2lvbiI6MSwic2NoZW1lIjoiZXhhY3QiLC4uLn0=",
  "requirements": {
    "scheme": "exact",
    "network": "solana",
    "maxAmountRequired": "100000",
    "asset": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "payTo": "9aUn5swQzUTRanaaTwmszxiv89cvFwUCjEBv1vZCoT1u",
    "resource": "/api/premium-data",
    "description": "Access to premium data endpoint",
    "mimeType": "application/json",
    "outputSchema": null,
    "maxTimeoutSeconds": 60,
    "extra": null
  }
}

Response (success):

json
{
  "success": true,
  "errorReason": null,
  "transaction": "5UfDuX7hXrPtMGBb8efPkLszrgMfCnWdAhAkQbpSTmvHBMDy3UY...",
  "network": "solana",
  "payer": "7vto3C4YGhBrFsxVBu8TNaEL1gCDgMJwqBn2CnAFaJE2"
}

Response (failure):

json
{
  "success": false,
  "errorReason": "insufficient_funds",
  "transaction": null,
  "network": "solana",
  "payer": "7vto3C4YGhBrFsxVBu8TNaEL1gCDgMJwqBn2CnAFaJE2"
}

GET /supported

Returns all supported payment schemes, networks, and tokens.

Response:

json
{
  "x402Version": 1,
  "kinds": [
    {
      "scheme": "exact",
      "network": "solana",
      "asset": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
    },
    {
      "scheme": "exact",
      "network": "solana-devnet",
      "asset": "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU"
    }
  ]
}

Error Codes

The following error codes may appear in the invalidReason field of a verify response or the errorReason field of a settle response.

General Error Codes

Error CodeDescription
insufficient_fundsThe payer does not have enough of the required token to cover the payment amount.
invalid_networkThe specified network is not supported by the facilitator.
invalid_payloadThe payment payload is malformed or cannot be decoded.
invalid_schemeThe specified payment scheme is not supported.
invalid_x402_versionThe x402 protocol version in the payload does not match a supported version.
invalid_transaction_stateThe transaction is in an invalid state (e.g., already executed, expired, or has an invalid blockhash).
unexpected_verify_errorAn unexpected error occurred during payment verification.
unexpected_settle_errorAn unexpected error occurred during on-chain settlement.

Solana-Specific Error Codes

Error CodeDescription
invalid_exact_svm_payload_transaction_instructions_lengthThe Solana transaction contains an unexpected number of instructions. The facilitator expects a specific instruction layout for the exact payment scheme, and the submitted transaction does not match.

Next Steps

Powered by SVM Facilitator