Claude
Skills
Sign in
Back

x402

Included with Lifetime
$97 forever

x402 paid API endpoints, inbox messaging, project scaffolding, and OpenRouter AI integration. Execute and probe x402-enabled endpoints from multiple sources, send inbox messages with sponsored sBTC transactions, scaffold new x402 Cloudflare Worker projects, and explore OpenRouter model options.

Ads & Marketing

What this skill does


# x402 Skill

Provides tools for interacting with x402 paid API endpoints, sending inbox messages, scaffolding new x402 API projects, and exploring OpenRouter AI models. Payment flows are handled automatically using the configured wallet.

## Usage

```
bun run x402/x402.ts <subcommand> [options]
```

## Subcommands

### list-endpoints

List known x402 API endpoint sources with descriptions and usage examples.

```
bun run x402/x402.ts list-endpoints
```

Output:
```json
{
  "network": "mainnet",
  "defaultApiUrl": "https://x402.biwas.xyz",
  "sources": [
    {
      "name": "x402.biwas.xyz",
      "url": "https://x402.biwas.xyz",
      "description": "DeFi analytics, market data, wallet analysis, Zest/ALEX protocols",
      "categories": ["defi", "market", "wallet", "analytics"],
      "example": { "path": "/api/pools/trending", "method": "GET" }
    }
  ],
  "usage": { "probe": "...", "execute": "..." }
}
```

### probe-endpoint

Probe an x402 API endpoint to discover its cost WITHOUT making payment.

```
bun run x402/x402.ts probe-endpoint --method GET --path /api/pools/trending
bun run x402/x402.ts probe-endpoint --method GET --url https://stx402.com/ai/dad-joke
bun run x402/x402.ts probe-endpoint --method POST --url https://x402.aibtc.com/inference/openrouter/chat --data '{"messages":[{"role":"user","content":"hello"}]}'
```

Options:
- `--method` (optional) — HTTP method (default: GET)
- `--url` (optional) — Full endpoint URL. Takes precedence over `--path`.
- `--path` (optional) — API endpoint path. Required if `--url` not provided.
- `--api-url` (optional) — API base URL (default: configured API_URL)
- `--params` (optional) — Query parameters as JSON object
- `--data` (optional) — Request body for POST/PUT as JSON object

Output (free endpoint):
```json
{
  "type": "free",
  "endpoint": "GET https://x402.biwas.xyz/api/public",
  "message": "This endpoint is free (no payment required)",
  "response": { ... }
}
```

Output (paid endpoint):
```json
{
  "type": "payment_required",
  "endpoint": "GET https://x402.biwas.xyz/api/pools/trending",
  "message": "This endpoint costs 0.001 STX. Use execute-endpoint --auto-approve to pay and execute.",
  "payment": {
    "amount": "1000",
    "asset": "STX",
    "recipient": "SP...",
    "network": "mainnet"
  }
}
```

### execute-endpoint

Execute an x402 API endpoint. By default probes first and shows cost for paid endpoints. Use `--auto-approve` to pay immediately.

```
bun run x402/x402.ts execute-endpoint --method GET --path /api/pools/trending --auto-approve
bun run x402/x402.ts execute-endpoint --method GET --url https://stx402.com/ai/dad-joke --auto-approve
bun run x402/x402.ts execute-endpoint --method POST --url https://x402.aibtc.com/inference/openrouter/chat --data '{"messages":[{"role":"user","content":"hello"}]}' --auto-approve
```

Options:
- `--method` (optional) — HTTP method (default: GET)
- `--url` (optional) — Full endpoint URL. Takes precedence over `--path`.
- `--path` (optional) — API endpoint path. Required if `--url` not provided.
- `--api-url` (optional) — API base URL (default: configured API_URL)
- `--params` (optional) — Query parameters as JSON object
- `--data` (optional) — Request body for POST/PUT as JSON object
- `--auto-approve` (flag) — Skip cost probe and execute immediately, paying if required

Output:
```json
{
  "endpoint": "GET https://x402.biwas.xyz/api/pools/trending",
  "response": { ... },
  "payment": {
    "status": "queued",
    "terminalReason": null,
    "action": "poll",
    "guidance": "Payment is still in flight. Keep polling this paymentId and do not rebuild or re-sign.",
    "paymentId": "relay_pay_123",
    "checkUrl": "https://relay.example/rpc/payment-check/relay_pay_123",
    "txid": null
  }
}
```

Notes:
- `payment` is only included when canonical payment metadata is actually known.
- The client-side `payment-identifier` extension is an idempotency key for relay dedup, not caller-facing canonical `paymentId`.

### send-inbox-message

Send a paid x402 message to another agent's inbox on aibtc.com. Uses sponsored transactions (no STX gas fees). Requires an unlocked wallet with sBTC balance.

```
bun run x402/x402.ts send-inbox-message \
  --recipient-btc-address bc1q... \
  --recipient-stx-address SP... \
  --content "Hello from the agent!"
```

Options:
- `--recipient-btc-address` (required) — Recipient's Bitcoin address (bc1...)
- `--recipient-stx-address` (required) — Recipient's Stacks address (SP...)
- `--content` (required) — Message content (max 500 characters)

Output:
```json
{
  "success": false,
  "message": "Payment is still in flight. Keep polling the same paymentId; do not rebuild or re-sign.",
  "recipient": { "btcAddress": "bc1q...", "stxAddress": "SP..." },
  "contentLength": 22,
  "inbox": { ... },
  "payment": {
    "amount": "1000 sats sBTC",
    "status": "queued",
    "terminalReason": null,
    "action": "poll",
    "paymentId": "pay_123",
    "checkUrl": "https://aibtc.com/rpc/payment-check/pay_123",
    "txid": null
  }
}
```

Notes:
- Caller-facing payment states collapse legacy `submitted` to `queued`.
- `send-inbox-message` reports caller-facing `success: true` only after confirmed delivery. Internally, the retry helper's `success` flag only means the workflow completed without throwing; `messageDelivered` is the delivery confirmation bit.
- When payment is still in flight, keep polling the same `payment.paymentId`. Use `payment.checkUrl` only when the server returns a canonical hint; do not assume every x402 endpoint exposes a local `/api/payment-status/:paymentId` route. `x402-api` remains an immediate pay-per-call exception and does not create a generic local polling contract.
- `terminalReason` is the normalized terminal signal when a payment reaches a terminal state.

### scaffold-endpoint

Create a complete x402 paid API project as a Cloudflare Worker. Generates a new project folder with Hono.js app, x402 payment middleware, wrangler.jsonc config, and README.

```
bun run x402/x402.ts scaffold-endpoint \
  --output-dir /path/to/projects \
  --project-name my-x402-api \
  --endpoints '[{"path":"/api/data","method":"GET","description":"Get premium data","amount":"0.001","tokenType":"STX"}]'
```

Options:
- `--output-dir` (required) — Directory where the project folder will be created
- `--project-name` (required) — Project name (lowercase with hyphens)
- `--endpoints` (required) — JSON array of endpoint configs
- `--recipient-address` (optional) — Stacks address to receive payments (uses active wallet if omitted)
- `--network` (optional) — Network for payments (default: mainnet)
- `--relay-url` (optional) — Custom relay URL (default: https://x402-relay.aibtc.com)

Endpoint config fields:
- `path` — Endpoint path (e.g., `/api/data`)
- `method` — HTTP method (GET or POST)
- `description` — Endpoint description
- `amount` — Payment amount (e.g., `"0.001"`)
- `tokenType` — Payment token (STX, sBTC, or USDCx)
- `tier` (optional) — Pricing tier: simple, standard, ai, heavy_ai, storage_read, storage_write

### scaffold-ai-endpoint

Create a complete x402 paid AI API project with OpenRouter integration as a Cloudflare Worker.

```
bun run x402/x402.ts scaffold-ai-endpoint \
  --output-dir /path/to/projects \
  --project-name my-ai-api \
  --endpoints '[{"path":"/api/chat","description":"AI chat","amount":"0.003","tokenType":"STX","aiType":"chat"}]'
```

Options:
- `--output-dir` (required) — Directory where the project folder will be created
- `--project-name` (required) — Project name (lowercase with hyphens)
- `--endpoints` (required) — JSON array of AI endpoint configs
- `--recipient-address` (optional) — Stacks address to receive payments (uses active wallet if omitted)
- `--network` (optional) — Network for payments (default: mainnet)
- `--relay-url` (optional) — Custom relay URL
- `--default-model` (optional) — Default OpenRouter model (default: anthropic/claude-3-haiku)

AI Endpoint config fields:
- `path`, `descr
Files: 3
Size: 50.3 KB
Complexity: 42/100
Category: Ads & Marketing

Related in Ads & Marketing