@x402apis/node
v1.0.8
Published
Provider node software for x402 API Router
Readme
@x402apis/node
Provider node software for earning money by serving APIs through the x402 network.
Installation
npm install @x402apis/nodeQuick Start
import { createProviderServer } from "@x402apis/node";
const server = createProviderServer({
wallet: "./wallet.json",
port: 9000,
});
// Add your API
server.addAPI(
"openai.chat",
async (params) => {
const response = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify(params),
});
return response.json();
},
{
price: 0.045, // $0.045 per request
},
);
await server.start();Examples
See /examples for ready-to-use templates:
openai.ts- OpenAI GPTdeepgram.ts- Speech-to-textelevenlabs.ts- Text-to-speechcustom-api.ts- Generic template
Configuration
interface ServerConfig {
wallet: string; // Path to wallet keypair
port?: number; // Server port (default: 9000)
publicUrl?: string; // Public URL (for NAT/proxy)
registry?: string; // Registry URL (default: registry.x402apis.io)
chains?: Chain[]; // Supported chains (default: ['solana'])
defaultPrice?: number; // Default price (default: 0.01)
logging?: boolean; // Enable logs (default: true)
}How It Works
- You run a node with your API keys
- Node registers with central registry
- Clients discover your node
- They pay via x402 → you proxy their request → you keep the USDC
License
MIT
