Skip to content

Commit 7086720

Browse files
MQ37marcel-rbro
andauthored
docs: add direct API quickstart and improve x402 docs page (#2392)
## Summary - Adds a new **"Use x402 with the Apify API directly"** section with step-by-step payment flow and curl example using `run-sync-get-dataset-items` - Restructures the page for clarity: shared prerequisites/wallet setup at the top, parallel "How it works" + "Example" subsections for both MCP and direct API paths - Moves pricing/refund details into a single shared section to avoid duplication - Tightens intro and removes AI-sloppy filler phrases flagged in readability review - Adds "Supported Actors" info admonition (Pay Per Event only, no Standby) at page top - Adds "Agent autonomy" tip suggesting users provide this page as context to their AI agent - Fixes style issues: replaces em dashes with hyphens, removes incorrect bold emphasis --------- Co-authored-by: Marcel Rebro <marcel.rebro@apify.com>
1 parent 85008c1 commit 7086720

1 file changed

Lines changed: 93 additions & 38 deletions

File tree

  • sources/platform/integrations/ai
Lines changed: 93 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,129 @@
11
---
22
title: Agentic payments with x402 protocol
33
sidebar_label: x402
4-
description: Use the x402 protocol to enable AI agents to autonomously pay for Apify Actor runs using USDC on the Base blockchain.
4+
description: Use the x402 protocol to enable AI agents to autonomously pay for Apify Actor runs using USDC on the Base blockchain - no Apify account required.
55
sidebar_position: 19
66
slug: /integrations/x402
77
---
88

9-
Agentic payments enable AI agents to autonomously run Apify Actors using third-party payment providers, without requiring traditional Apify user accounts. This allows agents to discover, execute, and pay for web scraping and automation tasks independently.
10-
11-
Apify supports agentic payments through the [x402 protocol](https://www.x402.org/), an open standard for internet-native payments.
9+
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.
1210

1311
:::caution Experimental feature
1412

15-
Agentic payments are an experimental feature and may change significantly as payment protocols and AI technologies evolve.
13+
Agentic payments are experimental and may change as payment protocols evolve. Only Actors with the [Pay Per Event](/platform/actors/publishing/monetize/pay-per-event) pricing model are supported. [Standby](/platform/actors/running/standby) Actors are not supported.
1614

1715
:::
1816

1917
## What is x402
2018

21-
The [x402 protocol](https://www.x402.org/) is an open standard for internet-native payments. It enables direct on-chain payments using USDC on the [Base](https://www.base.org/) blockchain.
19+
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.
2220

23-
The Apify MCP server implements an MCP extension of this protocol to support agentic payments. The client automatically detects payment requirements in the tool's metadata and signs a USDC payment on the Base blockchain (mainnet). This payment is included with the tool call - no human intervention needed.
21+
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.
2422

25-
## Use x402 with Apify MCP server
23+
## Prerequisites
24+
25+
- [`mcpc` CLI](https://github.com/apify/mcp-cli) installed (`npm install -g @apify/mcpc`) - manages your wallet and signs payments.
26+
- A wallet funded with USDC on [Base](https://www.base.org/) mainnet.
2627

27-
The [Apify MCP server](/platform/integrations/mcp) provides the simplest way for agents to access Apify's Actor library using x402 payments.
28+
### Wallet setup
2829

29-
### Prerequisites
30+
Use the `mcpc` CLI to create or import a wallet:
3031

31-
- _`mcpc` CLI_ - Install the [`mcpc` CLI](https://github.com/apify/mcp-cli) (`npm install -g @apify/mcpc`), the Universal MCP command-line client.
32-
- _USDC on Base_ - A wallet funded with USDC on the [Base](https://www.base.org/) mainnet blockchain.
32+
```bash
33+
# Create a new wallet (generates a random private key)
34+
mcpc x402 init
3335

34-
### Setup
36+
# Or import an existing wallet from a private key
37+
mcpc x402 import <private-key>
3538

36-
Set up a local wallet and connect to the Apify MCP server with x402 payment support.
39+
# Verify your wallet address
40+
mcpc x402 info
41+
```
3742

38-
1. Create or import a wallet:
43+
Fund the displayed wallet address with USDC on Base mainnet.
3944

40-
```bash
41-
# Create a new wallet (generates a random private key)
42-
mcpc x402 init
45+
## Use x402 with Apify MCP server
4346

44-
# Or import an existing wallet from a private key
45-
mcpc x402 import <private-key>
47+
The [Apify MCP server](/platform/integrations/mcp) is the recommended way to get started. `mcpc` handles payment signing and retries automatically.
4648

47-
# Verify your wallet address
48-
mcpc x402 info
49-
```
49+
### How it works
5050

51-
1. Fund the wallet with USDC on Base mainnet.
51+
1. The MCP server advertises payment requirements in each paid tool's metadata.
52+
1. When `mcpc` calls a paid tool, it signs a USDC payment using your wallet and includes it in the request.
53+
1. The server verifies and settles the payment on-chain, then runs the tool and returns the result.
54+
1. If you call a tool without a payment, the server responds that payment is required and `mcpc` signs and retries automatically.
5255

53-
1. Connect to the Apify MCP server with x402 payment mode enabled. Add the `?payment=x402` query parameter to the server URL and pass the `--x402` flag to `mcpc`:
56+
### Example
5457

55-
```bash
56-
mcpc connect "mcp.apify.com?payment=x402" @apify --x402
57-
```
58+
:::tip Agent autonomy
5859

59-
1. Call tools as usual. Payments are handled automatically:
60+
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.
6061

61-
```bash
62-
mcpc @apify tools-call call-actor actor:="apify/rag-web-browser" input:='{"query": "latest AI news"}'
63-
```
62+
:::
63+
64+
```bash
65+
# Connect to the Apify MCP server with x402 enabled
66+
mcpc connect "mcp.apify.com?payment=x402" @apify --x402
67+
68+
# Call a paid tool - payment is handled automatically
69+
mcpc @apify tools-call call-actor actor:="apify/instagram-post-scraper" input:='{"username": ["natgeo"], "resultsLimit": 3}'
70+
```
71+
72+
## Use x402 with the Apify API directly
73+
74+
You can also send x402 payments directly against the Apify REST API. This works with any HTTP client or x402-compatible wallet.
6475

6576
### How it works
6677

67-
When x402 payment mode is enabled, the agent handles the full payment flow autonomously:
78+
1. Call the Apify API with the header `X-APIFY-PAYMENT-PROTOCOL: X402` and no payment signature.
79+
1. The API returns HTTP `402` with a `PAYMENT-REQUIRED` header - base64-encoded JSON listing accepted payment formats.
80+
1. Sign the payment using `mcpc x402 sign <PAYMENT-REQUIRED header value>`.
81+
1. Resend the request with two headers: `X-APIFY-PAYMENT-PROTOCOL: X402` and `PAYMENT-SIGNATURE: <signed payload>`.
82+
1. The API settles the payment on-chain, runs the Actor, and returns the dataset items directly.
83+
84+
### Example
85+
86+
:::caution Actor name format
87+
88+
When using the API, replace the `/` in the Actor name with `~` (for example, `apify/instagram-post-scraper` becomes `apify~instagram-post-scraper`).
89+
90+
:::
91+
92+
```bash
93+
# Step 1: Discover payment requirements
94+
curl -si \
95+
-H "X-APIFY-PAYMENT-PROTOCOL: X402" \
96+
"https://api.apify.com/v2/acts/apify~instagram-post-scraper/run-sync-get-dataset-items"
97+
# → HTTP 402 + PAYMENT-REQUIRED header value
98+
99+
# Step 2: Sign the payment with mcpc
100+
mcpc x402 sign <PAYMENT-REQUIRED header value>
101+
# → outputs your base64 PAYMENT-SIGNATURE
102+
103+
# Step 3: Run the Actor and get results in one call
104+
curl -s \
105+
-H "X-APIFY-PAYMENT-PROTOCOL: X402" \
106+
-H "PAYMENT-SIGNATURE: <base64-signed-payload>" \
107+
-H "Content-Type: application/json" \
108+
-d '{"username": ["natgeo"], "resultsLimit": 3}' \
109+
"https://api.apify.com/v2/acts/apify~instagram-post-scraper/run-sync-get-dataset-items"
110+
# → JSON array with the scraped Instagram posts
111+
```
112+
113+
You can replace `apify~instagram-post-scraper` with any supported Actor from [Apify Store](https://apify.com/store).
114+
115+
## Pricing and refunds
116+
117+
Both paths (MCP server and direct API) share the same pricing model:
118+
119+
- Minimum transaction: $1 in USDC.
120+
- The payment is tracked as a prepaid balance. Subsequent calls draw from it without new on-chain transactions.
121+
- When using the MCP server, `mcpc` signs a new payment automatically when the balance runs out.
122+
- 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.
68123

69-
1. The Apify MCP server advertises payment requirements in each paid tool's metadata.
70-
1. When `mcpc` calls a paid tool, it automatically signs a USDC payment using your local wallet and includes it in the request.
71-
1. The server verifies and settles the payment on-chain, then executes the tool and returns the result.
72-
1. If a tool is called without a payment, the server responds that payment is required and `mcpc` signs and retries automatically.
124+
## Next steps
73125

74-
The Apify MCP server requires a minimum transaction of $1.00. The server tracks the payment as a balance. Subsequent tool calls draw from this balance without requiring a new on-chain transaction. When the balance runs out, `mcpc` automatically signs a new payment to top it up. After a period of inactivity, the server refunds any remaining unused balance to the client's wallet address on the Base blockchain.
126+
- Browse [Apify Store](https://apify.com/store) for supported Actors to use with x402.
127+
- Learn more about [Pay Per Event](/platform/actors/publishing/monetize/pay-per-event) pricing for Actors.
128+
- Set up the [Apify MCP server](/platform/integrations/mcp) for automated tool discovery and payment handling.
129+
- Read the [x402 protocol specification](https://www.x402.org/) for technical details on the payment standard.

0 commit comments

Comments
 (0)