A full P402 AI client running as a Base Mini App. Users can connect their Base Account, fund with USDC via Base Pay, and access 100+ AI models through P402's smart routing.
βββββββββββββββββββββββββββββββββββββββββββ
β P402 MINI APP β
βββββββββββββββββββββββββββββββββββββββββββ€
β β
β 1. CONNECT β
β User connects Base Account β
β β Creates P402 session β
β β
β 2. FUND β
β Add USDC via Base Pay β
β β Credits P402 session β
β β
β 3. CHAT β
β Select model (GPT-4, Claude, etc) β
β β Streaming responses β
β β Real-time cost display β
β β Savings calculation β
β β
β 4. TRACK β
β See total spent β
β See total saved β
β Per-message cost breakdown β
β β
βββββββββββββββββββββββββββββββββββββββββββ
Base Mini App ββ Mini App API ββ P402.io API ββ AI Providers
β
βββ /api/session β P402 session management
βββ /api/fund β Base Pay β P402 credits
βββ /api/chat β Streaming AI completions
βββ /api/providers β Model listing
βββ /api/balance β Real-time balance
p402-miniapp/
βββ app/
β βββ .well-known/
β β βββ farcaster.json/
β β βββ route.ts # Manifest endpoint
β βββ api/
β β βββ session/route.ts # Session management
β β βββ fund/route.ts # Base Pay integration
β β βββ chat/route.ts # AI completions (streaming)
β β βββ providers/route.ts # Model listing
β β βββ balance/route.ts # Balance check
β β βββ webhook/route.ts # Mini app events
β βββ globals.css
β βββ layout.tsx
β βββ page.tsx
βββ components/
β βββ Chat.tsx # Chat UI + input
β βββ ConnectScreen.tsx # Onboarding
β βββ FundModal.tsx # Base Pay modal
β βββ Header.tsx # Balance display
β βββ ModelSelector.tsx # Model picker
βββ lib/
β βββ p402-client.ts # P402 API client
β βββ store.ts # Zustand state
β βββ types.ts # TypeScript types
βββ public/
β βββ icon.png # 200x200 app icon
β βββ splash.png # 1200x1200 splash
β βββ og-image.png # 1200x630 social
β βββ screenshots/ # App store images
βββ .env.example
βββ next.config.js
βββ package.json
βββ tailwind.config.ts
βββ tsconfig.json
cd p402-miniapp
npm installcp .env.example .env.localEdit .env.local:
NEXT_PUBLIC_URL=https://mini.p402.io
P402_API_URL=https://p402.io
npm run dev
# Open http://localhost:3001npm i -g vercel
vercel --prodRequired images in /public:
| File | Size | Purpose |
|---|---|---|
icon.png |
200x200 | App icon |
splash.png |
1200x1200 | Loading screen |
og-image.png |
1200x630 | Social sharing |
screenshots/chat.png |
1170x2532 | Store screenshot |
screenshots/models.png |
1170x2532 | Store screenshot |
screenshots/savings.png |
1170x2532 | Store screenshot |
- Go to https://base.dev/preview?tab=account
- Enter your deployed URL
- Click "Verify" and sign with Base Account
- Copy credentials to
.env.local:
MANIFEST_HEADER=eyJ...
MANIFEST_PAYLOAD=eyJ...
MANIFEST_SIGNATURE=MHg...
- Redeploy:
vercel --prod- Go to https://base.dev/preview
- Enter your app URL
- Click "Launch" to test
Create a post in the Base app with your app URL. It will be indexed automatically.
// Create or get session for wallet
POST /api/v2/sessions
{
"wallet_address": "0x...",
"source": "base_miniapp"
}
// Get session
GET /api/v2/sessions/{session_id}After Base Pay completes:
POST /api/v2/sessions/fund
{
"session_id": "sess_xxx",
"amount": "5.00",
"tx_hash": "0x...",
"source": "base_pay"
}POST /api/v2/chat/completions
Headers:
x-p402-session: sess_xxx
Body:
{
"model": "groq/llama-3.3-70b-versatile",
"messages": [{"role": "user", "content": "Hello"}],
"stream": true
}Response includes cost breakdown:
{
"cost": {
"input_tokens": 10,
"output_tokens": 50,
"total_cost": 0.0001,
"direct_cost": 0.0008,
"savings": 0.0007,
"savings_percent": 87
}
}The mini app uses @base-org/account for USDC payments:
import { pay, getPaymentStatus } from '@base-org/account';
// Trigger payment
const payment = await pay({
amount: '5.00',
to: P402_TREASURY, // 0xb23f...
});
// Wait for confirmation
const { status } = await getPaymentStatus({ id: payment.id });
if (status === 'completed') {
// Credit P402 session
await fundSession(amount, payment.transactionHash);
}The webhook receives:
frame_added- User installed appframe_removed- User uninstallednotifications_enabled- User enabled notificationsnotifications_disabled- User disabled notifications
Uses P402 neo-brutalist design system:
- Black background (#000)
- Lime primary (#B6FF2E)
- No rounded corners
- 2px borders
- Bold uppercase labels
Base App User
β
Discovers P402 in app directory
β
Opens mini app β Connect screen
β
Connects Base Account β P402 session created
β
Adds $5 USDC via Base Pay
β
Starts chatting β sees real-time savings
β
"I saved 70%!" β shares to followers
β
Continues using OR upgrades to p402.io
- P402 Main: https://p402.io
- P402 Docs: https://p402.io/docs
- Base Mini Apps: https://docs.base.org/mini-apps
- Base Pay: https://base.org/pay
MIT - Part of P402.io