A demo application that mimics the Cursor text editor interface to showcase Lumen's billing integration capabilities.
-
Three-panel layout mimicking Cursor editor:
- Left: File explorer with e-commerce product catalog files
- Center: Monaco code editor with syntax highlighting
- Right: AI chat assistant for coding help
-
Interactive demos with Lumen billing gates:
- Tab completion (press
TaborCmd/Ctrl + Space) - Gated by feature entitlement - AI chat responses - Gated by usage limits
- Tab completion (press
-
Backend architecture:
- Mock authentication system
- Lumen SDK integration for billing checks
- API routes with proper authorization
- Install dependencies:
npm install- Set up environment variables:
cp .env.example .env
# Add your Lumen API key to .env- Run the development server:
npm run dev- Open http://localhost:3000 in your browser
- Click in the editor
- Press
TaborCmd/Ctrl + Spaceto see a code completion suggestion - The suggestion popup will auto-hide after 3 seconds
Ask the AI assistant coding questions:
- "How do I add search filters?"
- "Show me error handling"
- "How can I optimize performance?"
- "Help me with TypeScript types"
The AI will respond with relevant code examples. Gated by Lumen usage limits.
- Next.js 15 - React framework
- TypeScript - Type safety
- Tailwind CSS - Styling
- Monaco Editor - VS Code editor component
- Lucide React - Icons
- Next.js API Routes - Serverless functions
- Lumen SDK - Billing and usage tracking
- Mock Auth System - Simulates user authentication
- Frontend - User triggers action (tab completion or AI chat)
- Backend API - Receives request from frontend
- Auth Check - Verifies user is logged in (
lib/auth.ts) - Lumen Entitlement Check -
isFeatureEntitled()checks:- Does user's plan include this feature?
- Does user have remaining credits/quota?
- Gate Decision:
- ✅ Allowed - Execute logic → track usage with
sendEvent()→ return result - ❌ Blocked - Return 402 error with upgrade message
- ✅ Allowed - Execute logic → track usage with
- Frontend - Displays result or shows upgrade prompt
app/page.tsx- Main layout with three panelscomponents/FileExplorer.tsx- Left sidebar file treecomponents/CodeEditor.tsx- Code editor (calls/api/completion)components/ChatPanel.tsx- AI chat (calls/api/chat)
lib/auth.ts- Mock authentication systemlib/lumen.ts- Lumen SDK clientapp/api/completion/route.ts- Tab completion API (gated by Lumen)app/api/chat/route.ts- AI chat API (gated by Lumen)
This demo uses the official @getlumen/server package to implement feature gates following the Lumen quickstart guide.
Checks if user has access to a feature (includes both plan access AND remaining credits):
import { isFeatureEntitled } from '@getlumen/server'
const hasAccess = await isFeatureEntitled({
feature: 'ai-completions',
userId: user.id
})
if (!hasAccess) {
// User either doesn't have this feature in their plan
// OR they've exceeded their usage limit
return error('Upgrade or out of credits')
}After successful feature consumption, record the event:
import { sendEvent } from '@getlumen/server'
// Only call this AFTER the feature is actually used
await sendEvent({
name: 'ai-completions',
userId: user.id
})// 1. Check auth
const user = await requireAuth()
// 2. Check entitlement (plan + usage)
if (await isFeatureEntitled({ feature: 'ai-completions', userId: user.id })) {
// 3. Execute feature logic
const result = await generateCompletion()
// 4. Track usage
await sendEvent({ name: 'ai-completions', userId: user.id })
return result
}You can easily customize:
- Mock user data in
lib/auth.ts - Feature names - Change
'ai-completions'and'ai-messages'to match your Lumen dashboard - File structure in
components/FileExplorer.tsx - Sample code in
components/CodeEditor.tsx - AI responses in
app/api/chat/route.ts
- Sign up at getlumen.dev
- Create your features in the Lumen dashboard (e.g.,
ai-completions,ai-messages) - Set up your pricing model and plans
- Get your API key and add it to
.env:LUMEN_API_KEY=lumen_sk_your_key_here - The app will automatically gate features based on your Lumen configuration!