vibezcheck 0.3.0 → 0.4.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.
package/README.md CHANGED
@@ -1,213 +1,203 @@
1
1
  # ⚡ vibezcheck
2
2
 
3
- > **The Declarative 1-Line Stripe Billing & Token Metering Engine for LLMs.**
4
- > Track tokens, compute real-time USD costs, and bill customers with 0ms added latency across any LLM provider.
3
+ > **Give your AI app a financial mind.**
4
+ > The declarative 1-line Stripe Billing and Token Metering engine for LLMs. Measure tokens, compute real-time dollar costs, and bill customers with **0ms added latency**.
5
5
 
6
6
  [![npm version](https://img.shields.io/npm/v/vibezcheck.svg)](https://npmjs.org/package/vibezcheck)
7
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
8
8
  [![TypeScript](https://img.shields.io/badge/TypeScript-Strict-blue.svg)](https://www.typescriptlang.org/)
9
+ [![Tests](https://img.shields.io/badge/Tests-31%20Passed-brightgreen.svg)]()
9
10
 
10
11
  ---
11
12
 
12
- ## 🚀 Why vibezcheck?
13
+ ## 🍌 The Electric Meter for Artificial Intelligence
13
14
 
14
- * **⚡ 0ms Added Latency**: Streams pass straight through to the browser with zero buffering or middleware delay.
15
- * **🧠 Thinking & Reasoning Token Aware**: Accurately extracts hidden reasoning tokens in GPT-5, o1/o3-mini, Claude 3.7 Thinking, and Gemini 2.0 Flash Thinking.
16
- * **💰 Built-in Cost Calculation**: Real-time USD inference pricing out of the box with prompt caching discounts.
17
- * **🆓 Zero-Config Local Mode**: Works 100% free in development with no database or Stripe account required.
18
- * **💳 1-Line Stripe Billing**: Turn an AI prototype into a revenue-generating SaaS with autonomous customer provisioning and meter events.
19
- * **⚛️ React & React Native Ready**: Live floating widgets, badges, and checkout paywall modals (`<VibezBillingModal />`).
15
+ When you turn on the lights in your bedroom, your electric meter spins. When users prompt your AI, **VibezCheck** is the smart meter that counts every word and hidden thought — converting it into pennies with Stripe so your app actually looks out for your margins.
16
+
17
+ ### 🛡️ Sane Defaults (Zero Configuration Required)
18
+ * **⚡ 0ms Added Latency**: Streams pass directly to your user's browser with zero intermediate proxy buffering.
19
+ * **🛡️ Default $0.50 Fuse Box**: Automatically prevents runaway loops without requiring manual ceilings.
20
+ * **🛟 In-Flight Abort Trapper**: Captures and bills partial tokens even if a user closes their browser tab mid-stream.
21
+ * **🏷️ Automatic 85% Prompt Cache Discounts**: Detects cache hits on Claude 3.7, GPT-4o, and DeepSeek and passes real savings through.
22
+ * **🚀 Serverless Lifecycle Protection**: Seamlessly keeps serverless containers alive until telemetry is acknowledged.
23
+ * **💰 1-Line Profit Margins**: Turn wholesale provider costs into guaranteed net profit with `pricing: { margin: 1.5 }`.
24
+ * **💳 Prepaid & Postpaid**: Choose between monthly metered invoices or zero-debt credit wallets.
25
+ * **🧠 Reasoning Token Aware**: Captures hidden thinking tokens in o3-mini and Claude 3.7 Thinking.
26
+ * **🆓 Free Vibe Mode**: Works 100% out of the box in local development with no Stripe account required.
20
27
 
21
28
  ---
22
29
 
23
30
  ## 📦 Installation
24
31
 
25
32
  ```bash
26
- npm install vibezcheck stripe
27
- # or
28
- pnpm add vibezcheck stripe
33
+ npm install vibezcheck ai @ai-sdk/openai stripe
29
34
  ```
30
35
 
31
36
  ---
32
37
 
33
- ## ⚡ 1. Declarative Vercel AI SDK Integration
34
-
35
- `vibezcheck` wraps any model string or provider instance into a fully compliant Vercel AI SDK model:
36
-
37
- ### A. Single-Turn Generation (`generateText` & Server Actions)
38
- ```typescript
39
- import { generateText } from "ai";
40
- import { vibezcheck } from "vibezcheck";
41
-
42
- const { text, usage } = await generateText({
43
- model: vibezcheck("openai/gpt-4o-mini", {
44
- customer: "alex@example.com", // Auto-creates or matches Stripe customer
45
- }),
46
- prompt: "What is love?",
47
- });
48
- ```
49
-
50
- ### B. Streaming AI Route (`streamText`)
51
- ```typescript
52
- // app/api/chat/route.ts
53
- import { streamText } from "ai";
54
- import { vibezcheck } from "vibezcheck";
55
-
56
- export async function POST(req: Request) {
57
- const { messages } = await req.json();
58
-
59
- return streamText({
60
- model: vibezcheck("gpt-4o-mini", { customer: "alex@example.com" }),
61
- messages,
62
- }).toTextStreamResponse();
63
- }
64
- ```
38
+ ## ⚡ 1. The 60-Second Quickstart
65
39
 
66
- ### C. Direct `createOpenAI` Connection
67
- You can pass custom OpenAI / Gateway instances directly into `vibezcheck()`:
40
+ ### Backend API Route (`app/api/chat/route.ts`)
68
41
  ```typescript
69
- import { createOpenAI } from "@ai-sdk/openai";
70
- import { streamText } from "ai";
71
- import { vibezcheck } from "vibezcheck";
72
-
73
- const openai = createOpenAI({
74
- apiKey: process.env.AI_GATEWAY_API_KEY,
75
- baseURL: "https://ai-gateway.vercel.sh/v1", // Vercel AI Gateway or Cloudflare
76
- });
42
+ import { streamText } from 'ai';
43
+ import { vibezcheck } from 'vibezcheck';
77
44
 
78
45
  export async function POST(req: Request) {
79
- const { messages } = await req.json();
46
+ const { messages, userEmail = 'alex@company.com' } = await req.json();
80
47
 
81
48
  return streamText({
82
- model: vibezcheck(openai("gpt-4o-mini"), { customer: "alex@example.com" }),
49
+ // 1 Line. All 6 sane defaults run automatically.
50
+ model: vibezcheck('openai/gpt-4o-mini', { customer: userEmail }),
83
51
  messages,
84
- }).toTextStreamResponse();
52
+ }).toDataStreamResponse();
85
53
  }
86
54
  ```
87
55
 
88
- ---
89
-
90
- ## ⚛️ 2. Declarative React UI & Hooks (`vibezcheck/react`)
91
-
92
- ### A. 1-Line Streaming Chat Hook (`useVibezChat`)
93
- Automatically connects to your API route and syncs tokens, reasoning thoughts, and costs with the session widget:
94
-
56
+ ### Frontend Chat UI (`app/page.tsx`)
95
57
  ```tsx
96
58
  'use client';
97
- import { useVibezChat, VibezSessionWidget, VibezBillingModal } from 'vibezcheck/react';
59
+ import { useVibezChat, VibezReceipt, VibezSessionWidget } from 'vibezcheck/react';
98
60
 
99
61
  export default function ChatPage() {
100
- const { messages, input, handleInputChange, handleSubmit, isLoading } = useVibezChat({
101
- model: 'gpt-4o-mini',
102
- customer: 'alex@example.com',
103
- });
62
+ const { messages, input, handleInputChange, handleSubmit } = useVibezChat();
104
63
 
105
64
  return (
106
- <main className="p-6 max-w-3xl mx-auto">
107
- {messages.map((m) => (
108
- <div key={m.id}>
109
- <strong>{m.role}:</strong> {m.content}
110
- </div>
111
- ))}
112
-
113
- <form onSubmit={handleSubmit}>
114
- <input value={input} onChange={handleInputChange} placeholder="Ask..." />
115
- <button type="submit" disabled={isLoading}>Send</button>
65
+ <main className="max-w-xl mx-auto py-10 px-4 space-y-6">
66
+ {/* 1. Floating live token & dollar counter */}
67
+ <VibezSessionWidget position="bottom-right" />
68
+
69
+ {/* 2. Messages with micro-receipts */}
70
+ <div className="space-y-4">
71
+ {messages.map((m) => (
72
+ <div key={m.id} className="p-4 rounded-2xl bg-white border border-slate-200">
73
+ <p className="text-slate-900 text-sm">{m.content}</p>
74
+
75
+ {/* Micro-Receipt under assistant answers */}
76
+ {m.role === 'assistant' && <VibezReceipt message={m} />}
77
+ </div>
78
+ ))}
79
+ </div>
80
+
81
+ <form onSubmit={handleSubmit} className="flex gap-2">
82
+ <input
83
+ value={input}
84
+ onChange={handleInputChange}
85
+ placeholder="Ask a question..."
86
+ className="flex-1 px-4 py-2 rounded-xl border border-slate-200 text-sm"
87
+ />
88
+ <button type="submit" className="px-5 py-2 rounded-xl bg-slate-950 text-white font-bold text-sm">
89
+ Send
90
+ </button>
116
91
  </form>
117
-
118
- {/* Live Token & Dollar Tracker Widget */}
119
- <VibezSessionWidget theme="light" position="bottom-right" />
120
92
  </main>
121
93
  );
122
94
  }
123
95
  ```
124
96
 
125
- ### B. Autonomous Paywall & Top-Up Modal (`<VibezBillingModal />`)
126
- Pops up an in-app Stripe Checkout modal whenever a customer reaches their credit limit:
97
+ ---
98
+
99
+ ## 🛠️ Real-World Implementation Patterns
127
100
 
128
- ```tsx
129
- <VibezBillingModal
130
- isOpen={limitReached}
131
- onClose={() => setLimitReached(false)}
132
- notice={{
133
- status: 'limit_reached',
134
- tokensUsed: 150000,
135
- costUSD: 5.00,
136
- message: 'Free credit limit reached. Top up to keep streaming!',
137
- }}
138
- theme="light"
139
- testMode={true} // Supports Stripe Sandbox testing
140
- />
101
+ ### Pattern A: 50% Profit Margin Engine
102
+ Turn wholesale provider costs into guaranteed net profit:
103
+
104
+ ```typescript
105
+ model: vibezcheck('openai/gpt-4o-mini', {
106
+ customer: 'sarah@acme.com',
107
+ pricing: {
108
+ margin: 1.5, // 👈 Cost + 50% margin automatically billed to Stripe!
109
+ minimumChargeUSD: 0.01, // 👈 Minimum charge 1 cent per question
110
+ },
111
+ })
141
112
  ```
142
113
 
143
114
  ---
144
115
 
145
- ## 💳 3. Stripe Sandbox & Customer Provisioning
116
+ ### Pattern B: Prepaid Credit Wallets (Zero Debt Risk)
117
+ User pre-purchases $10; stream cleanly halts when balance hits $0 without invoice debt:
146
118
 
147
- ### A. Auto Customer Provisioning in 1 Line:
148
119
  ```typescript
149
- import { vibezcheck } from "vibezcheck";
120
+ model: vibezcheck('openai/gpt-4o-mini', {
121
+ customer: 'alex@gmail.com',
122
+ billing: {
123
+ mode: 'prepaid', // 👈 Deducts from prepaid credit balance in real time
124
+ },
125
+ // Gracefully downshift when credits run low instead of crashing
126
+ fallbackModelOnBudget: 'openai/gpt-4o-mini',
127
+ })
128
+ ```
150
129
 
151
- const vz = vibezcheck();
130
+ ---
152
131
 
153
- // Automatically finds existing customer by email or creates a new one in Stripe
154
- const customer = await vz.customers.getOrCreate({
155
- email: "alex@company.com",
156
- name: "Alex Rivera",
157
- });
158
- console.log(customer.id); // "cus_R3K7h9Qv..."
159
- ```
132
+ ### Pattern C: Frontier Reasoning Models (Claude 3.7 & o3-mini)
133
+ Automatically extracts hidden thinking tokens and applies 85% prompt cache discounts:
160
134
 
161
- ### B. 1-Line Stripe Checkout Session:
162
135
  ```typescript
163
- const checkoutUrl = await vz.billing.createCheckoutSession({
164
- customerId: customer.id,
165
- priceId: "price_metered_tokens", // Your Stripe metered price ID
166
- returnUrl: "https://myapp.com/dashboard",
167
- });
136
+ model: vibezcheck('anthropic/claude-3-7-sonnet', {
137
+ customer: 'alex@company.com',
138
+ maxCostPerCallUSD: 0.75, // Extended ceiling for multi-minute deep reasoning
139
+ })
168
140
  ```
169
141
 
170
142
  ---
171
143
 
172
- ## 📊 Live Telemetry Payload Structure
173
-
174
- Every inference event emitted by `onUsage` captures complete token and cost economics:
175
-
176
- ```json
177
- {
178
- "timestamp": "2026-08-31T11:00:00.000Z",
179
- "model": "openai/gpt-4o-mini",
180
- "provider": "openai",
181
- "customerId": "cus_R3K7h9Qv",
182
- "usage": {
183
- "inputTokens": 850,
184
- "outputTokens": 420,
185
- "totalTokens": 1270,
186
- "reasoningTokens": 280,
187
- "cachedTokens": 500
188
- },
189
- "cost": {
190
- "inputUSD": 0.000127,
191
- "outputUSD": 0.000252,
192
- "totalUSD": 0.000379
193
- }
144
+ ### Pattern D: Unified Agent Tool Call Metering
145
+ Bill external tools (web searches, scrapers, Python sandboxes) and LLM streams into one invoice:
146
+
147
+ ```typescript
148
+ // app/api/agent/route.ts
149
+ import { generateText, tool } from 'ai';
150
+ import { vibezcheck } from 'vibezcheck';
151
+ import { z } from 'zod';
152
+
153
+ export async function POST(req: Request) {
154
+ const { prompt, customer = 'alex@company.com' } = await req.json();
155
+
156
+ // Create unified customer session
157
+ const session = vibezcheck.session({ customer });
158
+
159
+ const result = await generateText({
160
+ model: session.model('openai/gpt-4o-mini'),
161
+ tools: {
162
+ searchGoogle: tool({
163
+ description: 'Live Google Search',
164
+ parameters: z.object({ query: z.string() }),
165
+ execute: async ({ query }) => {
166
+ // ⚡ Bill non-LLM tool execution ($0.01) into the same customer balance
167
+ await session.trackTool('google_search', { costUSD: 0.01 });
168
+ return `Search results for: ${query}`;
169
+ },
170
+ }),
171
+ },
172
+ prompt,
173
+ });
174
+
175
+ return Response.json(result);
194
176
  }
195
177
  ```
196
178
 
197
179
  ---
198
180
 
199
- ## 📜 Supported Models (Auto-Priced)
181
+ ### Pattern E: Brand-New Model (1-Line Inline Rate Card)
182
+ Use newly released or fine-tuned models with zero wait for package updates:
183
+
184
+ ```typescript
185
+ model: vibezcheck('deepseek/deepseek-r2', {
186
+ rate: { in: 0.20, out: 0.80 }, // $0.20/M in, $0.80/M out
187
+ })
188
+ ```
189
+
190
+ ---
191
+
192
+ ## 🎨 React UI Suite (`vibezcheck/react`)
200
193
 
201
- | Model Family | Examples | Reasoning Aware | Caching Discounts |
202
- | :--- | :--- | :---: | :---: |
203
- | **OpenAI** | `gpt-4o`, `gpt-4o-mini`, `o1`, `o3-mini`, `gpt-5.6-sol` | | |
204
- | **Anthropic** | `claude-3-7-sonnet`, `claude-3-5-sonnet`, `claude-3-5-haiku` | | ✅ |
205
- | **Google** | `gemini-2.0-flash`, `gemini-1.5-pro` | ✅ | ✅ |
206
- | **DeepSeek** | `deepseek-chat`, `deepseek-reasoner` | ✅ | ✅ |
207
- | **Custom** | Register any custom model with `registerModelPricing()` | ✅ | ✅ |
194
+ * **`useVibezChat`**: 1-hook drop-in chat streaming with live session cost sync.
195
+ * **`<VibezReceipt />`**: Micro-badge rendered below assistant responses (*"⚡ gpt-4o-mini • 342 tokens • $0.0005 • Verified by VibezCheck"*).
196
+ * **`<VibezSessionWidget />`**: Floating live token & dollar speedometer in the screen corner.
197
+ * **`<VibezBillingModal />`**: Drop-in 1-click Stripe Checkout top-up modal.
208
198
 
209
199
  ---
210
200
 
211
201
  ## 📄 License
212
202
 
213
- MIT © [seeyouin2x5x](https://github.com/seeyouin2x5x)
203
+ MIT © [VibezCheck](https://vibezcheck.app)
@@ -1,5 +1,5 @@
1
- import { b as CircuitBreakerOptions, C as CustomerParam, U as UsageEvent } from '../types-DCuzLVyc.mjs';
2
- import { V as VibezMeter } from '../client-C67DW_tR.mjs';
1
+ import { c as CircuitBreakerOptions, C as CustomerParam, B as BillingConfig, P as PricingConfig, d as InlineRateConfig, U as UsageEvent } from '../types-Zbzxg-Ka.mjs';
2
+ import { V as VibezMeter } from '../client--iq93FQg.mjs';
3
3
  import 'stripe';
4
4
 
5
5
  interface WithBillingOptions extends CircuitBreakerOptions {
@@ -7,6 +7,16 @@ interface WithBillingOptions extends CircuitBreakerOptions {
7
7
  customer?: CustomerParam;
8
8
  /** Direct Stripe customer ID */
9
9
  customerId?: string;
10
+ /** Billing mode configuration (postpaid vs prepaid) */
11
+ billing?: BillingConfig;
12
+ /** Profit margin & minimum charge configuration */
13
+ pricing?: PricingConfig;
14
+ /** 1-line inline pricing rate card */
15
+ rate?: InlineRateConfig;
16
+ /** Whether to capture tokens if the client aborts or closes tab mid-stream (default: true) */
17
+ captureOnAbort?: boolean;
18
+ /** Execution runtime environment (default: 'auto') */
19
+ runtime?: 'auto' | 'serverless' | 'edge' | 'node';
10
20
  /** Stripe API Key override (uses STRIPE_SECRET_KEY env by default) */
11
21
  stripeApiKey?: string;
12
22
  /** Existing VibezMeter instance (optional) */
@@ -21,9 +31,11 @@ interface WithBillingOptions extends CircuitBreakerOptions {
21
31
  /**
22
32
  * Wraps any Vercel AI SDK LanguageModel (v2 or v3) with automated Stripe billing, token metering, and agent circuit breakers.
23
33
  *
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, sends Stripe meter events, and enforces budget guardrails
34
+ * Sane Defaults Built-In:
35
+ * - $0.50 safety ceiling per call (overridable)
36
+ * - Automatic in-flight token capture on abort
37
+ * - Automatic prompt caching discount parsing
38
+ * - Serverless lifecycle preservation
27
39
  */
28
40
  declare function withBilling<T extends object>(model: T, options?: WithBillingOptions): T;
29
41
  /**
@@ -37,6 +49,24 @@ interface VibezCheckModelOptions extends WithBillingOptions {
37
49
  /** AI Gateway / OpenAI Base URL override */
38
50
  baseURL?: string;
39
51
  }
52
+ interface VibezSessionOptions {
53
+ customer?: CustomerParam;
54
+ stripeApiKey?: string;
55
+ pricing?: WithBillingOptions['pricing'];
56
+ billing?: WithBillingOptions['billing'];
57
+ metadata?: Record<string, string | number | boolean>;
58
+ }
59
+ interface VibezSession {
60
+ /** Creates a metered model bound to this session customer */
61
+ model: (modelOrId: any, options?: VibezCheckModelOptions) => any;
62
+ /** Tracks a non-LLM tool execution cost (e.g. search, scraper, image gen) */
63
+ trackTool: (name: string, options: {
64
+ costUSD: number;
65
+ metadata?: Record<string, any>;
66
+ }) => Promise<void>;
67
+ /** Underlying meter instance */
68
+ meter: VibezMeter;
69
+ }
40
70
  /**
41
71
  * Creates or resolves an AI SDK compatible LanguageModel with built-in VibezCheck billing & metering.
42
72
  *
@@ -53,18 +83,21 @@ interface VibezCheckModelOptions extends WithBillingOptions {
53
83
  *
54
84
  * // 2. Works with all Vercel AI SDK primitives (streamText, generateObject, streamObject):
55
85
  * const result = streamText({
56
- * model: vibezcheck('gpt-4o', { customer: 'alex@example.com' }),
57
- * messages,
58
- * });
59
- *
60
- * // 3. Wrap existing provider instances:
61
- * import { openai } from '@ai-sdk/openai';
62
- * const result = streamText({
63
- * model: vibezcheck(openai('gpt-4o-mini'), { customer: 'alex@example.com' }),
86
+ * model: vibezcheck('gpt-4o', {
87
+ * customer: 'alex@example.com',
88
+ * pricing: { margin: 1.5 }, // 50% profit margin
89
+ * }),
64
90
  * messages,
65
91
  * });
66
92
  * ```
67
93
  */
68
94
  declare function createVibezModel(modelOrId: any, options?: VibezCheckModelOptions): any;
95
+ /**
96
+ * Creates a scoped session for unified multi-call and tool tracking.
97
+ */
98
+ declare function createVibezSession(sessionOptions?: VibezSessionOptions): VibezSession;
99
+ declare const vibezcheck: typeof createVibezModel & {
100
+ session: typeof createVibezSession;
101
+ };
69
102
 
70
- export { type VibezCheckModelOptions, type WithBillingOptions, createVibezModel, meteredModel, withBilling };
103
+ export { type VibezCheckModelOptions, type VibezSession, type VibezSessionOptions, type WithBillingOptions, createVibezModel, createVibezSession, meteredModel, vibezcheck, withBilling };
@@ -1,5 +1,5 @@
1
- import { b as CircuitBreakerOptions, C as CustomerParam, U as UsageEvent } from '../types-DCuzLVyc.js';
2
- import { V as VibezMeter } from '../client-S3qmTXTR.js';
1
+ import { c as CircuitBreakerOptions, C as CustomerParam, B as BillingConfig, P as PricingConfig, d as InlineRateConfig, U as UsageEvent } from '../types-Zbzxg-Ka.js';
2
+ import { V as VibezMeter } from '../client-kJN_Znan.js';
3
3
  import 'stripe';
4
4
 
5
5
  interface WithBillingOptions extends CircuitBreakerOptions {
@@ -7,6 +7,16 @@ interface WithBillingOptions extends CircuitBreakerOptions {
7
7
  customer?: CustomerParam;
8
8
  /** Direct Stripe customer ID */
9
9
  customerId?: string;
10
+ /** Billing mode configuration (postpaid vs prepaid) */
11
+ billing?: BillingConfig;
12
+ /** Profit margin & minimum charge configuration */
13
+ pricing?: PricingConfig;
14
+ /** 1-line inline pricing rate card */
15
+ rate?: InlineRateConfig;
16
+ /** Whether to capture tokens if the client aborts or closes tab mid-stream (default: true) */
17
+ captureOnAbort?: boolean;
18
+ /** Execution runtime environment (default: 'auto') */
19
+ runtime?: 'auto' | 'serverless' | 'edge' | 'node';
10
20
  /** Stripe API Key override (uses STRIPE_SECRET_KEY env by default) */
11
21
  stripeApiKey?: string;
12
22
  /** Existing VibezMeter instance (optional) */
@@ -21,9 +31,11 @@ interface WithBillingOptions extends CircuitBreakerOptions {
21
31
  /**
22
32
  * Wraps any Vercel AI SDK LanguageModel (v2 or v3) with automated Stripe billing, token metering, and agent circuit breakers.
23
33
  *
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, sends Stripe meter events, and enforces budget guardrails
34
+ * Sane Defaults Built-In:
35
+ * - $0.50 safety ceiling per call (overridable)
36
+ * - Automatic in-flight token capture on abort
37
+ * - Automatic prompt caching discount parsing
38
+ * - Serverless lifecycle preservation
27
39
  */
28
40
  declare function withBilling<T extends object>(model: T, options?: WithBillingOptions): T;
29
41
  /**
@@ -37,6 +49,24 @@ interface VibezCheckModelOptions extends WithBillingOptions {
37
49
  /** AI Gateway / OpenAI Base URL override */
38
50
  baseURL?: string;
39
51
  }
52
+ interface VibezSessionOptions {
53
+ customer?: CustomerParam;
54
+ stripeApiKey?: string;
55
+ pricing?: WithBillingOptions['pricing'];
56
+ billing?: WithBillingOptions['billing'];
57
+ metadata?: Record<string, string | number | boolean>;
58
+ }
59
+ interface VibezSession {
60
+ /** Creates a metered model bound to this session customer */
61
+ model: (modelOrId: any, options?: VibezCheckModelOptions) => any;
62
+ /** Tracks a non-LLM tool execution cost (e.g. search, scraper, image gen) */
63
+ trackTool: (name: string, options: {
64
+ costUSD: number;
65
+ metadata?: Record<string, any>;
66
+ }) => Promise<void>;
67
+ /** Underlying meter instance */
68
+ meter: VibezMeter;
69
+ }
40
70
  /**
41
71
  * Creates or resolves an AI SDK compatible LanguageModel with built-in VibezCheck billing & metering.
42
72
  *
@@ -53,18 +83,21 @@ interface VibezCheckModelOptions extends WithBillingOptions {
53
83
  *
54
84
  * // 2. Works with all Vercel AI SDK primitives (streamText, generateObject, streamObject):
55
85
  * const result = streamText({
56
- * model: vibezcheck('gpt-4o', { customer: 'alex@example.com' }),
57
- * messages,
58
- * });
59
- *
60
- * // 3. Wrap existing provider instances:
61
- * import { openai } from '@ai-sdk/openai';
62
- * const result = streamText({
63
- * model: vibezcheck(openai('gpt-4o-mini'), { customer: 'alex@example.com' }),
86
+ * model: vibezcheck('gpt-4o', {
87
+ * customer: 'alex@example.com',
88
+ * pricing: { margin: 1.5 }, // 50% profit margin
89
+ * }),
64
90
  * messages,
65
91
  * });
66
92
  * ```
67
93
  */
68
94
  declare function createVibezModel(modelOrId: any, options?: VibezCheckModelOptions): any;
95
+ /**
96
+ * Creates a scoped session for unified multi-call and tool tracking.
97
+ */
98
+ declare function createVibezSession(sessionOptions?: VibezSessionOptions): VibezSession;
99
+ declare const vibezcheck: typeof createVibezModel & {
100
+ session: typeof createVibezSession;
101
+ };
69
102
 
70
- export { type VibezCheckModelOptions, type WithBillingOptions, createVibezModel, meteredModel, withBilling };
103
+ export { type VibezCheckModelOptions, type VibezSession, type VibezSessionOptions, type WithBillingOptions, createVibezModel, createVibezSession, meteredModel, vibezcheck, withBilling };