vibezcheck 0.1.0

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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +219 -0
  3. package/dist/ai-sdk/index.d.mts +34 -0
  4. package/dist/ai-sdk/index.d.ts +34 -0
  5. package/dist/ai-sdk/index.js +982 -0
  6. package/dist/ai-sdk/index.js.map +1 -0
  7. package/dist/ai-sdk/index.mjs +944 -0
  8. package/dist/ai-sdk/index.mjs.map +1 -0
  9. package/dist/auth/index.d.mts +59 -0
  10. package/dist/auth/index.d.ts +59 -0
  11. package/dist/auth/index.js +129 -0
  12. package/dist/auth/index.js.map +1 -0
  13. package/dist/auth/index.mjs +90 -0
  14. package/dist/auth/index.mjs.map +1 -0
  15. package/dist/billing/index.d.mts +48 -0
  16. package/dist/billing/index.d.ts +48 -0
  17. package/dist/billing/index.js +128 -0
  18. package/dist/billing/index.js.map +1 -0
  19. package/dist/billing/index.mjs +90 -0
  20. package/dist/billing/index.mjs.map +1 -0
  21. package/dist/client-MJ3tl7bz.d.mts +44 -0
  22. package/dist/client-txrE0D_D.d.ts +44 -0
  23. package/dist/customers/index.d.mts +49 -0
  24. package/dist/customers/index.d.ts +49 -0
  25. package/dist/customers/index.js +158 -0
  26. package/dist/customers/index.js.map +1 -0
  27. package/dist/customers/index.mjs +119 -0
  28. package/dist/customers/index.mjs.map +1 -0
  29. package/dist/index.d.mts +92 -0
  30. package/dist/index.d.ts +92 -0
  31. package/dist/index.js +1458 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/index.mjs +1386 -0
  34. package/dist/index.mjs.map +1 -0
  35. package/dist/meter/index.d.mts +131 -0
  36. package/dist/meter/index.d.ts +131 -0
  37. package/dist/meter/index.js +895 -0
  38. package/dist/meter/index.js.map +1 -0
  39. package/dist/meter/index.mjs +843 -0
  40. package/dist/meter/index.mjs.map +1 -0
  41. package/dist/pricing/index.d.mts +40 -0
  42. package/dist/pricing/index.d.ts +40 -0
  43. package/dist/pricing/index.js +178 -0
  44. package/dist/pricing/index.js.map +1 -0
  45. package/dist/pricing/index.mjs +146 -0
  46. package/dist/pricing/index.mjs.map +1 -0
  47. package/dist/types-CSrSmsd1.d.mts +159 -0
  48. package/dist/types-CSrSmsd1.d.ts +159 -0
  49. package/package.json +131 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 VibezCheck <dev@vibezcheck.xyz> (https://vibezcheck.xyz)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,219 @@
1
+ # ⚡ vibezcheck
2
+
3
+ > **The 1-line Stripe Billing & Token Metering engine for LLMs.**
4
+ > Track tokens, compute real-time dollar costs, and bill customers with 0ms added latency.
5
+
6
+ [![npm version](https://img.shields.io/npm/v/vibezcheck.svg)](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
+
10
+ ---
11
+
12
+ ## 🚀 Why vibezcheck?
13
+
14
+ * **⚡ 0ms Added Latency**: Streams pass straight through to the browser with zero buffering.
15
+ * **🧠 Reasoning & Thinking Token Aware**: Accurately tracks hidden reasoning tokens in GPT-5, o1/o3, Claude 3.7 Thinking, and Gemini 3.7 Thoughts.
16
+ * **💰 Built-in Cost Engine**: Calculates exact USD inference costs out of the box with prompt caching discounts.
17
+ * **🆓 Zero-Config Local Mode**: Works 100% free in development with no Stripe account needed.
18
+ * **💳 1-Line Stripe Billing**: Turn an AI prototype into a live, revenue-generating SaaS in 1 line of code.
19
+
20
+ ---
21
+
22
+ ## 📦 Installation
23
+
24
+ ```bash
25
+ npm install vibezcheck stripe
26
+ # or
27
+ pnpm add vibezcheck stripe
28
+ ```
29
+
30
+ ---
31
+
32
+ ## 🎯 The 2 Core Features
33
+
34
+ ---
35
+
36
+ ### Feature 1: Local Token & Cost Tracking (Free / No Stripe Required)
37
+
38
+ Use this in development or when you want real-time token and USD cost analytics without billing users:
39
+
40
+ #### 💻 Code:
41
+ ```typescript
42
+ // app/api/chat/route.ts
43
+ import { createMeter } from 'vibezcheck/meter';
44
+ import OpenAI from 'openai';
45
+
46
+ const openai = new OpenAI();
47
+
48
+ // 1. Create a meter (no Stripe key required!)
49
+ const meter = createMeter({
50
+ onUsage: (event) => {
51
+ console.log(`[vibezcheck] 📊 Model: ${event.model}`);
52
+ console.log(`Tokens: ${event.usage.totalTokens} (Input: ${event.usage.inputTokens}, Output: ${event.usage.outputTokens}, Reasoning: ${event.usage.reasoningTokens ?? 0})`);
53
+ console.log(`Inference Cost: $${event.cost.totalUSD.toFixed(6)} USD\n`);
54
+ },
55
+ });
56
+
57
+ export async function POST(req: Request) {
58
+ const { messages } = await req.json();
59
+
60
+ const stream = await openai.chat.completions.create({
61
+ model: 'gpt-4o',
62
+ messages,
63
+ stream: true,
64
+ stream_options: { include_usage: true },
65
+ });
66
+
67
+ // 2. Wrap stream - passes chunks directly to user with 0ms added delay
68
+ return new Response(meter.wrapStream(stream));
69
+ }
70
+ ```
71
+
72
+ #### 🌐 What the Frontend receives:
73
+ ```http
74
+ HTTP/1.1 200 OK
75
+ Content-Type: text/plain; charset=utf-8
76
+ Transfer-Encoding: chunked
77
+
78
+ Quantum computing uses qubits to perform complex calculations exponentially faster...
79
+ ```
80
+
81
+ #### 🖥️ What your Terminal logs:
82
+ ```
83
+ [vibezcheck] 📊 Model: openai/gpt-4o
84
+ Tokens: 1,420 (Input: 800, Output: 620, Reasoning: 0)
85
+ Inference Cost: $0.008200 USD
86
+ ```
87
+
88
+ ---
89
+
90
+ ### Feature 2: 1-Line Stripe Billing with Vercel AI SDK (`withBilling`)
91
+
92
+ Use this when you are ready to charge users and protect your margins from heavy reasoning models (GPT-5, Claude 3.7 Thinking):
93
+
94
+ #### 💻 Code:
95
+ ```typescript
96
+ // app/api/chat/route.ts
97
+ import { withBilling } from 'vibezcheck';
98
+ import { openai } from '@ai-sdk/openai';
99
+ import { streamText } from 'ai';
100
+
101
+ export async function POST(req: Request) {
102
+ const { messages, userEmail } = await req.json();
103
+
104
+ // 1-line wrapper: extracts reasoning tokens & logs meter events to Stripe!
105
+ const result = streamText({
106
+ model: withBilling(openai('gpt-5.6-sol'), {
107
+ customer: userEmail, // e.g. "alex@example.com"
108
+ stripeApiKey: process.env.STRIPE_SECRET_KEY,
109
+ }),
110
+ messages,
111
+ });
112
+
113
+ return result.toDataStreamResponse();
114
+ }
115
+ ```
116
+
117
+ #### 🌐 What the Frontend receives:
118
+ Compatible with Vercel's `useChat()` React hook:
119
+ ```http
120
+ HTTP/1.1 200 OK
121
+ Content-Type: text/event-stream; charset=utf-8
122
+ x-vercel-ai-data-stream: v1
123
+
124
+ 0:"Here is the "
125
+ 0:"solution step by step..."
126
+ d:{"finishReason":"stop","usage":{"promptTokens":1200,"completionTokens":450,"reasoningTokens":350}}
127
+ ```
128
+
129
+ #### 💳 What Stripe receives in the background:
130
+ 1. **Customer Created/Resolved**: Customer `alex@example.com` is automatically created (`cus_Q871xyz`).
131
+ 2. **Meter Event Dispatched to Stripe Billing**:
132
+ ```json
133
+ {
134
+ "event_name": "token-billing-tokens",
135
+ "timestamp": "2026-08-23T10:12:00.000Z",
136
+ "payload": {
137
+ "stripe_customer_id": "cus_Q871xyz",
138
+ "value": "800",
139
+ "model": "openai/gpt-5.6-sol",
140
+ "token_type": "output",
141
+ "is_reasoning": "true"
142
+ }
143
+ }
144
+ ```
145
+ 3. **Invoice Updated**: Stripe increments Alex's monthly usage bill or deducts \$0.016 from their prepaid credit balance.
146
+
147
+ ---
148
+
149
+ ### Also works with Claude 3.7 Sonnet Extended Thinking
150
+
151
+ ```typescript
152
+ import { createMeter } from 'vibezcheck/meter';
153
+ import Anthropic from '@anthropic-ai/sdk';
154
+
155
+ const anthropic = new Anthropic();
156
+ const meter = createMeter({ apiKey: process.env.STRIPE_SECRET_KEY });
157
+
158
+ export async function handleThinkingPrompt(prompt: string, customerId: string) {
159
+ const stream = await anthropic.messages.create({
160
+ model: 'claude-3-7-sonnet-20250219',
161
+ max_tokens: 4000,
162
+ thinking: { type: 'enabled', budget_tokens: 2000 },
163
+ messages: [{ role: 'user', content: prompt }],
164
+ stream: true,
165
+ });
166
+
167
+ // Automatically captures Claude 3.7 thinking tokens and sends to Stripe:
168
+ return meter.wrapStream(stream, { customerId });
169
+ }
170
+ ```
171
+
172
+ #### 💳 Stripe Meter Event output for Thinking Tokens:
173
+ ```json
174
+ {
175
+ "event_name": "token-billing-tokens",
176
+ "payload": {
177
+ "stripe_customer_id": "cus_Q871xyz",
178
+ "value": "1840",
179
+ "model": "anthropic/claude-3-7-sonnet",
180
+ "token_type": "output_thinking"
181
+ }
182
+ }
183
+ ```
184
+
185
+ ---
186
+
187
+ ## 💰 Built-in Model Pricing Registry
188
+
189
+ `vibezcheck` ships with default rates for all active frontier models:
190
+
191
+ ```typescript
192
+ import { calculateCost } from 'vibezcheck/pricing';
193
+
194
+ const cost = calculateCost({
195
+ model: 'claude-3-7-sonnet',
196
+ inputTokens: 2000,
197
+ outputTokens: 800,
198
+ reasoningTokens: 1200, // thinking tokens
199
+ });
200
+
201
+ console.log(cost);
202
+ ```
203
+
204
+ #### 🖥️ Response:
205
+ ```json
206
+ {
207
+ "inputCostUSD": 0.00118,
208
+ "outputCostUSD": 0.002344,
209
+ "reasoningCostUSD": 0.003516,
210
+ "totalCostUSD": 0.007040,
211
+ "currency": "USD"
212
+ }
213
+ ```
214
+
215
+ ---
216
+
217
+ ## 📄 License
218
+
219
+ MIT © [vibezcheck.xyz](https://vibezcheck.xyz)
@@ -0,0 +1,34 @@
1
+ import { C as CustomerParam, U as UsageEvent } from '../types-CSrSmsd1.mjs';
2
+ import { V as VibezMeter } from '../client-MJ3tl7bz.mjs';
3
+ import 'stripe';
4
+
5
+ interface WithBillingOptions {
6
+ /** Customer email, user ID, or Stripe customer ID */
7
+ customer?: CustomerParam;
8
+ /** Direct Stripe customer ID */
9
+ customerId?: string;
10
+ /** Stripe API Key override (uses STRIPE_SECRET_KEY env by default) */
11
+ stripeApiKey?: string;
12
+ /** Existing VibezMeter instance (optional) */
13
+ meter?: VibezMeter;
14
+ /** Custom meter event name */
15
+ eventName?: string;
16
+ /** Usage callback fired upon generation/stream completion */
17
+ onUsage?: (event: UsageEvent) => void | Promise<void>;
18
+ /** Custom developer metadata */
19
+ metadata?: Record<string, string | number | boolean>;
20
+ }
21
+ /**
22
+ * Wraps any Vercel AI SDK LanguageModel (v2 or v3) with automated Stripe billing and token metering.
23
+ *
24
+ * @param model - The Vercel AI SDK language model instance (e.g. openai('gpt-5.6-sol'), anthropic('claude-3-7-sonnet'))
25
+ * @param options - Billing & customer configuration
26
+ * @returns Decorated LanguageModel that automatically meters tokens and sends Stripe meter events
27
+ */
28
+ declare function withBilling<T extends object>(model: T, options?: WithBillingOptions): T;
29
+ /**
30
+ * Alias for withBilling
31
+ */
32
+ declare const meteredModel: typeof withBilling;
33
+
34
+ export { type WithBillingOptions, meteredModel, withBilling };
@@ -0,0 +1,34 @@
1
+ import { C as CustomerParam, U as UsageEvent } from '../types-CSrSmsd1.js';
2
+ import { V as VibezMeter } from '../client-txrE0D_D.js';
3
+ import 'stripe';
4
+
5
+ interface WithBillingOptions {
6
+ /** Customer email, user ID, or Stripe customer ID */
7
+ customer?: CustomerParam;
8
+ /** Direct Stripe customer ID */
9
+ customerId?: string;
10
+ /** Stripe API Key override (uses STRIPE_SECRET_KEY env by default) */
11
+ stripeApiKey?: string;
12
+ /** Existing VibezMeter instance (optional) */
13
+ meter?: VibezMeter;
14
+ /** Custom meter event name */
15
+ eventName?: string;
16
+ /** Usage callback fired upon generation/stream completion */
17
+ onUsage?: (event: UsageEvent) => void | Promise<void>;
18
+ /** Custom developer metadata */
19
+ metadata?: Record<string, string | number | boolean>;
20
+ }
21
+ /**
22
+ * Wraps any Vercel AI SDK LanguageModel (v2 or v3) with automated Stripe billing and token metering.
23
+ *
24
+ * @param model - The Vercel AI SDK language model instance (e.g. openai('gpt-5.6-sol'), anthropic('claude-3-7-sonnet'))
25
+ * @param options - Billing & customer configuration
26
+ * @returns Decorated LanguageModel that automatically meters tokens and sends Stripe meter events
27
+ */
28
+ declare function withBilling<T extends object>(model: T, options?: WithBillingOptions): T;
29
+ /**
30
+ * Alias for withBilling
31
+ */
32
+ declare const meteredModel: typeof withBilling;
33
+
34
+ export { type WithBillingOptions, meteredModel, withBilling };