Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions typescript/.changeset/loud-jars-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@coinbase/agentkit": minor
---

Added a new action provider to call x402 protected api
13 changes: 13 additions & 0 deletions typescript/agentkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,19 @@ const agent = createReactAgent({
</table>
</details>
<details>
<summary><strong>X402</strong></summary>
<table width="100%">
<tr>
<td width="200"><code>paid_request</code></td>
<td width="768">Makes HTTP requests to x402-protected API endpoints with automatic payment handling.</td>
</tr>
<tr>
<td width="200"><code>fetch_payment_info</code></td>
<td width="768">Fetches payment information from x402-protected endpoints without making payments.</td>
</tr>
</table>
</details>
<details>
<summary><strong>ZeroDev Wallet</strong></summary>
<table width="100%">
<tr>
Expand Down
8 changes: 5 additions & 3 deletions typescript/agentkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,20 @@
"@privy-io/server-auth": "1.18.4",
"@solana/spl-token": "^0.4.12",
"@solana/web3.js": "^1.98.1",
"@zerodev/ecdsa-validator": "^5.4.5",
"@zerodev/intent": "^0.0.24",
"@zerodev/sdk": "^5.4.28",
"axios": "^1.9.0",
"bs58": "^4.0.1",
"canonicalize": "^2.1.0",
"decimal.js": "^10.5.0",
"ethers": "^6.13.5",
"@zerodev/ecdsa-validator": "^5.4.5",
"@zerodev/intent": "^0.0.24",
"@zerodev/sdk": "^5.4.28",
"md5": "^2.3.0",
"opensea-js": "^7.1.18",
"reflect-metadata": "^0.2.2",
"twitter-api-v2": "^1.18.2",
"viem": "^2.22.16",
"x402-axios": "^0.3.3",
"zod": "^3.23.8"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions typescript/agentkit/src/action-providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ export * from "./allora";
export * from "./flaunch";
export * from "./onramp";
export * from "./vaultsfyi";
export * from "./x402";
export * from "./zerodev";
70 changes: 70 additions & 0 deletions typescript/agentkit/src/action-providers/x402/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# X402 Action Provider

This directory contains the **X402ActionProvider** implementation, which provides actions to interact with **x402-protected APIs** that require payment to access.

## Directory Structure

```
x402/
├── x402ActionProvider.ts # Main provider with x402 payment functionality
├── schemas.ts # x402 action schemas
├── index.ts # Main exports
└── README.md # This file
```

## Actions

- `paid_request`: Make HTTP requests to x402-protected API endpoints with automatic payment handling
- `fetch_payment_info`: Get payment information from x402-protected endpoints without making payments

## Overview

The x402 protocol enables APIs to require micropayments for access. When a client makes a request to a protected endpoint, the server responds with a `402 Payment Required` status code along with payment instructions. This action provider automatically handles the entire payment flow:

1. Makes the initial request to the protected API
2. If a 402 response is received, automatically processes the payment using the wallet
3. Retries the request with payment proof
4. Returns the API response data

## Usage

### `paid_request` Action

The `paid_request` action accepts the following parameters:

- **url**: The full URL of the x402-protected API endpoint
- **method**: HTTP method (GET, POST, PUT, DELETE, PATCH) - defaults to GET
- **headers**: Optional additional headers to include in the request
- **body**: Optional request body for POST/PUT/PATCH requests

### `fetch_payment_info` Action

The `fetch_payment_info` action accepts the following parameters:

- **url**: The full URL of the x402-protected API endpoint
- **method**: HTTP method (GET, POST, PUT, DELETE, PATCH) - defaults to GET
- **headers**: Optional additional headers to include in the request

This action is useful for:
- Checking payment requirements before committing to a paid request
- Understanding the cost structure of an API
- Getting details about accepted payment tokens and amounts
- Debugging x402 payment configurations

## Network Support

The x402 provider currently supports the following networks:
- `base-mainnet`
- `base-sepolia`

The provider requires EVM-compatible networks where the wallet can sign payment transactions.

## Dependencies

This action provider requires:
- `axios` - For making HTTP requests
- `x402-axios` - For handling x402 payment flows

## Notes

For more information on the **x402 protocol**, visit the [x402 documentation](https://x402.gitbook.io/x402/).
1 change: 1 addition & 0 deletions typescript/agentkit/src/action-providers/x402/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./x402ActionProvider";
26 changes: 26 additions & 0 deletions typescript/agentkit/src/action-providers/x402/schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { z } from "zod";

export const PaidRequestSchema = z
.object({
url: z.string().url().describe("The URL of the x402-protected API endpoint"),
method: z
.enum(["GET", "POST", "PUT", "DELETE", "PATCH"])
.default("GET")
.describe("The HTTP method to use for the request"),
headers: z.record(z.string()).optional().describe("Optional headers to include in the request"),
body: z.any().optional().describe("Optional request body for POST/PUT/PATCH requests"),
})
.strip()
.describe("Instructions for making a paid request to an x402-protected API");

export const FetchPaymentInfoSchema = z
.object({
url: z.string().url().describe("The URL of the x402-protected API endpoint"),
method: z
.enum(["GET", "POST", "PUT", "DELETE", "PATCH"])
.default("GET")
.describe("The HTTP method to use for the request"),
headers: z.record(z.string()).optional().describe("Optional headers to include in the request"),
})
.strip()
.describe("Instructions for fetching payment information from an x402-protected API endpoint");
Loading
Loading