# Agentic payments with x402 protocol

With the [x402 protocol](https://www.x402.org/), AI agents can run Apify Actors and pay with USDC on the [Base](https://www.base.org/) blockchain - no Apify account needed.

Experimental feature

Agentic payments are experimental and may change as payment protocols evolve. Only Actors with the [Pay Per Event](https://pr-2413.preview.docs.apify.com/platform/actors/publishing/monetize/pay-per-event.md) pricing model are supported. [Standby](https://pr-2413.preview.docs.apify.com/platform/actors/running/standby.md) Actors are not supported.

## What is x402

The [x402 protocol](https://www.x402.org/) is an open standard for on-chain payments over HTTP. It uses [USDC](https://www.circle.com/usdc), a stablecoin pegged to the US dollar, on the [Base](https://www.base.org/) 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

* [mcpc CLI](https://github.com/apify/mcp-cli) installed (`npm install -g @apify/mcpc`) - manages your wallet and signs payments.
* A wallet funded with USDC on [Base](https://www.base.org/) 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](https://pr-2413.preview.docs.apify.com/platform/integrations/mcp.md) is the recommended way to get started. `mcpc` handles payment signing and retries automatically.

### How it works

1. The MCP server advertises payment requirements in each paid tool's metadata.
2. When `mcpc` calls a paid tool, it signs a USDC payment using your wallet and includes it in the request.
3. The server verifies and settles the payment on-chain, then runs the tool and returns the result.
4. If you call a tool without a payment, the server responds that payment is required and `mcpc` signs and retries automatically.

### Example

Agent autonomy

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

1. Call the Apify API with the header `X-APIFY-PAYMENT-PROTOCOL: X402` and no payment signature.
2. The API returns HTTP `402` with a `PAYMENT-REQUIRED` header - base64-encoded JSON listing accepted payment formats.
3. Sign the payment using `mcpc x402 sign <PAYMENT-REQUIRED header value>`.
4. Resend the request with two headers: `X-APIFY-PAYMENT-PROTOCOL: X402` and `PAYMENT-SIGNATURE: <signed payload>`.
5. The API settles the payment on-chain, runs the Actor, and returns the dataset items directly.

### Example

Actor name format

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](https://apify.com/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, `mcpc` signs 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)](https://docs.base.org/base-chain/network-information/network-fees) charged by the Base network to process the transaction.

## Next steps

* Browse [Apify Store](https://apify.com/store) for supported Actors to use with x402.
* Learn more about [Pay Per Event](https://pr-2413.preview.docs.apify.com/platform/actors/publishing/monetize/pay-per-event.md) pricing for Actors.
* Set up the [Apify MCP server](https://pr-2413.preview.docs.apify.com/platform/integrations/mcp.md) for automated tool discovery and payment handling.
* Read the [x402 protocol specification](https://www.x402.org/) for technical details on the payment standard.
