Agentic payments with x402 protocol
With the x402 protocol, AI agents can run Apify Actors and pay with USDC on the Base blockchain - no Apify account needed.
Agentic payments are experimental and may change as payment protocols evolve. Only Actors with the Pay Per Event pricing model are supported. Standby Actors are not supported.
What is x402
The x402 protocol is an open standard for on-chain payments over HTTP. It uses USDC, a stablecoin pegged to the US dollar, on the Base blockchain.
When a server requires payment, it responds with HTTP 402 and tells the client what payment formats it accepts. The client signs a USDC transfer off-chain (locally, without touching the blockchain) and resends the request with the signature attached. The server settles (finalizes) the payment on-chain (on the blockchain) and processes the request.
Prerequisites
mcpcCLI installed (npm install -g @apify/mcpc) - manages your wallet and signs payments.- A wallet funded with USDC on Base mainnet.
Wallet setup
Use the mcpc CLI to create or import a wallet:
# Create a new wallet (generates a random private key)
mcpc x402 init
# Or import an existing wallet from a private key
mcpc x402 import <private-key>
# Verify your wallet address
mcpc x402 info
Fund the displayed wallet address with USDC on Base mainnet.
Use x402 with Apify MCP server
The Apify MCP server is the recommended way to get started. mcpc handles payment signing and retries automatically.
How it works
- The MCP server advertises payment requirements in each paid tool's metadata.
- When
mcpccalls a paid tool, it signs a USDC payment using your wallet and includes it in the request. - The server verifies and settles the payment on-chain, then runs the tool and returns the result.
- If you call a tool without a payment, the server responds that payment is required and
mcpcsigns and retries automatically.
Example
Provide this page (or the example below) as context to your AI agent. The agent can then connect to the Apify MCP server and pay for tools via x402 autonomously - no human in the loop.
# Connect to the Apify MCP server with x402 enabled
mcpc connect "mcp.apify.com?payment=x402" @apify --x402
# Call a paid tool - payment is handled automatically
mcpc @apify tools-call call-actor actor:="apify/instagram-post-scraper" input:='{"username": ["natgeo"], "resultsLimit": 3}'
Use x402 with the Apify API directly
You can also send x402 payments directly against the Apify REST API. This works with any HTTP client or x402-compatible wallet.
How it works
- Call the Apify API with the header
X-APIFY-PAYMENT-PROTOCOL: X402and no payment signature. - The API returns HTTP
402with aPAYMENT-REQUIREDheader - base64-encoded JSON listing accepted payment formats. - Sign the payment using
mcpc x402 sign <PAYMENT-REQUIRED header value>. - Resend the request with two headers:
X-APIFY-PAYMENT-PROTOCOL: X402andPAYMENT-SIGNATURE: <signed payload>. - The API settles the payment on-chain, runs the Actor, and returns the dataset items directly.
Example
When using the API, replace the / in the Actor name with ~ (for example, apify/instagram-post-scraper becomes apify~instagram-post-scraper).
# Step 1: Discover payment requirements
curl -si \
-H "X-APIFY-PAYMENT-PROTOCOL: X402" \
"https://api.apify.com/v2/acts/apify~instagram-post-scraper/run-sync-get-dataset-items"
# → HTTP 402 + PAYMENT-REQUIRED header value
# Step 2: Sign the payment with mcpc
mcpc x402 sign <PAYMENT-REQUIRED header value>
# → outputs your base64 PAYMENT-SIGNATURE
# Step 3: Run the Actor and get results in one call
curl -s \
-H "X-APIFY-PAYMENT-PROTOCOL: X402" \
-H "PAYMENT-SIGNATURE: <base64-signed-payload>" \
-H "Content-Type: application/json" \
-d '{"username": ["natgeo"], "resultsLimit": 3}' \
"https://api.apify.com/v2/acts/apify~instagram-post-scraper/run-sync-get-dataset-items"
# → JSON array with the scraped Instagram posts
You can replace apify~instagram-post-scraper with any supported Actor from Apify Store.
Pricing and refunds
Both paths (MCP server and direct API) share the same pricing model:
- Minimum transaction: $1 in USDC.
- The payment is tracked as a prepaid balance. Subsequent calls draw from it without new on-chain transactions.
- When using the MCP server,
mcpcsigns a new payment automatically when the balance runs out. - After 60 minutes of inactivity (no running Actors), any remaining balance is refunded on-chain to your wallet, minus a small gas fee (network cost) charged by the Base network to process the transaction.
Next steps
- Browse Apify Store for supported Actors to use with x402.
- Learn more about Pay Per Event pricing for Actors.
- Set up the Apify MCP server for automated tool discovery and payment handling.
- Read the x402 protocol specification for technical details on the payment standard.