vibepanel-sdk
v0.1.0
Published
Track AI costs, feature usage, and per-user profitability
Maintainers
Readme
vibepanel-sdk
Track AI costs, feature usage, and per-user profitability from inside your app.
VibePanel tells you which users are profitable, which features cost money, and who's burning your AI budget — data that Stripe and OpenAI can't give you alone.
Install
npm install vibepanel-sdkQuick start
import { VibePanel } from 'vibepanel-sdk'
const vp = new VibePanel({
writeKey: process.env.VIBEPANEL_WRITE_KEY,
})
// After any AI call — fire and forget, no await needed
vp.ai({
userId: req.user.id,
model: 'gpt-4o',
inputTokens: response.usage.prompt_tokens,
outputTokens: response.usage.completion_tokens,
feature: 'chat',
})What you can track
AI calls
vp.ai({
userId: 'user_123',
model: 'gpt-4o',
inputTokens: 1200,
outputTokens: 340,
feature: 'essay_generator',
latencyMs: 1842,
metadata: { prompt_version: 'v2' },
})User identification
vp.identify({
userId: 'user_123',
plan: 'pro',
monthlyRevenue: 49.00,
email: '[email protected]',
})Feature usage
vp.feature({
userId: 'user_123',
feature: 'pdf_summarizer',
action: 'run',
})Generic events
vp.event({
userId: 'user_123',
name: 'export_completed',
metadata: { format: 'pdf', pages: 24 },
})How it works
- Events queue in memory and flush every 2 seconds (configurable)
- Failed sends retry 3 times, then drop silently — never crashes your app
- Zero runtime dependencies
- Costs are calculated server-side — the SDK just sends model + token counts
Configuration
const vp = new VibePanel({
writeKey: process.env.VIBEPANEL_WRITE_KEY, // required
flushInterval: 2000, // ms between flushes (default: 2000)
maxBatchSize: 50, // events per batch (default: 50)
debug: false, // log to console (default: false)
})Serverless (Next.js, Vercel, Lambda)
In serverless environments, flush before the function exits:
export async function POST(req: Request) {
const response = await openai.chat.completions.create({ ... })
vp.ai({ userId, model, inputTokens, outputTokens })
await vp.flush()
return Response.json({ result: response })
}Graceful shutdown
process.on('SIGTERM', async () => {
await vp.shutdown()
process.exit(0)
})Requirements
- Node.js 18+ (uses native
fetch) - Server-side only — never expose the write key in client code
Get your write key
- Sign up at vibepanel.app
- Create a project
- Go to Settings → SDK tab
- Click Generate Write Key
Docs
Full documentation at docs.vibepanel.app
License
MIT
