vibezcheck 0.5.10 → 0.5.12
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 +495 -213
- package/dist/ai-sdk/index.d.mts +5 -5
- package/dist/ai-sdk/index.d.ts +5 -5
- package/dist/ai-sdk/index.js +34 -5
- package/dist/ai-sdk/index.js.map +1 -1
- package/dist/ai-sdk/index.mjs +34 -5
- package/dist/ai-sdk/index.mjs.map +1 -1
- package/dist/ai-sdk/middleware.d.mts +3 -3
- package/dist/ai-sdk/middleware.d.ts +3 -3
- package/dist/ai-sdk/middleware.js +26 -3
- package/dist/ai-sdk/middleware.js.map +1 -1
- package/dist/ai-sdk/middleware.mjs +26 -3
- package/dist/ai-sdk/middleware.mjs.map +1 -1
- package/dist/billing/index.d.mts +8 -6
- package/dist/billing/index.d.ts +8 -6
- package/dist/billing/index.js +301 -6
- package/dist/billing/index.js.map +1 -1
- package/dist/billing/index.mjs +308 -6
- package/dist/billing/index.mjs.map +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/index.mjs.map +1 -1
- package/dist/{client-eXSwD_kI.d.ts → client-0CuOBECi.d.ts} +1 -1
- package/dist/{client-ttJwYM7x.d.mts → client-xP86Qg_b.d.mts} +1 -1
- package/dist/customers/index.d.mts +1 -1
- package/dist/customers/index.d.ts +1 -1
- package/dist/database/index.d.mts +1 -1
- package/dist/database/index.d.ts +1 -1
- package/dist/index.d.mts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +41 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -6
- package/dist/index.mjs.map +1 -1
- package/dist/meter/index.d.mts +2 -2
- package/dist/meter/index.d.ts +2 -2
- package/dist/meter/index.js +24 -2
- package/dist/meter/index.js.map +1 -1
- package/dist/meter/index.mjs +24 -2
- package/dist/meter/index.mjs.map +1 -1
- package/dist/pricing/index.d.mts +27 -3
- package/dist/pricing/index.d.ts +27 -3
- package/dist/pricing/index.js +23 -1
- package/dist/pricing/index.js.map +1 -1
- package/dist/pricing/index.mjs +23 -1
- package/dist/pricing/index.mjs.map +1 -1
- package/dist/react/index.d.mts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/{session-D9fdP255.d.mts → session-CueUIV77.d.mts} +10 -4
- package/dist/{session-CUnv_muf.d.ts → session-YF67Yij2.d.ts} +10 -4
- package/dist/{types-DHlsaLvI.d.mts → types-CqXTmCNv.d.mts} +2 -0
- package/dist/{types-DHlsaLvI.d.ts → types-CqXTmCNv.d.ts} +2 -0
- package/dist/{with-billing-DhHGWCAp.d.mts → with-billing-Df6izlJ4.d.mts} +4 -2
- package/dist/{with-billing-CVGxl3ot.d.ts → with-billing-DgQ380Zl.d.ts} +4 -2
- package/examples/nextjs-app-router-openai/package.json +1 -1
- package/examples/nextjs-saas-starter/package.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,167 +1,348 @@
|
|
|
1
1
|
# ✦ VibezCheck
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Know what every AI request costs.
|
|
4
|
+
The cost layer for AI applications.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
##
|
|
18
|
+
## Why VibezCheck?
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
Your users buy:
|
|
26
|
+
- messages
|
|
27
|
+
- documents
|
|
28
|
+
- agent runs
|
|
29
|
+
- API calls
|
|
30
|
+
- credits
|
|
31
|
+
- subscriptions
|
|
32
32
|
|
|
33
|
-
|
|
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
|
-
##
|
|
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 {
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
63
|
-
|
|
82
|
+
## 💰 Measure
|
|
83
|
+
|
|
84
|
+
VibezCheck gives your application an economic view of AI usage.
|
|
85
|
+
|
|
86
|
+
### Request cost
|
|
87
|
+
|
|
64
88
|
```typescript
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
79
|
-
|
|
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
|
-
|
|
87
|
-
|
|
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,
|
|
91
|
-
maxTokensPerCall: 4000,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
106
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
123
|
-
|
|
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
|
-
<
|
|
130
|
-
<VibezReceipt message={message} />
|
|
131
|
-
</div>
|
|
205
|
+
<VibezReceipt message={message} />
|
|
132
206
|
)}
|
|
133
|
-
|
|
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
|
-
|
|
139
|
-
|
|
236
|
+
## 🔌 Native Provider Streams
|
|
237
|
+
|
|
238
|
+
VibezCheck also works outside the Vercel AI SDK.
|
|
239
|
+
|
|
140
240
|
```typescript
|
|
141
|
-
import
|
|
142
|
-
import { openai } from '@ai-sdk/openai';
|
|
241
|
+
import OpenAI from 'openai';
|
|
143
242
|
import { vibezcheck } from 'vibezcheck';
|
|
144
243
|
|
|
145
|
-
const
|
|
244
|
+
const openai = new OpenAI();
|
|
245
|
+
const client = vibezcheck.create();
|
|
146
246
|
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
156
|
-
|
|
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
|
-
|
|
159
|
-
|
|
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: '
|
|
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
|
-
|
|
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
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
194
|
-
|
|
392
|
+
## 🧠 AI Agents
|
|
393
|
+
|
|
394
|
+
Agentic applications need more than token tracking.
|
|
395
|
+
They need economic boundaries.
|
|
396
|
+
|
|
195
397
|
```typescript
|
|
196
|
-
|
|
398
|
+
const session = vibezcheck.session({
|
|
399
|
+
customer: 'enterprise_123',
|
|
400
|
+
sessionBudgetUSD: 5.00,
|
|
401
|
+
});
|
|
197
402
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
|
203
|
-
|
|
204
|
-
|
|
412
|
+
const result = await runAutonomousWorkflow({
|
|
413
|
+
model: session.model('gpt-4o'),
|
|
414
|
+
tools,
|
|
205
415
|
});
|
|
206
|
-
|
|
416
|
+
```
|
|
207
417
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
-
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
###
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
240
|
-
|
|
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
|
-
|
|
246
|
-
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
|
|
252
|
-
|
|
482
|
+
The important part:
|
|
483
|
+
Your model traffic stays in your application path.
|
|
484
|
+
VibezCheck adds the economic layer around it.
|
|
253
485
|
|
|
254
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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
|
-
|
|
273
|
-
|
|
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
|
-
|
|
526
|
+
Generate starter examples:
|
|
527
|
+
|
|
528
|
+
```bash
|
|
279
529
|
npx vibezcheck examples
|
|
280
530
|
```
|
|
281
531
|
|
|
282
532
|
---
|
|
283
533
|
|
|
284
|
-
## 🚀 Complete
|
|
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 {
|
|
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
|
|
544
|
+
const { messages, userId } = await req.json();
|
|
296
545
|
|
|
297
546
|
const result = streamText({
|
|
298
547
|
model: vibezcheck(openai('gpt-4o-mini'), {
|
|
299
|
-
customer:
|
|
300
|
-
pricing: {
|
|
301
|
-
|
|
548
|
+
customer: userId,
|
|
549
|
+
pricing: {
|
|
550
|
+
markup: 1.3,
|
|
551
|
+
},
|
|
552
|
+
maxCostPerCallUSD: 0.50,
|
|
302
553
|
}),
|
|
303
|
-
|
|
304
|
-
messages: await convertToModelMessages(messages),
|
|
554
|
+
messages,
|
|
305
555
|
});
|
|
306
556
|
|
|
307
557
|
return vibezcheck.toResponse(result);
|
|
308
558
|
}
|
|
309
559
|
```
|
|
310
560
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
-
|
|
321
|
-
const [input, setInput] = useState('');
|
|
322
|
-
const { messages, sendMessage, status } = useChat({
|
|
323
|
-
transport: new DefaultChatTransport({ api: '/api/chat' }),
|
|
324
|
-
});
|
|
569
|
+
---
|
|
325
570
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
-
##
|
|
642
|
+
## License
|
|
363
643
|
|
|
364
|
-
MIT ©
|
|
644
|
+
MIT © VibezCheck
|
|
645
|
+
[Website](https://vibezcheck.xyz/) · [npm](https://www.npmjs.com/package/vibezcheck)
|
|
646
|
+
Contact: [yt@vibezcheck.app](mailto:yt@vibezcheck.app)
|