OpenKrill - x402 Payments Skill
This skill enables AI agents to autonomously make micropayments using the x402 protocol. It handles wallet management, balance checking, and automatic payment flows when APIs return HTTP 402 Payment Required responses.
When to Use This Skill
- - When asked "what services can I purchase?" or "what x402 APIs are available?" - Query the Bazaar first!
- When purchasing browser automation sessions on Browserbase
- When performing web scraping tasks with Firecrawl
- When the agent needs to create an email address for signups or verification
- When interacting with any x402-compatible API
- When the user mentions micropayments, crypto payments, or paying for API access
- When you encounter a 402 Payment Required response
- When discovering new x402-compatible services via the Bazaar
TIP: When a user or agent asks what services are available for purchase, always start by querying the Bazaar discovery endpoint. It provides a live, up-to-date catalog of 12,000+ x402-compatible services.
Quick: Discover Available Services
CODEBLOCK0
Prerequisites
Before using this skill, ensure:
- 1. THIRDWEBSECRETKEY environment variable is set with a valid thirdweb project secret key
- The wallet has sufficient USDC balance on Base chain (or the target chain)
- Network access to thirdweb API endpoints
IMPORTANT: x402 Endpoint URLs & Service Types
Two Types of x402 Support
| Type | Description | Example |
|---|
| True x402 | Fully keyless - no API keys needed, just pay and use | Browserbase |
| Hybrid x402 |
Requires API key/token + payment header | Firecrawl |
x402 Endpoint Patterns
| Service | Standard API | x402 Endpoint | Type | Status |
|---|
| Browserbase | INLINECODE0 | INLINECODE1 | True x402 | ✅ Works |
| Firecrawl |
api.firecrawl.dev/v1/search |
api.firecrawl.dev/v1/x402/search | Non-standard | ❌ Broken |
Discovery tips:
- - Check for
x402. subdomain (e.g., x402.browserbase.com) - Check for
/x402/ in the path (e.g., /v1/x402/search) - Hit the x402 root URL for endpoint listing (e.g.,
curl https://x402.browserbase.com/)
Core Workflow
Step 1: Check or Create Wallet
Use the thirdweb API directly (recommended):
CODEBLOCK1
The response will include the wallet address. Store this for subsequent operations.
Step 2: Make Payments with fetchWithPayment
Call the thirdweb x402 fetch API directly:
CODEBLOCK2
Step 3: Handle the Response
Success: The API returns the session data directly.
Insufficient Funds: If the wallet needs funding, the API returns:
CODEBLOCK3
When you receive a payment link, open it in the user's browser:
- - If browser automation is available (MCP, browser tool, etc.), use it to navigate to the link in a new tab
- Otherwise, display the link prominently and instruct the user to open it manually
This opens thirdweb's payment page where users can fund the wallet.
API Reference
fetchWithPayment Endpoint
URL: INLINECODE9
Method: POST
Query Parameters:
| Parameter | Required | Description |
|---|
| INLINECODE10 | Yes | Target API URL to call |
| INLINECODE11 |
Yes | HTTP method (GET, POST, etc.) |
|
from | No | Wallet address for payment (uses default project wallet if omitted) |
|
maxValue | No | Maximum payment amount in wei |
|
asset | No | Payment token address (defaults to USDC) |
|
chainId | No | Chain ID for payment (e.g., "eip155:8453" for Base) |
Headers:
- -
x-secret-key: Your thirdweb project secret key (required) - INLINECODE17 : application/json
Supported x402 Services
Browserbase
x402 Endpoint: https://x402.browserbase.com
Pricing: $0.12/hour (paid in USDC on Base)
| Endpoint | Method | Description |
|---|
| INLINECODE19 | POST | Create a browser session |
| INLINECODE20 |
GET | Check session status |
|
/browser/session/:id/extend | POST | Add more time |
|
/browser/session/:id | DELETE | Terminate session |
CODEBLOCK4
Firecrawl (Non-Standard x402 - NOT RECOMMENDED)
x402 Endpoint: https://api.firecrawl.dev/v1/x402/search
Pricing: $0.01/request
Status: ⚠️ Incomplete implementation - cannot be used with thirdweb
WARNING: Firecrawl's x402 implementation is non-standard and currently unusable for automated agents:
- 1. Returns
401 Unauthorized instead of INLINECODE25 - Doesn't include payment details (payTo address, asset, amount) in response
- Documentation says to use
X-Payment: {{paymentHeader}} but doesn't explain how to generate it
Comparison with proper x402 (Browserbase):
- - Browserbase: Returns 402 with
x402Version, accepts, payTo, asset → thirdweb can auto-pay - Firecrawl: Returns 401 with just
{"error":"Unauthorized"} → no payment info provided
| Endpoint | Method | Status |
|---|
| INLINECODE32 | POST | ❌ Non-functional for agents |
Recommended alternatives:
- 1. Firecrawl MCP - If available in your environment (uses standard API key)
- Browserbase + scraping script - True x402, fully keyless
- Standard Firecrawl API - With subscription/API key
Reference: Firecrawl x402 docs
Mail.tm (Disposable Email)
Base URL: https://api.mail.tm
Pricing: Free (no x402 payment required)
Mail.tm allows agents to create email addresses for signups and receive verification emails.
| Endpoint | Method | Auth | Description |
|---|
| INLINECODE34 | GET | No | Get available email domains |
| INLINECODE35 |
POST | No | Create an email account |
|
/token | POST | No | Get authentication token |
|
/messages | GET | Yes | List all messages |
|
/messages/:id | GET | Yes | Get full message content |
|
/me | GET | Yes | Get account info |
Create Email Account
CODEBLOCK5
Get Token and Check Messages
CODEBLOCK6
Important: Store email credentials (address, password, token) for later use. Consider saving to .agent-emails.json (gitignored).
Error Handling
| Error | Cause | Solution |
|---|
| 401 Unauthorized | Invalid or missing THIRDWEBSECRETKEY | Check environment variable |
| 402 Payment Required |
Insufficient balance | Auto-open payment link (see above) |
| 400 Bad Request | Invalid URL or method | Verify request parameters |
| 404 Not Found | Wrong endpoint | Check x402-specific endpoint (e.g.,
x402.browserbase.com) |
| 500 Server Error | thirdweb or target API issue | Retry or check service status |
Common Mistakes
- 1. Using wrong subdomain:
api.browserbase.com vs INLINECODE43 - Using wrong path:
/v1/sessions vs INLINECODE45 - Not checking for payment links: Always parse response for
link field
Discovering x402 Endpoints
There are two ways to discover x402-compatible services:
Method 1: x402 Bazaar (Recommended)
The x402 Bazaar is a machine-readable catalog that helps AI agents discover x402-compatible API endpoints programmatically.
Query the Bazaar Discovery Endpoint
CODEBLOCK7
Using the Discovery Script
CODEBLOCK8
Response Format
CODEBLOCK9
Query Parameters
| Parameter | Type | Default | Description |
|---|
| INLINECODE47 | string | - | Filter by protocol type (e.g., "http") |
| INLINECODE49 |
number | 20 | Number of resources to return (max: 100) |
|
offset | number | 0 | Offset for pagination |
Method 2: Manual Discovery
When encountering a new service that might support x402:
1. Check for x402 Subdomain
CODEBLOCK10
2. Check for /x402/ Path Prefix
CODEBLOCK11
3. Test for 402 Response
CODEBLOCK12
Expected for true x402:
CODEBLOCK13
If you see 401 Unauthorized: The service uses hybrid x402 (needs API key + payment).
4. Check Service Documentation
Look for x402/payments documentation:
- - INLINECODE51
- INLINECODE52
- Search for "x402" or "402" in their docs
Additional Resources
Links
OpenKrill - x402 支付技能
本技能使AI代理能够使用x402协议自主进行微支付。它处理钱包管理、余额检查,以及当API返回HTTP 402 Payment Required响应时的自动支付流程。
何时使用此技能
- - 当被问及我可以购买哪些服务?或有哪些x402 API可用?时 - 首先查询Bazaar!
- 在Browserbase上购买浏览器自动化会话时
- 使用Firecrawl执行网页抓取任务时
- 当代理需要创建电子邮件地址用于注册或验证时
- 与任何兼容x402的API交互时
- 当用户提到微支付、加密货币支付或为API访问付费时
- 当遇到402 Payment Required响应时
- 通过Bazaar发现新的x402兼容服务时
提示: 当用户或代理询问有哪些服务可供购买时,始终从查询Bazaar发现端点开始。它提供包含12,000多个x402兼容服务的实时、最新目录。
快速发现可用服务
bash
查询Bazaar查看可用服务(无需认证)
curl -s https://api.cdp.coinbase.com/platform/v2/x402/discovery/resources?type=http&limit=50
前提条件
使用此技能前,请确保:
- 1. THIRDWEBSECRETKEY 环境变量已设置为有效的thirdweb项目密钥
- 钱包在Base链(或目标链)上有足够的USDC余额
- 网络可访问thirdweb API端点
重要:x402端点URL与服务类型
两种x402支持类型
| 类型 | 描述 | 示例 |
|---|
| 纯x402 | 完全无密钥 - 无需API密钥,只需付费即可使用 | Browserbase |
| 混合x402 |
需要API密钥/令牌 + 支付头 | Firecrawl |
x402端点模式
| 服务 | 标准API | x402端点 | 类型 | 状态 |
|---|
| Browserbase | api.browserbase.com | x402.browserbase.com | 纯x402 | ✅ 可用 |
| Firecrawl |
api.firecrawl.dev/v1/search | api.firecrawl.dev/v1/x402/search | 非标准 | ❌ 已损坏 |
发现提示:
- - 检查x402.子域名(例如x402.browserbase.com)
- 检查路径中的/x402/(例如/v1/x402/search)
- 访问x402根URL获取端点列表(例如curl https://x402.browserbase.com/)
核心工作流
步骤1:检查或创建钱包
直接使用thirdweb API(推荐):
bash
curl -s -X POST https://api.thirdweb.com/v1/wallets/server \
-H Content-Type: application/json \
-H x-secret-key: $THIRDWEBSECRETKEY \
-d {identifier: x402-agent-wallet}
响应将包含钱包地址。请存储此地址以供后续操作使用。
步骤2:使用fetchWithPayment进行支付
直接调用thirdweb x402 fetch API:
bash
Browserbase - 创建浏览器会话
curl -s -X POST https://api.thirdweb.com/v1/payments/x402/fetch?url=https://x402.browserbase.com/browser/session/create&method=POST \
-H Content-Type: application/json \
-H x-secret-key: $THIRDWEB
SECRETKEY \
-d {browserSettings: {viewport: {width: 1920, height: 1080}}}
步骤3:处理响应
成功: API直接返回会话数据。
余额不足: 如果钱包需要充值,API返回:
json
{
result: {
message: 此端点需要链ID 8453上的0.002 USDC...,
link: https://thirdweb.com/pay?chain=8453&receiver=0x...&token=0x...
}
}
当收到支付链接时,在用户浏览器中打开它:
- - 如果浏览器自动化可用(MCP、浏览器工具等),使用它在新标签页中导航到该链接
- 否则,突出显示该链接并指导用户手动打开
这将打开thirdweb的支付页面,用户可以在其中为钱包充值。
API参考
fetchWithPayment端点
URL: https://api.thirdweb.com/v1/payments/x402/fetch
方法: POST
查询参数:
| 参数 | 必需 | 描述 |
|---|
| url | 是 | 要调用的目标API URL |
| method |
是 | HTTP方法(GET、POST等) |
| from | 否 | 支付钱包地址(省略时使用默认项目钱包) |
| maxValue | 否 | 最大支付金额(以wei为单位) |
| asset | 否 | 支付代币地址(默认为USDC) |
| chainId | 否 | 支付链ID(例如Base的eip155:8453) |
头信息:
- - x-secret-key:您的thirdweb项目密钥(必需)
- Content-Type:application/json
支持的x402服务
Browserbase
x402端点: https://x402.browserbase.com
定价: $0.12/小时(以Base链上的USDC支付)
| 端点 | 方法 | 描述 |
|---|
| /browser/session/create | POST | 创建浏览器会话 |
| /browser/session/:id/status |
GET | 检查会话状态 |
| /browser/session/:id/extend | POST | 增加时间 |
| /browser/session/:id | DELETE | 终止会话 |
bash
curl -s -X POST https://api.thirdweb.com/v1/payments/x402/fetch?url=https://x402.browserbase.com/browser/session/create&method=POST \
-H Content-Type: application/json \
-H x-secret-key: $THIRDWEBSECRETKEY \
-d {browserSettings: {viewport: {width: 1920, height: 1080}}}
Firecrawl(非标准x402 - 不推荐)
x402端点: https://api.firecrawl.dev/v1/x402/search
定价: $0.01/请求
状态: ⚠️ 实现不完整 - 无法与thirdweb一起使用
警告: Firecrawl的x402实现是非标准的,目前无法用于自动化代理:
- 1. 返回401 Unauthorized而不是402 Payment Required
- 响应中不包含支付详情(payTo地址、资产、金额)
- 文档说使用X-Payment: {{paymentHeader}},但未说明如何生成
与正确x402(Browserbase)的比较:
- - Browserbase:返回402,包含x402Version、accepts、payTo、asset → thirdweb可自动支付
- Firecrawl:返回401,仅包含{error:Unauthorized} → 未提供支付信息
| 端点 | 方法 | 状态 |
|---|
| /v1/x402/search | POST | ❌ 对代理不可用 |
推荐替代方案:
- 1. Firecrawl MCP - 如果环境中可用(使用标准API密钥)
- Browserbase + 抓取脚本 - 纯x402,完全无密钥
- 标准Firecrawl API - 使用订阅/API密钥
参考:Firecrawl x402文档
Mail.tm(临时邮箱)
基础URL: https://api.mail.tm
定价: 免费(无需x402支付)
Mail.tm允许代理创建用于注册的电子邮件地址并接收验证邮件。
| 端点 | 方法 | 认证 | 描述 |
|---|
| /domains | GET | 否 | 获取可用邮箱域名 |
| /accounts |
POST | 否 | 创建邮箱账户 |
| /token | POST | 否 | 获取认证令牌 |
| /messages | GET | 是 | 列出所有消息 |
| /messages/:id | GET | 是 | 获取完整消息内容 |
| /me | GET | 是 | 获取账户信息 |
创建邮箱账户
bash
1. 获取可用域名
DOMAIN=$(curl -s https://api.mail.tm/domains |