Skip to content

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

fix: configure x402 facilitator URL from env (#2930)

Abimael Martell0e3ea540fa30
diff --git a/apps/api/package.json b/apps/api/package.json
index b026bdad9..147aed09b 100644
--- a/apps/api/package.json
+++ b/apps/api/package.json
@@ -87,6 +87,7 @@
"@sentry/node": "^10.27.0",
"@supabase/supabase-js": "^2.52.0",
"@types/ws": "^8.5.12",
+ "@x402/core": "^2.4.0",
"@x402/evm": "^2.4.0",
"@x402/express": "^2.4.0",
"ai": "5.0.89",
diff --git a/apps/api/pnpm-lock.yaml b/apps/api/pnpm-lock.yaml
index c17b345d1..511090273 100644
--- a/apps/api/pnpm-lock.yaml
+++ b/apps/api/pnpm-lock.yaml
@@ -74,6 +74,9 @@ importers:
'@types/ws':
specifier: ^8.5.12
version: 8.5.12
+ '@x402/core':
+ specifier: ^2.4.0
+ version: 2.4.0
'@x402/evm':
specifier: ^2.4.0
diff --git a/apps/api/src/config.ts b/apps/api/src/config.ts
index 925d58002..0f1cbc167 100644
--- a/apps/api/src/config.ts
+++ b/apps/api/src/config.ts
@@ -202,6 +202,7 @@ const configSchema = z.object({
X402_ENDPOINT_PRICE_USD: z.string().optional(),
X402_NETWORK: z.string().optional(),
X402_PAY_TO_ADDRESS: ethereumAddress,
+ X402_FACILITATOR_URL: z.string().url().optional(),
// System
MAX_CPU: z.coerce.number().default(0.8),
diff --git a/apps/api/src/lib/x402.ts b/apps/api/src/lib/x402.ts
index f96fcdb7c..18d370bb7 100644
--- a/apps/api/src/lib/x402.ts
+++ b/apps/api/src/lib/x402.ts
@@ -4,6 +4,7 @@ import {
x402ResourceServer as X402ResourceServer,
type Network,
} from "@x402/express";
+import { HTTPFacilitatorClient } from "@x402/core/server";
import { registerExactEvmScheme } from "@x402/evm/exact/server";
// Network name to CAIP-2 chain ID mapping
@@ -27,7 +28,12 @@ let _resourceServer: X402ResourceServer | null = null;
export function getX402ResourceServer(): X402ResourceServer {
if (!_resourceServer) {
- _resourceServer = new X402ResourceServer();
+ const facilitatorUrl =
+ config.X402_FACILITATOR_URL || "https://x402.org/facilitator";
+ const facilitatorClient = new HTTPFacilitatorClient({
+ url: facilitatorUrl,
+ });
+ _resourceServer = new X402ResourceServer(facilitatorClient);
registerExactEvmScheme(_resourceServer, {
networks: [getX402Network()],
});