vibezcheck 0.2.0 → 0.3.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 +135 -191
- package/bin/vibezcheck.js +4 -0
- package/dist/ai-sdk/index.d.mts +43 -7
- package/dist/ai-sdk/index.d.ts +43 -7
- package/dist/ai-sdk/index.js +115 -55
- package/dist/ai-sdk/index.js.map +1 -1
- package/dist/ai-sdk/index.mjs +121 -55
- package/dist/ai-sdk/index.mjs.map +1 -1
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +232 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/index.mjs +209 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/{client-MJ3tl7bz.d.mts → client-C67DW_tR.d.mts} +1 -1
- package/dist/{client-txrE0D_D.d.ts → client-S3qmTXTR.d.ts} +1 -1
- package/dist/index.d.mts +49 -26
- package/dist/index.d.ts +49 -26
- package/dist/index.js +136 -94
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +141 -94
- 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/pricing/index.d.mts +1 -1
- package/dist/pricing/index.d.ts +1 -1
- package/dist/react/index.d.mts +70 -18
- package/dist/react/index.d.ts +70 -18
- package/dist/react/index.js +345 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +346 -3
- package/dist/react/index.mjs.map +1 -1
- package/dist/{types-CSrSmsd1.d.mts → types-DCuzLVyc.d.mts} +48 -3
- package/dist/{types-CSrSmsd1.d.ts → types-DCuzLVyc.d.ts} +48 -3
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# ⚡ vibezcheck
|
|
2
2
|
|
|
3
|
-
> **The 1-
|
|
4
|
-
> Track tokens, compute real-time
|
|
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.
|
|
5
5
|
|
|
6
6
|
[](https://npmjs.org/package/vibezcheck)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -11,11 +11,12 @@
|
|
|
11
11
|
|
|
12
12
|
## 🚀 Why vibezcheck?
|
|
13
13
|
|
|
14
|
-
* **⚡ 0ms Added Latency**: Streams pass straight through to the browser with zero buffering.
|
|
15
|
-
* **🧠
|
|
16
|
-
* **💰 Built-in Cost
|
|
17
|
-
* **🆓 Zero-Config Local Mode**: Works 100% free in development with no Stripe account
|
|
18
|
-
* **💳 1-Line Stripe Billing**: Turn an AI prototype into a
|
|
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 />`).
|
|
19
20
|
|
|
20
21
|
---
|
|
21
22
|
|
|
@@ -29,241 +30,184 @@ pnpm add vibezcheck stripe
|
|
|
29
30
|
|
|
30
31
|
---
|
|
31
32
|
|
|
32
|
-
##
|
|
33
|
+
## ⚡ 1. Declarative Vercel AI SDK Integration
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
### Feature 1: Local Token & Cost Tracking (Free / No Stripe Required)
|
|
35
|
+
`vibezcheck` wraps any model string or provider instance into a fully compliant Vercel AI SDK model:
|
|
37
36
|
|
|
38
|
-
|
|
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
|
+
```
|
|
39
49
|
|
|
40
|
-
|
|
50
|
+
### B. Streaming AI Route (`streamText`)
|
|
41
51
|
```typescript
|
|
42
52
|
// app/api/chat/route.ts
|
|
43
|
-
import {
|
|
44
|
-
import
|
|
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
|
-
});
|
|
53
|
+
import { streamText } from "ai";
|
|
54
|
+
import { vibezcheck } from "vibezcheck";
|
|
56
55
|
|
|
57
56
|
export async function POST(req: Request) {
|
|
58
57
|
const { messages } = await req.json();
|
|
59
58
|
|
|
60
|
-
|
|
61
|
-
model:
|
|
59
|
+
return streamText({
|
|
60
|
+
model: vibezcheck("gpt-4o-mini", { customer: "alex@example.com" }),
|
|
62
61
|
messages,
|
|
63
|
-
|
|
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));
|
|
62
|
+
}).toTextStreamResponse();
|
|
69
63
|
}
|
|
70
64
|
```
|
|
71
65
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
### C. Direct `createOpenAI` Connection
|
|
67
|
+
You can pass custom OpenAI / Gateway instances directly into `vibezcheck()`:
|
|
68
|
+
```typescript
|
|
69
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
70
|
+
import { streamText } from "ai";
|
|
71
|
+
import { vibezcheck } from "vibezcheck";
|
|
77
72
|
|
|
78
|
-
|
|
79
|
-
|
|
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
|
+
});
|
|
80
77
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
export async function POST(req: Request) {
|
|
79
|
+
const { messages } = await req.json();
|
|
80
|
+
|
|
81
|
+
return streamText({
|
|
82
|
+
model: vibezcheck(openai("gpt-4o-mini"), { customer: "alex@example.com" }),
|
|
83
|
+
messages,
|
|
84
|
+
}).toTextStreamResponse();
|
|
85
|
+
}
|
|
86
86
|
```
|
|
87
87
|
|
|
88
88
|
---
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
## ⚛️ 2. Declarative React UI & Hooks (`vibezcheck/react`)
|
|
91
91
|
|
|
92
|
-
|
|
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:
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
import { withBilling } from 'vibezcheck';
|
|
98
|
-
import { openai } from '@ai-sdk/openai';
|
|
99
|
-
import { streamText } from 'ai';
|
|
95
|
+
```tsx
|
|
96
|
+
'use client';
|
|
97
|
+
import { useVibezChat, VibezSessionWidget, VibezBillingModal } from 'vibezcheck/react';
|
|
100
98
|
|
|
101
|
-
export
|
|
102
|
-
const { messages,
|
|
103
|
-
|
|
104
|
-
|
|
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,
|
|
99
|
+
export default function ChatPage() {
|
|
100
|
+
const { messages, input, handleInputChange, handleSubmit, isLoading } = useVibezChat({
|
|
101
|
+
model: 'gpt-4o-mini',
|
|
102
|
+
customer: 'alex@example.com',
|
|
111
103
|
});
|
|
112
104
|
|
|
113
|
-
return
|
|
105
|
+
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>
|
|
116
|
+
</form>
|
|
117
|
+
|
|
118
|
+
{/* Live Token & Dollar Tracker Widget */}
|
|
119
|
+
<VibezSessionWidget theme="light" position="bottom-right" />
|
|
120
|
+
</main>
|
|
121
|
+
);
|
|
114
122
|
}
|
|
115
123
|
```
|
|
116
124
|
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
```
|
|
125
|
+
### B. Autonomous Paywall & Top-Up Modal (`<VibezBillingModal />`)
|
|
126
|
+
Pops up an in-app Stripe Checkout modal whenever a customer reaches their credit limit:
|
|
128
127
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
{
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
}
|
|
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
|
+
/>
|
|
144
141
|
```
|
|
145
|
-
3. **Invoice Updated**: Stripe increments Alex's monthly usage bill or deducts \$0.016 from their prepaid credit balance.
|
|
146
142
|
|
|
147
143
|
---
|
|
148
144
|
|
|
149
|
-
|
|
145
|
+
## 💳 3. Stripe Sandbox & Customer Provisioning
|
|
150
146
|
|
|
147
|
+
### A. Auto Customer Provisioning in 1 Line:
|
|
151
148
|
```typescript
|
|
152
|
-
import {
|
|
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
|
-
});
|
|
149
|
+
import { vibezcheck } from "vibezcheck";
|
|
166
150
|
|
|
167
|
-
|
|
168
|
-
return meter.wrapStream(stream, { customerId });
|
|
169
|
-
}
|
|
170
|
-
```
|
|
151
|
+
const vz = vibezcheck();
|
|
171
152
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
"value": "1840",
|
|
179
|
-
"model": "anthropic/claude-3-7-sonnet",
|
|
180
|
-
"token_type": "output_thinking"
|
|
181
|
-
}
|
|
182
|
-
}
|
|
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..."
|
|
183
159
|
```
|
|
184
160
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
```tsx
|
|
193
|
-
import { VibezSessionProvider, VibezSessionWidget } from 'vibezcheck/react';
|
|
194
|
-
|
|
195
|
-
export default function App() {
|
|
196
|
-
return (
|
|
197
|
-
<VibezSessionProvider persist="sessionStorage">
|
|
198
|
-
<ChatInterface />
|
|
199
|
-
|
|
200
|
-
{/* Drop-in floating pill widget showing live session tokens & cost */}
|
|
201
|
-
<VibezSessionWidget position="bottom-right" showReasoning theme="dark" />
|
|
202
|
-
</VibezSessionProvider>
|
|
203
|
-
);
|
|
204
|
-
}
|
|
161
|
+
### B. 1-Line Stripe Checkout Session:
|
|
162
|
+
```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
|
+
});
|
|
205
168
|
```
|
|
206
169
|
|
|
207
|
-
|
|
208
|
-
```tsx
|
|
209
|
-
import { useChat } from 'ai/react';
|
|
210
|
-
import { useVibezSession, VibezSessionBadge } from 'vibezcheck/react';
|
|
170
|
+
---
|
|
211
171
|
|
|
212
|
-
|
|
213
|
-
const { recordTurn, sessionUsage, sessionCost } = useVibezSession();
|
|
172
|
+
## 📊 Live Telemetry Payload Structure
|
|
214
173
|
|
|
215
|
-
|
|
216
|
-
onFinish: (message, { usage }) => {
|
|
217
|
-
// 1 line: accumulates tokens & calculates real-time USD costs in React state
|
|
218
|
-
recordTurn({ model: 'gpt-5.6-sol', usage });
|
|
219
|
-
},
|
|
220
|
-
});
|
|
174
|
+
Every inference event emitted by `onUsage` captures complete token and cost economics:
|
|
221
175
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
+
}
|
|
232
194
|
}
|
|
233
195
|
```
|
|
234
196
|
|
|
235
197
|
---
|
|
236
198
|
|
|
237
|
-
##
|
|
238
|
-
|
|
239
|
-
`vibezcheck` ships with default rates for all active frontier models:
|
|
240
|
-
|
|
241
|
-
```typescript
|
|
242
|
-
import { calculateCost } from 'vibezcheck/pricing';
|
|
243
|
-
|
|
244
|
-
const cost = calculateCost({
|
|
245
|
-
model: 'claude-3-7-sonnet',
|
|
246
|
-
inputTokens: 2000,
|
|
247
|
-
outputTokens: 800,
|
|
248
|
-
reasoningTokens: 1200, // thinking tokens
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
console.log(cost);
|
|
252
|
-
```
|
|
199
|
+
## 📜 Supported Models (Auto-Priced)
|
|
253
200
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
"currency": "USD"
|
|
262
|
-
}
|
|
263
|
-
```
|
|
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()` | ✅ | ✅ |
|
|
264
208
|
|
|
265
209
|
---
|
|
266
210
|
|
|
267
211
|
## 📄 License
|
|
268
212
|
|
|
269
|
-
MIT © [
|
|
213
|
+
MIT © [seeyouin2x5x](https://github.com/seeyouin2x5x)
|
package/dist/ai-sdk/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as CustomerParam, U as UsageEvent } from '../types-
|
|
2
|
-
import { V as VibezMeter } from '../client-
|
|
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';
|
|
3
3
|
import 'stripe';
|
|
4
4
|
|
|
5
|
-
interface WithBillingOptions {
|
|
5
|
+
interface WithBillingOptions extends CircuitBreakerOptions {
|
|
6
6
|
/** Customer email, user ID, or Stripe customer ID */
|
|
7
7
|
customer?: CustomerParam;
|
|
8
8
|
/** Direct Stripe customer ID */
|
|
@@ -19,16 +19,52 @@ interface WithBillingOptions {
|
|
|
19
19
|
metadata?: Record<string, string | number | boolean>;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* Wraps any Vercel AI SDK LanguageModel (v2 or v3) with automated Stripe billing and
|
|
22
|
+
* Wraps any Vercel AI SDK LanguageModel (v2 or v3) with automated Stripe billing, token metering, and agent circuit breakers.
|
|
23
23
|
*
|
|
24
24
|
* @param model - The Vercel AI SDK language model instance (e.g. openai('gpt-5.6-sol'), anthropic('claude-3-7-sonnet'))
|
|
25
25
|
* @param options - Billing & customer configuration
|
|
26
|
-
* @returns Decorated LanguageModel that automatically meters tokens
|
|
26
|
+
* @returns Decorated LanguageModel that automatically meters tokens, sends Stripe meter events, and enforces budget guardrails
|
|
27
27
|
*/
|
|
28
28
|
declare function withBilling<T extends object>(model: T, options?: WithBillingOptions): T;
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* Convenient alias for withBilling
|
|
31
31
|
*/
|
|
32
32
|
declare const meteredModel: typeof withBilling;
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
interface VibezCheckModelOptions extends WithBillingOptions {
|
|
35
|
+
/** OpenAI / AI Gateway API Key override */
|
|
36
|
+
apiKey?: string;
|
|
37
|
+
/** AI Gateway / OpenAI Base URL override */
|
|
38
|
+
baseURL?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates or resolves an AI SDK compatible LanguageModel with built-in VibezCheck billing & metering.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { generateText, streamText } from 'ai';
|
|
46
|
+
* import { vibezcheck } from 'vibezcheck';
|
|
47
|
+
*
|
|
48
|
+
* // 1. Declarative string model identifier:
|
|
49
|
+
* const { text } = await generateText({
|
|
50
|
+
* model: vibezcheck('openai/gpt-4o-mini', { customer: 'alex@example.com' }),
|
|
51
|
+
* prompt: 'What is love?',
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* // 2. Works with all Vercel AI SDK primitives (streamText, generateObject, streamObject):
|
|
55
|
+
* 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' }),
|
|
64
|
+
* messages,
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
declare function createVibezModel(modelOrId: any, options?: VibezCheckModelOptions): any;
|
|
69
|
+
|
|
70
|
+
export { type VibezCheckModelOptions, type WithBillingOptions, createVibezModel, meteredModel, withBilling };
|
package/dist/ai-sdk/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as CustomerParam, U as UsageEvent } from '../types-
|
|
2
|
-
import { V as VibezMeter } from '../client-
|
|
1
|
+
import { b as CircuitBreakerOptions, C as CustomerParam, U as UsageEvent } from '../types-DCuzLVyc.js';
|
|
2
|
+
import { V as VibezMeter } from '../client-S3qmTXTR.js';
|
|
3
3
|
import 'stripe';
|
|
4
4
|
|
|
5
|
-
interface WithBillingOptions {
|
|
5
|
+
interface WithBillingOptions extends CircuitBreakerOptions {
|
|
6
6
|
/** Customer email, user ID, or Stripe customer ID */
|
|
7
7
|
customer?: CustomerParam;
|
|
8
8
|
/** Direct Stripe customer ID */
|
|
@@ -19,16 +19,52 @@ interface WithBillingOptions {
|
|
|
19
19
|
metadata?: Record<string, string | number | boolean>;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* Wraps any Vercel AI SDK LanguageModel (v2 or v3) with automated Stripe billing and
|
|
22
|
+
* Wraps any Vercel AI SDK LanguageModel (v2 or v3) with automated Stripe billing, token metering, and agent circuit breakers.
|
|
23
23
|
*
|
|
24
24
|
* @param model - The Vercel AI SDK language model instance (e.g. openai('gpt-5.6-sol'), anthropic('claude-3-7-sonnet'))
|
|
25
25
|
* @param options - Billing & customer configuration
|
|
26
|
-
* @returns Decorated LanguageModel that automatically meters tokens
|
|
26
|
+
* @returns Decorated LanguageModel that automatically meters tokens, sends Stripe meter events, and enforces budget guardrails
|
|
27
27
|
*/
|
|
28
28
|
declare function withBilling<T extends object>(model: T, options?: WithBillingOptions): T;
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* Convenient alias for withBilling
|
|
31
31
|
*/
|
|
32
32
|
declare const meteredModel: typeof withBilling;
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
interface VibezCheckModelOptions extends WithBillingOptions {
|
|
35
|
+
/** OpenAI / AI Gateway API Key override */
|
|
36
|
+
apiKey?: string;
|
|
37
|
+
/** AI Gateway / OpenAI Base URL override */
|
|
38
|
+
baseURL?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates or resolves an AI SDK compatible LanguageModel with built-in VibezCheck billing & metering.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { generateText, streamText } from 'ai';
|
|
46
|
+
* import { vibezcheck } from 'vibezcheck';
|
|
47
|
+
*
|
|
48
|
+
* // 1. Declarative string model identifier:
|
|
49
|
+
* const { text } = await generateText({
|
|
50
|
+
* model: vibezcheck('openai/gpt-4o-mini', { customer: 'alex@example.com' }),
|
|
51
|
+
* prompt: 'What is love?',
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* // 2. Works with all Vercel AI SDK primitives (streamText, generateObject, streamObject):
|
|
55
|
+
* 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' }),
|
|
64
|
+
* messages,
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
declare function createVibezModel(modelOrId: any, options?: VibezCheckModelOptions): any;
|
|
69
|
+
|
|
70
|
+
export { type VibezCheckModelOptions, type WithBillingOptions, createVibezModel, meteredModel, withBilling };
|