Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

refactor: integrate facilitator in payment middleware

Ademílson Tonatod6cebd59d674
diff --git a/apps/api/package.json b/apps/api/package.json
index 95c0f22e2..d30c8e257 100644
--- a/apps/api/package.json
+++ b/apps/api/package.json
@@ -71,6 +71,7 @@
"@apidevtools/json-schema-ref-parser": "^11.7.3",
"@bull-board/api": "^6.11.2",
"@bull-board/express": "^6.11.2",
+ "@coinbase/x402": "^0.6.4",
"@dqbd/tiktoken": "^1.0.22",
"@google-cloud/storage": "^7.16.0",
"@mendable/firecrawl-rs": "workspace:*",
diff --git a/apps/api/pnpm-lock.yaml b/apps/api/pnpm-lock.yaml
index c10b5de23..57f2795d8 100644
--- a/apps/api/pnpm-lock.yaml
+++ b/apps/api/pnpm-lock.yaml
@@ -42,6 +42,9 @@ importers:
'@bull-board/express':
specifier: ^6.11.2
version: 6.11.2
+ '@coinbase/x402':
+ specifier: ^0.6.4
'@dqbd/tiktoken':
specifier: ^1.0.22
version: 1.0.22
@@ -720,6 +723,9 @@ packages:
'@coinbase/[email protected]':
resolution: {integrity: sha512-4q8BNG1ViL4mSAAvPAtpwlOs1gpC+67eQtgIwNvT3xyeyFFd+guwkc8bcX5rTmQhXpqnhzC4f0obACbP9CqMSA==}
+ '@coinbase/[email protected]':
+ resolution: {integrity: sha512-T0tNU8/oZ64GaKC3dbGcOFHqYO0BjII/uZeC/tAS9HOqhWBvewhoa0rzPzaE8SHeKOIwX2YpbFXdG0Hyh0d4mw==}
+
'@colors/[email protected]':
resolution: {integrity: sha512-Ir+AOibqzrIsL6ajt3Rz3LskB7OiMVHqltZmspbW/TJuTVuyOMirVqAkjfY6JISiLHgyNqicAC8AyHHGzNd/dA==}
engines: {node: '>=0.1.90'}
@@ -6837,6 +6843,9 @@ packages:
resolution: {integrity: sha512-3FmcS/cwPQX9Kbf2pqoeF+iVgu5kDfNwz8wTSS/++cAwMAqpEgOaJ7jXMBYiEK4GXIqZEY6dSosZz/WzK5N6pw==}
+ resolution: {integrity: sha512-9UmeCSsYzFGav5FdVP70VplKlR3V90P0DZ9fPSrlLVp0ifUVi1S9TztvegkmIHE9xTGZ1GWNi+bkne6N0Ea58w==}
+
resolution: {integrity: sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==}
engines: {node: '>=18'}
@@ -7470,6 +7479,46 @@ snapshots:
- utf-8-validate
- zod
+ dependencies:
+ zod: 3.25.76
+ transitivePeerDependencies:
+ - '@azure/app-configuration'
+ - '@azure/cosmos'
+ - '@azure/data-tables'
+ - '@azure/identity'
+ - '@azure/keyvault-secrets'
+ - '@azure/storage-blob'
+ - '@capacitor/preferences'
+ - '@deno/kv'
+ - '@netlify/blobs'
+ - '@planetscale/database'
+ - '@react-native-async-storage/async-storage'
+ - '@solana/sysvars'
+ - '@tanstack/query-core'
+ - '@tanstack/react-query'
+ - '@types/react'
+ - '@upstash/redis'
+ - '@vercel/blob'
+ - '@vercel/kv'
+ - aws4fetch
+ - bufferutil
+ - db0
+ - debug
+ - encoding
+ - fastestsmallesttextencoderdecoder
+ - immer
+ - ioredis
+ - react
+ - supports-color
+ - typescript
+ - uploadthing
+ - utf-8-validate
+ - ws
+
'@colors/[email protected]': {}
'@cspotcode/[email protected]':
@@ -10804,17 +10853,17 @@ snapshots:
dependencies:
'@types/yargs-parser': 21.0.3
dependencies:
'@safe-global/safe-apps-provider': 0.18.6([email protected])([email protected])([email protected])([email protected])
cbw-sdk: '@coinbase/[email protected]'
optionalDependencies:
typescript: 5.8.3
transitivePeerDependencies:
@@ -10846,11 +10895,11 @@ snapshots:
- utf-8-validate
- zod
dependencies:
eventemitter3: 5.0.1
mipd: 0.0.7([email protected])
optionalDependencies:
'@tanstack/query-core': 5.83.1
@@ -11398,11 +11447,6 @@ snapshots:
typescript: 5.8.3
zod: 3.22.4
- optionalDependencies:
- typescript: 5.8.3
- zod: 3.24.2
-
optionalDependencies:
typescript: 5.8.3
@@ -13824,21 +13868,6 @@ snapshots:
transitivePeerDependencies:
- zod
- dependencies:
- '@adraffy/ens-normalize': 1.11.0
- '@noble/ciphers': 1.3.0
- '@noble/curves': 1.9.6
- '@noble/hashes': 1.8.0
- '@scure/bip32': 1.7.0
- '@scure/bip39': 1.6.0
- eventemitter3: 5.0.1
- optionalDependencies:
- typescript: 5.8.3
- transitivePeerDependencies:
- - zod
-
dependencies:
'@adraffy/ens-normalize': 1.11.0
@@ -14966,23 +14995,6 @@ snapshots:
- utf-8-validate
- zod
- dependencies:
- '@noble/curves': 1.9.2
- '@noble/hashes': 1.8.0
- '@scure/bip32': 1.7.0
- '@scure/bip39': 1.6.0
- optionalDependencies:
- typescript: 5.8.3
- transitivePeerDependencies:
- - bufferutil
- - utf-8-validate
- - zod
-
dependencies:
'@noble/curves': 1.9.2
@@ -15004,14 +15016,14 @@ snapshots:
dependencies:
xml-name-validator: 5.0.0
dependencies:
'@tanstack/react-query': 5.84.1([email protected])
react: 18.3.1
use-sync-external-store: 1.4.0([email protected])
optionalDependencies:
typescript: 5.8.3
transitivePeerDependencies:
@@ -15216,8 +15228,52 @@ snapshots:
+ zod: 3.25.76
+ transitivePeerDependencies:
+ - '@azure/app-configuration'
+ - '@azure/cosmos'
+ - '@azure/data-tables'
+ - '@azure/identity'
+ - '@azure/keyvault-secrets'
+ - '@azure/storage-blob'
+ - '@capacitor/preferences'
+ - '@deno/kv'
+ - '@netlify/blobs'
+ - '@planetscale/database'
+ - '@react-native-async-storage/async-storage'
+ - '@solana/sysvars'
+ - '@tanstack/query-core'
+ - '@tanstack/react-query'
+ - '@types/react'
+ - '@upstash/redis'
+ - '@vercel/blob'
+ - '@vercel/kv'
+ - aws4fetch
+ - bufferutil
+ - db0
+ - encoding
+ - fastestsmallesttextencoderdecoder
+ - immer
+ - ioredis
+ - react
+ - supports-color
+ - typescript
+ - uploadthing
+ - utf-8-validate
+ - ws
+
+ dependencies:
+ '@scure/base': 1.2.6
zod: 3.25.76
transitivePeerDependencies:
- '@azure/app-configuration'
diff --git a/apps/api/src/routes/v1.ts b/apps/api/src/routes/v1.ts
index 3551d2879..502787928 100644
--- a/apps/api/src/routes/v1.ts
+++ b/apps/api/src/routes/v1.ts
@@ -36,6 +36,7 @@ import { paymentMiddleware } from "x402-express";
import { queueStatusController } from "../controllers/v1/queue-status";
import { creditUsageHistoricalController } from "../controllers/v1/credit-usage-historical";
import { tokenUsageHistoricalController } from "../controllers/v1/token-usage-historical";
+import { facilitator } from "@coinbase/x402";
expressWs(express());
@@ -45,8 +46,10 @@ export const v1Router = express.Router();
// This middleware handles payment verification and processing for premium API features
// x402 payments protocol - https://github.com/coinbase/x402
v1Router.use(
- paymentMiddleware( (process.env.X402_PAY_TO_ADDRESS as `0x${string}`) ||
- "0x0000000000000000000000000000000000000000", {
+ paymentMiddleware(
+ (process.env.X402_PAY_TO_ADDRESS as `0x${string}`) ||
+ "0x0000000000000000000000000000000000000000",
+ {
"POST /x402/search": {
price: process.env.X402_ENDPOINT_PRICE_USD as string,
network: process.env.X402_NETWORK as
@@ -66,19 +69,19 @@ v1Router.use(
query: {
type: "string",
description: "Search query to find relevant web pages",
- required: true
+ required: true,
},
limit: {
type: "number",
description: "Maximum number of results to return (max 10)",
- required: false
+ required: false,
},
scrapeOptions: {
type: "object",
description: "Options for scraping the found pages",
- required: false
- }
- }
+ required: false,
+ },
+ },
},
outputSchema: {
type: "object",
@@ -92,15 +95,16 @@ v1Router.use(
url: { type: "string" },
title: { type: "string" },
description: { type: "string" },
- markdown: { type: "string" }
- }
- }
- }
- }
- }
+ markdown: { type: "string" },
+ },
+ },
+ },
+ },
+ },
},
},
},
+ facilitator,
),
);