{"slug": "monetize-express-js-apis-for-ai-agents-in-3-lines-of-code-with-x402", "title": "Monetize Express.js APIs for AI Agents in 3 Lines of Code with x402", "summary": "A developer released x402-express, an npm package that lets Express.js developers monetize APIs for AI agents with three lines of code. The middleware returns HTTP 402 Payment Required responses with payment parameters and autonomously verifies settlements on Base.", "body_md": "AI agents are increasingly making programmatic requests, but traditional billing (credit cards, OAuth, complex API keys) creates friction for automated microtransactions.\n\nWith **x402-express**, you can monetize any Express.js endpoint using HTTP 402 payment requirements on Base in 3 lines of code.\n\nbash\n\nnpm install x402-express\n\nAdd the middleware to any route you want to protect:\n\njavascript\n\nconst express = require('express');\n\nconst { x402Middleware } = require('x402-express');\n\nconst app = express();\n\napp.get('/api/agent-data', x402Middleware({ price: '0.01' }), (req, res) => {\n\nres.json({ message: \"Payment verified via x402!\" });\n\n});\n\napp.listen(3000, () => console.log('Server running on port 3000'));\n\n`io.github.ihen404/x402-express`\n\nWhen an unauthenticated agent hits your endpoint, `x402-express`\n\ninterceptively returns an `HTTP 402 Payment Required`\n\npayload containing payment parameters, verifying settlements autonomously.", "url": "https://wpnews.pro/news/monetize-express-js-apis-for-ai-agents-in-3-lines-of-code-with-x402", "canonical_source": "https://dev.to/ihen404/monetize-expressjs-apis-for-ai-agents-in-3-lines-of-code-with-x402-4i0l", "published_at": "2026-08-29 19:15:50+00:00", "updated_at": "2026-08-29 19:49:34.320434+00:00", "lang": "en", "topics": ["developer-tools", "ai-agents", "ai-infrastructure"], "entities": ["x402-express", "Express.js", "Base", "npm"], "alternates": {"html": "https://wpnews.pro/news/monetize-express-js-apis-for-ai-agents-in-3-lines-of-code-with-x402", "markdown": "https://wpnews.pro/news/monetize-express-js-apis-for-ai-agents-in-3-lines-of-code-with-x402.md", "text": "https://wpnews.pro/news/monetize-express-js-apis-for-ai-agents-in-3-lines-of-code-with-x402.txt", "jsonld": "https://wpnews.pro/news/monetize-express-js-apis-for-ai-agents-in-3-lines-of-code-with-x402.jsonld"}}