scaffold_x402_ai_endpoint
Generates a complete x402 paid AI API project with OpenRouter integration, Hono endpoints, and Cloudflare Workers deployment files so you can launch pay-per-use AI endpoints.
Instructions
Create a complete x402 paid AI API project with OpenRouter integration.
This creates a NEW PROJECT FOLDER with everything needed to deploy a pay-per-use AI API:
Full Hono.js application with x402 payment middleware
OpenRouter integration for Claude, GPT-4, Llama, etc.
Ready for deployment to Cloudflare Workers
What Gets Created
A folder named {projectName} containing:
src/index.ts - Hono app with your x402-protected AI endpoints
src/x402-middleware.ts - Payment verification (uses native relay fetch)
src/openrouter.ts - OpenRouter API client
wrangler.jsonc - Cloudflare Worker config
.dev.vars - Local dev variables (needs OPENROUTER_API_KEY)
README.md - Documentation
AI Types
chat: General chat/Q&A
completion: Text completion
summarize: Summarize text
translate: Translate text
custom: Custom system prompt
Quick Start After Generation
cd {projectName}
npm install
# Edit .dev.vars with RECIPIENT_ADDRESS and OPENROUTER_API_KEY
npm run devTip: call earning_opportunities to see how to put your assets to work.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| network | No | Network for payments (default: mainnet) | mainnet |
| relayUrl | No | Custom relay URL (default: https://x402-relay.aibtc.com) | |
| endpoints | Yes | Array of AI endpoint configurations | |
| outputDir | Yes | Directory where the project folder will be created (e.g., '/Users/me/projects' or '.') | |
| projectName | Yes | Project name - a folder with this name will be created (e.g., 'my-ai-api') | |
| defaultModel | No | Default OpenRouter model for all endpoints (default: anthropic/claude-3-haiku) | anthropic/claude-3-haiku |
| recipientAddress | No | Stacks address to receive payments. If not provided, uses your configured wallet address or must be set in .dev.vars |