# ethergrid EtherGrid Sovereign Factory V4 — a privacy-first AI inference layer on Cloudflare Pages (D1 + KV + AI). ## Endpoints - GET / — landing page - GET /dashboard.html — user inference dashboard - POST /api/inference — KV-cached AI inference (EtherGrid native JSON) - POST /v1/chat/completions — OpenAI-compatible chat completions (JSON + SSE streaming) - POST /api/keys — create an API key for a user - GET /api/balance?user_id= — user balance & free quota - POST /api/paypal/create-order — create PayPal order (AWAITING_OWNER_APPROVAL) - POST /api/paypal/webhook — PayPal webhook (verifies payment, issues HMAC-signed WhatsApp approval link) - GET /api/paypal/verify — PayPal return/cancel redirect - GET /api/admin/kpi — live KPI cards - GET /api/admin/orders — PayPal orders with 1-click owner approval - GET /api/admin/logs — last 15 system movements - POST /api/admin/approve — owner approves order + credits balance - POST /api/admin/credentials — set PayPal client_id/secret/admin_token in KV ## Authentication - User routes: `Authorization: Bearer ` or `x-api-key` header / `api_key` body field - Admin routes: `x-admin-token` header (default `ethergrid-admin`, settable in KV `config:admin_token`) ## Rules (constitution) - Free tier: 500 requests/day on KV Cache + env.AI at $0.00 - Paid tier: D1 balance pre-check (balance >= cost * 1.25), +25% net margin - PayPal payments never auto-credit; owner 1-click WhatsApp approval required