-
Notifications
You must be signed in to change notification settings - Fork 5.4k
feat(server): Add x402 payment middleware to Jobs API #6099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
Claude encountered an error —— View job PR Review for x402 Payment Middleware
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Claude finished @wtfsayo's task —— View job PR Review for x402 Payment Middleware
|
|
Claude finished @wtfsayo's task —— View job PR Review for x402 Payment Middleware
|
- Add x402 payment middleware with configurable authentication modes - Support for both testnet and mainnet via environment variables - Dual authentication: API key + payment, API key only, payment only, or none - Comprehensive test suite with 12 passing tests - Full documentation in docs/x402-payment-integration.md - Auto-discovery support via x402 Bazaar with JSON schemas Authentication modes: 1. Both API key + x402 enabled: Requires BOTH X-API-KEY AND X-PAYMENT 2. Only API key (x402=false): Requires only X-API-KEY 3. Only x402 (no API token): Requires only X-PAYMENT 4. Neither enabled: No authentication required Environment variables: - X402_ENABLED: Enable/disable payment middleware - X402_WALLET_ADDRESS: Receiving wallet address - X402_PRICE: Price in USDC (default: $0.01) - X402_NETWORK: Blockchain network (default: base-sepolia) - X402_USE_MAINNET: Use CDP facilitator for production - CDP_API_KEY_ID/SECRET: Required for mainnet Dependencies added: - [email protected] - @coinbase/[email protected]
Updated the x402 middleware to always allow OPTIONS requests to pass through without authentication or payment validation, supporting CORS preflight scenarios. Added comprehensive tests to ensure OPTIONS requests are permitted regardless of x402 or API key configuration.
333a95b to
6d858bd
Compare
|
Claude finished @wtfsayo's task —— View job PR Review: x402 Payment Middleware
|
|
Claude finished @wtfsayo's task —— View job PR Review: x402 Payment Middleware
|
|
Claude finished @wtfsayo's task —— View job PR Review: x402 Payment Middleware
|
|
Claude finished @wtfsayo's task —— View job PR Review: x402 Payment Middleware
|
|
Claude finished @wtfsayo's task —— View job PR Review: x402 Payment Middleware
|
|
Claude finished @wtfsayo's task —— View job PR Review: x402 Payment Middleware
|
|
Claude finished @wtfsayo's task —— View job PR Review: x402 Payment Middleware
|
|
This is exactly what I'm researching.
Not selling - just gathering feedback from builders Can talk: https://calendly.com/rahmanbazarov4567/30min or via Telegram: @bazarov_rahman or github: JustRahman |
|
Claude finished @wtfsayo's task —— View job PR Review: x402 Payment Middleware
|



Summary
This PR adds x402 payment middleware integration to the Jobs API, enabling cryptocurrency payments for AI agent access.
Key Features
Flexible Authentication Modes
X-API-KEYANDX-PAYMENTheadersX-API-KEYheaderX-PAYMENTheaderEnvironment-Based Configuration
All settings via
.envvariables:X402_ENABLED- Enable/disable payment middlewareX402_WALLET_ADDRESS- Receiving wallet addressX402_PRICE- Price in USDC (default: $0.01)X402_NETWORK- Blockchain network (default: base-sepolia)X402_USE_MAINNET- Use CDP facilitator for productionCDP_API_KEY_ID/CDP_API_KEY_SECRET- Required for mainnetAuto-Discovery
Endpoints automatically listed in x402 Bazaar (mainnet) with:
Files Changed
New Files
packages/server/src/middleware/x402.ts- Main middleware implementationpackages/server/src/middleware/__tests__/x402.test.ts- Comprehensive test suite (12 tests)docs/x402-payment-integration.md- Full documentationModified Files
packages/server/src/middleware/index.ts- Export x402 middlewarepackages/server/src/api/messaging/jobs.ts- Integrated x402 on POST /jobs routepackages/server/package.json- Added x402 dependenciesbun.lock- Lockfile updateDependencies Added
[email protected]- Express middleware for x402 protocol@coinbase/[email protected]- CDP facilitator for mainnetTesting
✅ All 12 unit tests passing
✅ Build successful
✅ No linter errors
✅ TypeScript types validated
Run tests:
Documentation
See
docs/x402-payment-integration.mdfor:Breaking Changes
None - x402 is disabled by default and completely optional.
References
Note
Adds optional x402 crypto payment middleware to the Jobs API with env-based config, dual auth support, discovery metadata, tests, docs, and dependencies.
createX402Middlewareand logging; configurable via env (price, network, wallet, facilitator/mainnet).POST /api/messaging/jobsandGET /api/messaging/jobs/:jobId; keepsGET /api/messaging/jobsadmin-only via API key.middleware/index.ts.x402-payment-integration.md: setup, config, testing, security.jobs-api-deployment-security.md: reverse proxy guidance and exposure controls.@coinbase/x402andx402-express; updates package/lockfile.Written by Cursor Bugbot for commit 132393d. This will update automatically on new commits. Configure here.