- Node.js 18+
- MongoDB (local binary or Docker)
- (Optional) Replicate API token for real image generation
- (Optional) Anthropic API key for LLM-powered composition
cd prompt-hero-x402
cp .env.example .env # or use the existing .envKey .env variables:
MONGODB_URI=mongodb://localhost:27017/prompthero
PAY_TO_ADDRESS=0x0000000000000000000000000000000000000001
REPLICATE_API_TOKEN=demo # "demo" → placeholder images
ANTHROPIC_API_KEY=demo # "demo" → fallback composition
PROMPT_STORAGE_URL=http://localhost:4001
PROMPT_BACKEND_URL=http://localhost:4000
AGENT_ENDPOINT=http://localhost:4002
AGENT_API_KEY=demo-agent-key-001
# Option A: Local binary
mongod --dbpath ./mongodb-data --port 27017 --fork --logpath ./mongodb.log
# Option B: Docker
docker run -d --name mongo -p 27017:27017 mongo:7cd prompt-storage && npm install && cd ..
cd prompt-backend && npm install && cd ..
cd external-agent && npm install && cd ..
cd validation-agent && npm install && cd ..Open 3 terminals (or use & for background):
# Terminal 1 — Prompt Storage (port 4001)
cd prompt-storage && npx tsx src/server.ts
# Terminal 2 — External Agent (port 4002)
cd external-agent && npx tsx src/server.ts
# Terminal 3 — Prompt Backend (port 4000)
cd prompt-backend && npx tsx src/server.tscd prompt-storage && npx tsx src/seed.tsThis inserts 20 sample prompt recipes (cinematic, anime, portrait, etc.).
curl -X POST http://localhost:4000/api/agents/register \
-H "Content-Type: application/json" \
-d '{
"name": "CinematicComposer",
"endpoint": "http://localhost:4002",
"categories": ["cinematic", "photorealistic", "portrait"],
"compositionFee": 0.01,
"paymentWallet": "0x0000000000000000000000000000000000000002",
"model": "flux",
"description": "Cinematic prompt composition agent"
}'curl -X POST http://localhost:4000/api/generate \
-H "Content-Type: application/json" \
-d '{"prompt": "a cat in rainy Tokyo at night"}'
# → 402 Payment Required with USDC payment infocurl -X POST http://localhost:4000/api/generate \
-H "Content-Type: application/json" \
-H "X-Payment: demo" \
-d '{"prompt": "a cat in rainy Tokyo at night"}'Response includes:
imageUrl— generated image (placeholder if no Replicate token)finalPrompt— LLM-composed prompt using recipe referencescompositionAgent— which agent was selectedpromptRefs— creator attribution with reward amountssettlement— fee breakdown (Agent 20%, Creators 50%, Platform 30%)
curl -X POST http://localhost:4000/api/feedback \
-H "Content-Type: application/json" \
-d '{
"generationId": "test-001",
"agentId": "<agentId from response>",
"score": 9,
"tags": ["creative", "accurate"]
}'curl http://localhost:4000/api/agentsThe validation agent runs 25 automated checks across all services:
cd validation-agent && npx tsx src/validate.tsTests cover:
- Health — all 3 servers are up
- Storage — recipe CRUD, search, deduplication
- Backend — 402 flow, agent routing, feedback
- Agent — compose with auth, rejection without auth
- E2E — full generate flow, settlement math, prompt diversity
- Integrity — SHA-256 hashes, wallet addresses, fee constants
| Endpoint | Method | Description |
|---|---|---|
localhost:4000/api/generate |
POST | Generate image (x402 payment) |
localhost:4000/api/agents |
GET | List registered agents |
localhost:4000/api/agents/register |
POST | Register new agent |
localhost:4000/api/feedback |
POST | Submit quality feedback |
localhost:4001/api/recipes |
GET | List all recipes (metadata) |
localhost:4001/api/recipes/search?q=cinematic |
GET | Search recipes (full content) |
localhost:4001/api/recipes/register |
POST | Register new recipe |
localhost:4002/api/compose |
POST | Compose prompt (needs auth) |
localhost:4002/health |
GET | Agent health check |
To generate actual images instead of placeholders, set a real Replicate API token:
REPLICATE_API_TOKEN=r8_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxGet a token at https://replicate.com/account/api-tokens
Consumer Agent ──(x402 $0.05)──▶ Prompt Backend ──(x402 $0.01)──▶ External Agent
│ │
│ ▼
│ Prompt Storage
│ (recipe DB)
▼
Replicate FLUX
(image generation)
Fee split per generation ($0.05 total):
- Agent: $0.010 (20%)
- Creators: $0.025 (50%)
- Platform: $0.015 (30%)