ScavioScavio
FeaturesPricingDocs
Sign InGet Started
  1. Home
  2. Tutorials
  3. How to Pay Per API Call with x402
Tutorial

How to Pay Per API Call with x402

x402 is the 2026 HTTP 402-based micropayment protocol for AI agents. Learn how to wire it into your Scavio API calls for usage-based billing.

Get Free API KeyAPI Docs

x402 is the 2026 micropayment protocol built on HTTP 402, letting AI agents pay for each API call with stablecoin micropayments instead of prepaid subscriptions. With 119M+ transactions as of March 2026, it is the fastest-growing paid-API pattern. This tutorial shows how to wire x402 into your Scavio API calls for usage-based billing.

Prerequisites

  • Python 3.8+ or Node 20+
  • An x402 client library (x402-python or x402-js)
  • A funded x402 wallet (Base network)
  • A Scavio x402-enabled endpoint

Walkthrough

Step 1: Install the x402 client

Install the official x402 client.

Bash
pip install x402-python

Step 2: Configure your wallet

Point the client at your funded Base-network wallet.

Python
from x402 import Client

client = Client(
    private_key=os.environ['X402_WALLET_KEY'],
    network='base'
)

Step 3: Make an x402-enabled call

Call Scavio's x402 endpoint. The client handles HTTP 402 and pays automatically.

Python
response = client.post(
    'https://api.scavio.dev/x402/v1/search',
    json={'query': 'AI agents 2026'}
)
print(response.json())

Step 4: Verify payment receipt

Each response includes the x402 payment receipt for audit.

Python
print('Paid:', response.headers.get('x-402-amount'))
print('Receipt:', response.headers.get('x-402-receipt'))

Step 5: Batch for efficiency

Batch queries to reduce per-call payment overhead.

Python
queries = ['query1', 'query2', 'query3']
responses = client.batch_post(
    'https://api.scavio.dev/x402/v1/search',
    [{'query': q} for q in queries]
)

Python Example

Python
import os
from x402 import Client

client = Client(private_key=os.environ['X402_WALLET_KEY'], network='base')

response = client.post(
    'https://api.scavio.dev/x402/v1/search',
    json={'query': 'AI agents 2026'}
)
print('Results:', len(response.json().get('organic_results', [])))
print('Paid:', response.headers.get('x-402-amount'), 'USDC')

JavaScript Example

JavaScript
import { Client } from 'x402-js';

const client = new Client({
  privateKey: process.env.X402_WALLET_KEY,
  network: 'base'
});

const response = await client.post('https://api.scavio.dev/x402/v1/search', {
  query: 'AI agents 2026'
});
console.log('Results:', response.data.organic_results.length);
console.log('Paid:', response.headers['x-402-amount'], 'USDC');

Expected Output

JSON
Results: 10
Paid: 0.003 USDC
The agent paid 0.003 USDC per API call. No prepaid subscription, no minimum commitment.

Related Tutorials

  • How to Build a Hermes Agent Search Tool
  • How to Build an OpenClaw Search Agent

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

Python 3.8+ or Node 20+. An x402 client library (x402-python or x402-js). A funded x402 wallet (Base network). A Scavio x402-enabled endpoint. A Scavio API key gives you 250 free credits per month.

Yes. The free tier includes 250 credits per month, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Related Resources

Best Of

Best Tools for Building Agents Without Frameworks (2026)

Read more
Use Case

Budget-Controlled Agent Search

Read more
Best Of

Best APIs for Agent Memory Search Grounding (2026)

Read more
Use Case

Plain Python Agent Search Tooling

Read more
Workflow

Agent Search Cost and Budget Tracking Workflow

Read more
Solution

Pay-Per-Call Search for Agents with x402

Read more

Start Building

x402 is the 2026 HTTP 402-based micropayment protocol for AI agents. Learn how to wire it into your Scavio API calls for usage-based billing.

Get Free API KeyRead the Docs
ScavioScavio

Real-time search API for AI agents. Search every platform, not just Google.

Product

  • Features
  • Pricing
  • Dashboard
  • Affiliates

Developers

  • Documentation
  • API Reference
  • Quickstart
  • MCP Integration
  • Python SDK

Alternatives

  • Tavily Alternative
  • SerpAPI Alternative
  • Firecrawl Alternative
  • Exa Alternative

Tools

  • JSON Formatter
  • cURL to Code
  • Token Counter
  • All Tools

© 2026 Scavio. All rights reserved.

Featured on TAAFT
Terms of ServicePrivacy Policy