vibezcheck 0.5.10 → 0.5.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,167 +1,348 @@
1
1
  # ✦ VibezCheck
2
2
 
3
- > **Track AI token spend, protect agent loops, and bill users in real time. Setup in 1 line.**
4
- > Zero external dependencies (`dependencies: {}`). 0ms added latency. Works completely offline.
3
+ Know what every AI request costs.
4
+ The cost layer for AI applications.
5
5
 
6
- [![npm version](https://img.shields.io/npm/v/vibezcheck.svg?color=cb3837)](https://npmjs.org/package/vibezcheck)
7
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
8
- [![TypeScript](https://img.shields.io/badge/TypeScript-Strict-blue.svg)](https://www.typescriptlang.org/)
9
- [![Tests](https://img.shields.io/badge/Tests-139%20Passed-brightgreen.svg)]()
10
- [![Latency](https://img.shields.io/badge/Latency-0ms%20Added-orange.svg)]()
11
- [![Dependencies](https://img.shields.io/badge/Dependencies-0%20External-success.svg)]()
6
+ VibezCheck measures AI usage in real dollars — per request, customer, feature, model, or agent session.
7
+
8
+ ```text
9
+ AI request → tokens → provider cost → customer economics
10
+ ```
11
+
12
+ ```bash
13
+ npm install vibezcheck
14
+ ```
12
15
 
13
16
  ---
14
17
 
15
- ## ⚡ The 1-Line Setup
18
+ ## Why VibezCheck?
16
19
 
17
- **1. On your server:** wrap any model to track spending, add profit margin, and set safety fuses:
18
- ```typescript
19
- import { openai } from '@ai-sdk/openai';
20
- import { vibezcheck } from 'vibezcheck';
20
+ Tokens are useful for engineers.
21
+ Dollars are useful for businesses.
21
22
 
22
- const model = vibezcheck(openai('gpt-4o-mini'), {
23
- customer: 'usr_123',
24
- pricing: { margin: 1.3 }, // +30% profit margin
25
- maxCostPerCallUSD: 0.50, // Auto-stops runaway calls at $0.50
26
- });
27
- ```
23
+ AI providers bill you in tokens.
28
24
 
29
- **2. On your frontend:** drop in the HUD component to display real-time usage:
30
- ```tsx
31
- import { VibezCheck } from 'vibezcheck/ui';
25
+ Your users buy:
26
+ - messages
27
+ - documents
28
+ - agent runs
29
+ - API calls
30
+ - credits
31
+ - subscriptions
32
32
 
33
- <VibezCheck messages={messages} />
33
+ VibezCheck connects the two.
34
+
35
+ ```text
36
+ What your user does
37
+ ↓
38
+ AI usage
39
+ ↓
40
+ Provider cost
41
+ ↓
42
+ Customer economics
34
43
  ```
35
44
 
45
+ Without a metering layer, you know what your users are doing — but not necessarily what each action costs you.
46
+
36
47
  ---
37
48
 
38
- ## 📦 Features & Simplest Usage Examples
49
+ ## ⚡ Quick Start
50
+
51
+ ### Vercel AI SDK
52
+
53
+ Wrap an existing model:
39
54
 
40
- ### 1. 1-Line Model Metering (Vercel AI SDK)
41
- Wrap existing provider models or use declarative string model identifiers with 0ms added latency:
42
55
  ```typescript
43
- import { generateText, streamText } from 'ai';
56
+ import { streamText } from 'ai';
44
57
  import { openai } from '@ai-sdk/openai';
45
58
  import { vibezcheck } from 'vibezcheck';
46
59
 
47
- // Option A: Wrap an existing provider instance
48
60
  const result = streamText({
49
- model: vibezcheck(openai('gpt-4o-mini')),
50
- prompt: 'Summarize quantum computing in 3 sentences.',
51
- });
52
-
53
- // Option B: Declarative string model identifier
54
- const { text } = await generateText({
55
- model: vibezcheck('openai/gpt-4o-mini'),
56
- prompt: 'Explain general relativity.',
61
+ model: vibezcheck(openai('gpt-4o-mini'), {
62
+ customer: 'user_123',
63
+ maxCostPerCallUSD: 0.50,
64
+ }),
65
+ prompt: 'Summarize quantum computing in three sentences.',
57
66
  });
58
67
  ```
59
68
 
69
+ That's it.
70
+
71
+ VibezCheck can now calculate the request's usage and provider cost while the request runs.
72
+
73
+ **Example:**
74
+ > `✦ $0.0028 · 1,420 tok · gpt-4o-mini`
75
+
76
+ - No VibezCheck proxy.
77
+ - No required database.
78
+ - No required cloud account.
79
+
60
80
  ---
61
81
 
62
- ### 2. Customer Identification & Session Metadata
63
- Attach user IDs, agent threads, and custom billing tags without extra database lookups:
82
+ ## 💰 Measure
83
+
84
+ VibezCheck gives your application an economic view of AI usage.
85
+
86
+ ### Request cost
87
+
64
88
  ```typescript
65
- const model = vibezcheck(openai('gpt-4o-mini'), {
66
- customer: 'user_alex@example.com', // User ID, email, or Stripe Customer ID
67
- threadId: 'agent_thread_4920', // Conversation or workflow thread ID
68
- metadata: { plan: 'pro', team: 'ai-ops' },
89
+ const cost = vibezcheck.calculateCost('gpt-4o-mini', {
90
+ promptTokens: 1240,
91
+ completionTokens: 150,
69
92
  });
93
+ console.log(cost.totalUSD);
94
+ // 0.000276
70
95
  ```
71
96
 
72
- ---
97
+ ### Customer attribution
73
98
 
74
- ### 3. Monetization & Profit Margins (Markups)
75
- Turn wholesale LLM expenses into profitable revenue with automatic markups:
76
99
  ```typescript
77
100
  const model = vibezcheck(openai('gpt-4o-mini'), {
78
- pricing: {
79
- margin: 1.25, // 25% profit margin applied to billed cost
101
+ customer: 'user_123',
102
+ threadId: 'thread_456',
103
+ metadata: {
104
+ plan: 'pro',
105
+ feature: 'document-analysis',
80
106
  },
81
107
  });
82
108
  ```
83
109
 
110
+ Track usage by:
111
+ - customer
112
+ - organization
113
+ - feature
114
+ - thread
115
+ - model
116
+ - agent session
117
+
84
118
  ---
85
119
 
86
- ### 4. Circuit Breakers (Runaway Loop & Cost Protection)
87
- Prevent infinite agent loops and accidental multi-hundred-dollar API bills with pre-flight and in-flight circuit breakers:
120
+ ## 🛡️ Control
121
+
122
+ AI agents can make multiple calls before a workflow finishes.
123
+ Put a ceiling on them.
124
+
125
+ ### Per-request limits
126
+
88
127
  ```typescript
89
128
  const model = vibezcheck(openai('gpt-4o-mini'), {
90
- maxCostPerCallUSD: 0.25, // Auto-terminates if call exceeds $0.25
91
- maxTokensPerCall: 4000, // Auto-terminates if prompt + completion exceeds 4,000 tokens
129
+ maxCostPerCallUSD: 0.25,
130
+ maxTokensPerCall: 4000,
131
+ });
132
+ ```
133
+
134
+ ### Agent session budgets
135
+
136
+ ```typescript
137
+ const session = vibezcheck.session({
138
+ customer: 'tenant_123',
139
+ sessionBudgetUSD: 2.00,
92
140
  });
93
141
  ```
94
142
 
143
+ The entire workflow gets a hard spending ceiling.
144
+
145
+ ### Tool costs
146
+
147
+ ```typescript
148
+ const tools = session.tools(agentTools, {
149
+ web_search: {
150
+ costUSD: 0.01,
151
+ },
152
+ code_interpreter: {
153
+ costUSD: 0.05,
154
+ },
155
+ });
156
+ ```
157
+
158
+ Now you can account for:
159
+
160
+ ```text
161
+ LLM usage + Tool usage = Agent cost
162
+ ```
163
+
95
164
  ---
96
165
 
97
- ### 5. Floating React Spending HUD (`<VibezCheck />`)
98
- A zero-prop floating financial HUD and expandable card that displays real-time tokens and costs directly from your `useChat()` messages array:
99
- ```tsx
100
- 'use client';
166
+ ## 💳 Monetize
101
167
 
102
- import { useChat } from '@ai-sdk/react';
103
- import { VibezCheck } from 'vibezcheck/ui'; // or 'vibezcheck/react'
168
+ Your provider cost can become part of your application's pricing model.
104
169
 
105
- export default function ChatView() {
106
- const { messages } = useChat();
170
+ ```typescript
171
+ const model = vibezcheck(openai('gpt-4o-mini'), {
172
+ customer: 'user_123',
173
+ pricing: {
174
+ markup: 1.3,
175
+ },
176
+ });
177
+ ```
107
178
 
108
- return (
109
- <div>
110
- {/* Your chat UI */}
111
- <VibezCheck messages={messages} />
112
- </div>
113
- );
114
- }
179
+ A 1.3x markup means:
180
+
181
+ ```text
182
+ Provider cost $1.00
183
+ Customer price $1.30
184
+ ─────────────────────
185
+ Markup 30%
115
186
  ```
116
- * **⇅ Unit Swap**: Click to toggle between **Dollar Cost** (`$0.0028`) and **Tokens** (`1,420 tok`).
117
- * **Multi-Model Breakdown**: Automatically displays per-model spend splits when conversations route across multiple models.
118
- * **Customer Privacy by Default**: Wholesale developer costs and margin formulas remain private unless explicitly enabled.
187
+
188
+ This lets you build products where AI usage can map directly to:
189
+ - credits
190
+ - usage limits
191
+ - customer pricing
192
+ - subscriptions
193
+ - metered billing
119
194
 
120
195
  ---
121
196
 
122
- ### 6. Per-Message Turn Micro-Receipt (`<VibezReceipt />`)
123
- Display an elegant micro-badge showing token count, cost, model, and latency below each assistant message:
197
+ ## 🧾 AI Cost Receipts
198
+
199
+ Show users the cost of individual AI responses.
200
+
124
201
  ```tsx
125
202
  import { VibezReceipt } from 'vibezcheck/ui';
126
203
 
127
- // Inside your assistant message bubble
128
204
  {message.role === 'assistant' && (
129
- <div className="flex justify-end mt-2">
130
- <VibezReceipt message={message} />
131
- </div>
205
+ <VibezReceipt message={message} />
132
206
  )}
133
- // Renders: ✦ $0.0001 · 31 tok · gpt-4o-mini
207
+ ```
208
+
209
+ **Example:**
210
+ > `✦ $0.0001 · 31 tok · gpt-4o-mini`
211
+
212
+ For complete conversations, use the spending HUD:
213
+
214
+ ```tsx
215
+ import { VibezCheck } from 'vibezcheck/ui';
216
+
217
+ <VibezCheck messages={messages} />
218
+ ```
219
+
220
+ The HUD can show:
221
+
222
+ ```text
223
+ ┌─────────────────────────┐
224
+ │ AI Usage │
225
+ │ │
226
+ │ $0.0248 │
227
+ │ 12,420 tokens │
228
+ │ │
229
+ │ gpt-4o-mini $0.0182 │
230
+ │ gpt-4o $0.0066 │
231
+ └─────────────────────────┘
134
232
  ```
135
233
 
136
234
  ---
137
235
 
138
- ### 7. Supabase Database Sink
139
- Persist usage records directly into your Supabase database in the background without slowing down the inference stream:
236
+ ## 🔌 Native Provider Streams
237
+
238
+ VibezCheck also works outside the Vercel AI SDK.
239
+
140
240
  ```typescript
141
- import { createClient } from '@supabase/supabase-js';
142
- import { openai } from '@ai-sdk/openai';
241
+ import OpenAI from 'openai';
143
242
  import { vibezcheck } from 'vibezcheck';
144
243
 
145
- const supabase = createClient(process.env.SUPABASE_URL!, process.env.SUPABASE_KEY!);
244
+ const openai = new OpenAI();
245
+ const client = vibezcheck.create();
146
246
 
147
- const model = vibezcheck(openai('gpt-4o-mini'), {
148
- customer: 'usr_alex',
149
- database: vibezcheck.supabase(supabase), // Inserts to default 'vibez_usage' table
247
+ const stream = await openai.chat.completions.create({
248
+ model: 'gpt-4o-mini',
249
+ messages: [
250
+ {
251
+ role: 'user',
252
+ content: 'Hello!',
253
+ },
254
+ ],
255
+ stream: true,
256
+ stream_options: {
257
+ include_usage: true,
258
+ },
259
+ });
260
+
261
+ const meteredStream = client.wrapStream(stream, {
262
+ model: 'gpt-4o-mini',
263
+ customer: 'user_123',
264
+ onUsage: (event) => {
265
+ console.log(
266
+ `Cost: $${event.cost.totalUSD} (${event.usage.totalTokens} tokens)`
267
+ );
268
+ },
150
269
  });
151
270
  ```
152
271
 
272
+ Use VibezCheck with native provider streams without routing requests through a VibezCheck gateway.
273
+
153
274
  ---
154
275
 
155
- ### 8. Extensible DIY Database Adapter (Drizzle, Kysely, MongoDB, ClickHouse)
156
- Plug in any custom database, ORM, or logging service with a simple 1-line callback:
276
+ ## 💵 Offline Pricing Engine
277
+
278
+ VibezCheck includes a bundled pricing catalog so known model costs can be calculated locally.
279
+
157
280
  ```typescript
158
- import { openai } from '@ai-sdk/openai';
159
- import { vibezcheck } from 'vibezcheck';
281
+ const rates = vibezcheck.getModelPricing('gpt-4o-mini');
282
+ console.log(rates);
283
+ // { inputPer1M: 0.15, outputPer1M: 0.60 }
284
+ ```
285
+
286
+ Calculate costs synchronously:
160
287
 
288
+ ```typescript
289
+ const cost = vibezcheck.calculateCost('gpt-4o-mini', {
290
+ promptTokens: 1000,
291
+ completionTokens: 500,
292
+ });
293
+ console.log(cost.totalUSD);
294
+ // 0.00045
295
+ ```
296
+
297
+ Optional pricing synchronization:
298
+
299
+ ```typescript
300
+ await vibezcheck.syncPricing();
301
+ await vibezcheck.syncVercelGateway();
302
+ ```
303
+
304
+ ---
305
+
306
+ ## 📊 700+ Model Pricing Catalog
307
+
308
+ VibezCheck ships with pricing information for hundreds of models and providers.
309
+
310
+ | Provider | Examples |
311
+ |---|---|
312
+ | **OpenAI** | GPT-4o, GPT-4o-mini, o1, o3-mini |
313
+ | **Anthropic** | Claude 3.5 Sonnet, Claude 3.5 Haiku, Claude 3 Opus |
314
+ | **Google** | Gemini 2.0 Flash, Gemini 1.5 Pro, Gemini 1.5 Flash |
315
+ | **DeepSeek** | DeepSeek R1, DeepSeek V3 |
316
+ | **Meta / Groq** | Llama 3.3 70B, Llama 3.1 8B |
317
+ | **Mistral** | Mistral Large, Codestral, Pixtral |
318
+ | **Gateways / Cloud** | AWS Bedrock, Azure OpenAI, OpenRouter, Vercel AI Gateway |
319
+
320
+ Pricing is bundled locally for offline calculations and can optionally be refreshed.
321
+
322
+ ---
323
+
324
+ ## 🗄️ Store Usage Events
325
+
326
+ VibezCheck does not require a database.
327
+ When you want persistence, attach a sink.
328
+
329
+ ### Supabase
330
+
331
+ ```typescript
332
+ const model = vibezcheck(openai('gpt-4o-mini'), {
333
+ customer: 'user_123',
334
+ database: vibezcheck.supabase(supabase),
335
+ });
336
+ ```
337
+
338
+ ### Custom database
339
+
340
+ Use your existing infrastructure:
341
+
342
+ ```typescript
161
343
  const model = vibezcheck(openai('gpt-4o-mini'), {
162
- customer: 'usr_alex',
344
+ customer: 'user_123',
163
345
  database: vibezcheck.database(async (event) => {
164
- // Custom sink: Drizzle, Kysely, Mongo, Prisma, or custom webhook
165
346
  await db.insert(usageEvents).values({
166
347
  customerId: event.customerId,
167
348
  model: event.model,
@@ -172,193 +353,294 @@ const model = vibezcheck(openai('gpt-4o-mini'), {
172
353
  });
173
354
  ```
174
355
 
356
+ Use your own:
357
+ - PostgreSQL
358
+ - Supabase
359
+ - Drizzle
360
+ - Prisma
361
+ - MongoDB
362
+ - ClickHouse
363
+ - webhooks
364
+ - analytics systems
365
+
175
366
  ---
176
367
 
177
- ### 9. Metronome Usage-Based Billing Ingestion
178
- Directly stream usage records to Metronome's `/v1/ingest` API using native zero-dependency HTTP requests:
179
- ```typescript
180
- import { openai } from '@ai-sdk/openai';
181
- import { vibezcheck } from 'vibezcheck';
368
+ ## 💳 Billing Integrations
182
369
 
183
- const model = vibezcheck(openai('gpt-4o-mini'), {
184
- customer: 'cust_metronome_456',
185
- database: vibezcheck.metronome({
186
- apiKey: process.env.METRONOME_API_KEY!,
370
+ Usage events can be connected to billing systems such as Stripe or Metronome.
371
+
372
+ For example:
373
+
374
+ ```typescript
375
+ const model = vibezcheck('openai/gpt-4o-mini', {
376
+ customer: 'cus_123',
377
+ database: vibezcheck.database(async (event) => {
378
+ // Send event to your billing system
379
+ await recordBillableUsage({
380
+ customerId: event.customerId,
381
+ costUSD: event.cost.totalUSD,
382
+ });
187
383
  }),
188
384
  });
189
385
  ```
190
386
 
387
+ VibezCheck gives you the usage event.
388
+ You decide how that usage becomes revenue.
389
+
191
390
  ---
192
391
 
193
- ### 10. Offline Pricing Engine & Dynamic Rate Sync
194
- Compute token costs synchronously in 0ms using bundled offline catalogs (700+ models) or optionally sync dynamic upstream rates:
392
+ ## 🧠 AI Agents
393
+
394
+ Agentic applications need more than token tracking.
395
+ They need economic boundaries.
396
+
195
397
  ```typescript
196
- import { vibezcheck } from 'vibezcheck';
398
+ const session = vibezcheck.session({
399
+ customer: 'enterprise_123',
400
+ sessionBudgetUSD: 5.00,
401
+ });
197
402
 
198
- // Synchronous 0ms offline calculation (works without internet)
199
- const rates = vibezcheck.getModelPricing('gpt-4o-mini');
200
- // { inputPer1M: 0.15, outputPer1M: 0.60 }
403
+ const tools = session.tools(agentTools, {
404
+ web_search: {
405
+ costUSD: 0.01,
406
+ },
407
+ code_interpreter: {
408
+ costUSD: 0.05,
409
+ },
410
+ });
201
411
 
202
- const cost = vibezcheck.calculateCost('gpt-4o-mini', {
203
- promptTokens: 1000,
204
- completionTokens: 500,
412
+ const result = await runAutonomousWorkflow({
413
+ model: session.model('gpt-4o'),
414
+ tools,
205
415
  });
206
- console.log(cost.totalUSD); // $0.00045
416
+ ```
207
417
 
208
- // Optional: refresh rates dynamically in the background
209
- await vibezcheck.syncPricing(); // Sync Stripe Metronome rates
210
- await vibezcheck.syncVercelGateway(); // Sync Vercel AI Gateway 260+ models
418
+ VibezCheck can track:
419
+
420
+ ```text
421
+ Model calls + Tool calls + Multiple turns
422
+ ↓
423
+ Total agent cost
211
424
  ```
212
425
 
213
426
  ---
214
427
 
215
- ### 11. Autonomous Agent Governance & Tool Ceilings
216
- Enforce a hard budget ceiling over multi-step agent loops and bill for tool invocations:
217
- ```typescript
218
- import { vibezcheck } from 'vibezcheck';
428
+ ## 🏗️ Production Characteristics
219
429
 
220
- const session = vibezcheck.session({
221
- customer: 'usr_agent_runner',
222
- sessionBudgetUSD: 1.00, // Hard ceiling for entire multi-turn workflow
223
- });
430
+ ### Zero runtime dependencies
431
+ `dependencies: {}`
432
+ The core library does not require an external runtime dependency.
433
+ Provider SDKs, React, and database clients are optional integrations.
224
434
 
225
- // Bill for tool executions
226
- const tools = session.tools(myTools, {
227
- web_search: { costUSD: 0.01 },
228
- code_interpreter: { costUSD: 0.05 },
229
- });
230
- ```
435
+ ### No network proxy
436
+ Model requests continue directly between your application and the provider.
437
+ VibezCheck runs inside your application.
231
438
 
232
- ---
439
+ ### No prompt storage by default
440
+ VibezCheck does not need to store prompts or model completions to calculate usage and cost.
441
+ Your application controls what gets persisted through optional database adapters.
233
442
 
234
- ### 12. Serverless Lifecycle Spooling & Manual Flush
235
- VibezCheck automatically hooks into `globalThis.after()` on Next.js / Vercel and `globalThis.waitUntil()` on Cloudflare Workers so logging never delays stream delivery. You can also explicitly flush before process termination:
236
- ```typescript
237
- import { vibezcheck } from 'vibezcheck';
443
+ ### Failure isolation
444
+ Telemetry and database reporting should not become a dependency of the user-facing AI response.
445
+ VibezCheck supports asynchronous reporting through serverless lifecycle mechanisms such as:
446
+ - Next.js / Vercel `globalThis.after()`
447
+ - Cloudflare Workers `waitUntil()`
238
448
 
239
- // Guarantees all queued usage telemetry is written before worker teardown
240
- await vibezcheck.flush();
241
- ```
449
+ ### Offline capable
450
+ The bundled pricing catalog allows cost calculations without requiring an external network request.
242
451
 
243
452
  ---
244
453
 
245
- ### 13. Native Non-AI-SDK Streams (OpenAI, Anthropic, Gemini)
246
- Meter raw SDK streams outside the Vercel AI SDK with 0ms added latency:
247
- ```typescript
248
- import OpenAI from 'openai';
249
- import { vibezcheck } from 'vibezcheck';
454
+ ## 🔄 How It Works
455
+
456
+ ```text
457
+ Your Application
458
+ │
459
+ ▼
460
+ ┌──────────────────┐
461
+ │ AI Provider │
462
+ │ OpenAI / Claude │
463
+ │ Gemini / etc. │
464
+ └────────┬─────────┘
465
+ │
466
+ ▼
467
+ ┌──────────────────┐
468
+ │ VibezCheck │
469
+ │ │
470
+ │ Usage │
471
+ │ Cost │
472
+ │ Attribution │
473
+ │ Limits │
474
+ └────────┬─────────┘
475
+ │
476
+ ┌────┴────┐
477
+ ▼ ▼
478
+ Application Async sinks
479
+ economics DB / billing / analytics
480
+ ```
250
481
 
251
- const openai = new OpenAI();
252
- const client = vibezcheck.create();
482
+ The important part:
483
+ Your model traffic stays in your application path.
484
+ VibezCheck adds the economic layer around it.
253
485
 
254
- const stream = await openai.chat.completions.create({
255
- model: 'gpt-4o-mini',
256
- messages: [{ role: 'user', content: 'Hello!' }],
257
- stream: true,
258
- stream_options: { include_usage: true },
259
- });
486
+ ---
260
487
 
261
- // Meter stream in real time
262
- const meteredStream = client.wrapStream(stream, {
263
- model: 'gpt-4o-mini',
264
- onUsage: (event) => {
265
- console.log(`Billed: $${event.cost.totalUSD} for ${event.usage.totalTokens} tokens`);
266
- },
267
- });
268
- ```
488
+ ## 🧩 Supported Integrations
489
+
490
+ ### AI SDKs
491
+ - Vercel AI SDK
492
+ - OpenAI
493
+ - Anthropic
494
+ - Gemini
495
+ - Native streaming APIs
496
+
497
+ ### Storage
498
+ - Supabase
499
+ - Custom database adapters
500
+ - PostgreSQL
501
+ - Drizzle
502
+ - Prisma
503
+ - MongoDB
504
+ - ClickHouse
505
+
506
+ ### Billing
507
+ - Stripe
508
+ - Metronome
509
+ - Custom billing systems
510
+
511
+ ### UI
512
+ - React
513
+ - `<VibezReceipt />`
514
+ - `<VibezCheck />`
269
515
 
270
516
  ---
271
517
 
272
- ### 14. CLI Diagnostics & Starter Scaffolding
273
- Inspect your codebase for unmetered LLM endpoints or scaffold complete starter templates:
518
+ ## 🔍 CLI
519
+
520
+ Audit your project for potentially unmetered AI calls:
521
+
274
522
  ```bash
275
- # Scan project routes for unmetered AI SDK calls
276
523
  npx vibezcheck audit
524
+ ```
277
525
 
278
- # Scaffold starter projects (Next.js App Router, minimal scripts, etc.)
526
+ Generate starter examples:
527
+
528
+ ```bash
279
529
  npx vibezcheck examples
280
530
  ```
281
531
 
282
532
  ---
283
533
 
284
- ## 🚀 Complete Next.js App Router Example
534
+ ## 🚀 Complete Example
535
+
536
+ A typical AI chat application can look like this:
285
537
 
286
- ### Server Route (`app/api/chat/route.ts`)
287
538
  ```typescript
288
- import { convertToModelMessages, streamText, UIMessage } from 'ai';
539
+ import { streamText } from 'ai';
289
540
  import { openai } from '@ai-sdk/openai';
290
541
  import { vibezcheck } from 'vibezcheck';
291
542
 
292
- export const maxDuration = 30;
293
-
294
543
  export async function POST(req: Request) {
295
- const { messages }: { messages: UIMessage[] } = await req.json();
544
+ const { messages, userId } = await req.json();
296
545
 
297
546
  const result = streamText({
298
547
  model: vibezcheck(openai('gpt-4o-mini'), {
299
- customer: 'user_alex@example.com',
300
- pricing: { margin: 1.3 }, // +30% margin
301
- maxCostPerCallUSD: 0.50, // Circuit breaker
548
+ customer: userId,
549
+ pricing: {
550
+ markup: 1.3,
551
+ },
552
+ maxCostPerCallUSD: 0.50,
302
553
  }),
303
- instructions: 'You are a helpful assistant.',
304
- messages: await convertToModelMessages(messages),
554
+ messages,
305
555
  });
306
556
 
307
557
  return vibezcheck.toResponse(result);
308
558
  }
309
559
  ```
310
560
 
311
- ### Frontend Client (`app/page.tsx`)
312
- ```tsx
313
- 'use client';
314
-
315
- import { useChat } from '@ai-sdk/react';
316
- import { DefaultChatTransport } from 'ai';
317
- import { useState } from 'react';
318
- import { VibezReceipt, VibezCheck } from 'vibezcheck/ui';
561
+ Your application now has:
562
+ - ✓ Model usage
563
+ - ✓ Dollar cost
564
+ - ✓ Customer attribution
565
+ - ✓ Pricing / markup
566
+ - ✓ Per-request protection
567
+ - ✓ Streaming support
319
568
 
320
- export default function ChatPage() {
321
- const [input, setInput] = useState('');
322
- const { messages, sendMessage, status } = useChat({
323
- transport: new DefaultChatTransport({ api: '/api/chat' }),
324
- });
569
+ ---
325
570
 
326
- return (
327
- <div className="flex flex-col w-full max-w-lg py-20 mx-auto px-4 min-h-screen">
328
- <div className="flex-1 space-y-4 mb-28">
329
- {messages.map((message) => (
330
- <div key={message.id} className="p-4 rounded-xl border">
331
- <div>{message.content}</div>
332
- {message.role === 'assistant' && (
333
- <div className="mt-2 flex justify-end">
334
- <VibezReceipt message={message} />
335
- </div>
336
- )}
337
- </div>
338
- ))}
339
- </div>
340
-
341
- <form onSubmit={(e) => { e.preventDefault(); sendMessage({ text: input }); setInput(''); }}>
342
- <input value={input} onChange={(e) => setInput(e.target.value)} placeholder="Type prompt..." />
343
- </form>
344
-
345
- <VibezCheck messages={messages} />
346
- </div>
347
- );
348
- }
571
+ ## 🎯 The Economic Layer for AI
572
+
573
+ AI applications are becoming more autonomous.
574
+ More messages.
575
+ More context.
576
+ More tool calls.
577
+ More model calls.
578
+ More cost.
579
+
580
+ VibezCheck gives your application a way to understand that cost at the point where the AI request happens.
581
+
582
+ ```text
583
+ MEASURE
584
+ │
585
+ ┌─────┴─────┐
586
+ │ │
587
+ tokens dollars
588
+ │ │
589
+ └─────┬─────┘
590
+ │
591
+ CONTROL
592
+ budgets / limits
593
+ │
594
+ MONETIZE
595
+ pricing / billing
349
596
  ```
350
597
 
598
+ **Know what every AI request costs.**
599
+
600
+ ---
601
+
602
+ ## Roadmap
603
+
604
+ ### Current
605
+ - Request-level cost metering
606
+ - 700+ model pricing catalog
607
+ - Streaming support
608
+ - Customer attribution
609
+ - Circuit breakers
610
+ - Agent session budgets
611
+ - Tool cost tracking
612
+ - React usage UI
613
+ - Database sinks
614
+
615
+ ### Next
616
+ - Persistent cost history
617
+ - Per-customer budgets
618
+ - Spend alerts
619
+ - Cost anomaly detection
620
+ - Native billing integrations
621
+ - Unit economics analytics
622
+
351
623
  ---
352
624
 
353
- ## 🛡️ Core Guarantees & Philosophy
625
+ ## Contributing
626
+
627
+ Contributions are welcome.
628
+
629
+ ```bash
630
+ pnpm install
631
+ pnpm test
632
+ pnpm typecheck
633
+ ```
634
+
635
+ To update model pricing:
636
+ `src/pricing/catalog.ts`
354
637
 
355
- * **Zero Added Latency (0ms)**: Calculations happen in-memory synchronously. Telemetry and database writes occur asynchronously via non-blocking lifecycles.
356
- * **Pure Zero Runtime Dependencies (`dependencies: {}`)**: Completely self-contained engine. Peer dependencies (`ai`, `@ai-sdk/provider`, `openai`, `react`) are purely optional.
357
- * **Airbag Failure Isolation**: Database or remote sync outages will never crash user-facing AI chat streams.
358
- * **Offline-First Resilience**: All rate calculations work immediately with bundled catalogs even with zero network access.
638
+ Please ensure tests pass and no unnecessary runtime dependencies are introduced.
359
639
 
360
640
  ---
361
641
 
362
- ## 📄 License
642
+ ## License
363
643
 
364
- MIT © [VibezCheck](https://vibezcheck.xyz)
644
+ MIT © VibezCheck
645
+ [Website](https://vibezcheck.xyz/) · [npm](https://www.npmjs.com/package/vibezcheck)
646
+ Contact: [yt@vibezcheck.app](mailto:yt@vibezcheck.app)