Getting Started By x402

The x402 protocol (also known as L402) is an emerging standard for API monetization that enables pay-per-use access without requiring a subscription.

Minara x402 endpoint: https://x402.minara.ai

What is x402?

x402 is a native "pay-to-play" system for the web. Instead of pre-paying for a subscription, you pay for each API call directly using stablecoins like $USDC.

Key Benefits:

  • No Subscription Required: Pay only for what you use

  • Permissionless Access: No account creation or approval process

  • Instant Activation: Start using APIs immediately after payment

  • Crypto-Native: Payments in USDC on Base, Solana, or Polygon

  • Transparent Pricing: Know exactly what each API call costs

How it works:

The x402 protocol follows a payment-challenge flow with these key steps:

The Complete Flow

  1. Initial Request (Client → Server)

    • You make an API request to a protected endpoint without payment

  2. Payment Challenge (Server → Client)

    • Server responds with 402 Payment Required status

    • Returns payment instructions (amount, currency, recipient address, chain)

  3. Payment Selection (Client)

    • You select a payment method and create a payment payload

    • Prepare to pay with USDC on the specified chain

  4. Authenticated Request (Client → Server)

    • Include payment proof in x-payment-response header

    • Retry the original request

  5. Verification (Server → Facilitator)

    • Server sends payment proof to facilitator for verification

    • Confirms payment validity

  6. Payment Processing (Facilitator → Blockchain)

    • Facilitator submits transaction to blockchain

    • Transaction confirmed on-chain

  7. Settlement (Facilitator → Server)

    • Facilitator confirms settlement to server

    • Payment is finalized

  8. Access Granted (Server → Client)

    • You receive the API response

    • Payment receipt included in X-PAYMENT-RESPONSE header

Key Components

  • Client: Your application making API requests

  • Server: Minara API endpoints (https://x402.minara.ai)

  • Facilitator: Payment verification and settlement service

  • Blockchain: On-chain payment settlement (Base, Solana, or Polygon)


How to Use x402 with Minara

Most developers use the official x402 SDK which handles all payment flows automatically.

You just make requests: the SDK handles payment challenges, verification, and settlement for you.

Prerequisites

Before you begin, ensure you have:

  • A crypto wallet with USDC (any EVM-compatible wallet)

  • Node.js and npm, Go, or Python and pip

  • Your wallet's private key (for signing payments)

Step 1: Install Dependencies

chevron-rightNode.js / TypeScripthashtag
chevron-rightPythonhashtag
chevron-rightGohashtag

Step 2: Set Up Your Wallet Signer

chevron-rightNode.js (using viem)hashtag

For Solana:

chevron-rightPython (using eth-account)hashtag
chevron-rightGohashtag

Step 3: Make Requests: Payments Handled Automatically!

The SDK automatically handles payment challenges for you. Just make requests normally!

chevron-rightNode.js (with fetch)hashtag
chevron-rightNode.js (with axios)hashtag
chevron-rightPython (async with httpx)hashtag
chevron-rightPython (sync with requests)hashtag
chevron-rightGohashtag

Multi-Chain Support (Base + Solana + Polygon)

You can register multiple payment schemes to support all Minara chains:

Complete Example: Chat with Minara

Here's a complete working example that calls Minara's AI chat endpoint:

For more information, please check the official x402 documentation: Quickstart for buyersarrow-up-right


2. Manual Payment Flow (Without SDK)

If you prefer not to use the SDK, you can handle payments manually:

Step 1: Make Initial Request

Step 2: Receive Payment Challenge

Step 3: Pay with Wallet

Use MetaMask, Phantom, or any Web3 wallet to send USDC to the recipient address.

Step 4: Retry with Payment Proof

Step 5: Get Response


Error Handling

Common Errors from Minara API

402 Payment Required

→ Normal! SDK will handle this automatically.

401 Unauthorized

→ Payment proof invalid or expired. SDK will retry.

400 Bad Request

→ Check your request body has required fields.

Rate Limits

x402 endpoints are rate-limited per wallet address:

  • AI Endpoints: 60 requests/minute

  • Trading Endpoints: 30 requests/minute

If you exceed limits:


Resources & Support

📚 Official x402 Resources

📦 NPM Packages

🔍 Minara Specific

API Reference

API Reference (x402)chevron-right

Last updated

Was this helpful?