vibezcheck 0.1.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 +138 -144
- 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 +206 -0
- package/dist/react/index.d.ts +206 -0
- package/dist/react/index.js +1019 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +985 -0
- package/dist/react/index.mjs.map +1 -0
- 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 +23 -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,191 +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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
### B. Autonomous Paywall & Top-Up Modal (`<VibezBillingModal />`)
|
|
126
|
+
Pops up an in-app Stripe Checkout modal whenever a customer reaches their credit limit:
|
|
127
|
+
|
|
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
|
+
/>
|
|
127
141
|
```
|
|
128
142
|
|
|
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
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
|
-
|
|
169
|
-
|
|
151
|
+
const vz = vibezcheck();
|
|
152
|
+
|
|
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..."
|
|
170
159
|
```
|
|
171
160
|
|
|
172
|
-
|
|
173
|
-
```
|
|
174
|
-
{
|
|
175
|
-
|
|
176
|
-
"
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
"model": "anthropic/claude-3-7-sonnet",
|
|
180
|
-
"token_type": "output_thinking"
|
|
181
|
-
}
|
|
182
|
-
}
|
|
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
|
+
});
|
|
183
168
|
```
|
|
184
169
|
|
|
185
170
|
---
|
|
186
171
|
|
|
187
|
-
##
|
|
188
|
-
|
|
189
|
-
`vibezcheck` ships with default rates for all active frontier models:
|
|
190
|
-
|
|
191
|
-
```typescript
|
|
192
|
-
import { calculateCost } from 'vibezcheck/pricing';
|
|
172
|
+
## 📊 Live Telemetry Payload Structure
|
|
193
173
|
|
|
194
|
-
|
|
195
|
-
model: 'claude-3-7-sonnet',
|
|
196
|
-
inputTokens: 2000,
|
|
197
|
-
outputTokens: 800,
|
|
198
|
-
reasoningTokens: 1200, // thinking tokens
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
console.log(cost);
|
|
202
|
-
```
|
|
174
|
+
Every inference event emitted by `onUsage` captures complete token and cost economics:
|
|
203
175
|
|
|
204
|
-
#### 🖥️ Response:
|
|
205
176
|
```json
|
|
206
177
|
{
|
|
207
|
-
"
|
|
208
|
-
"
|
|
209
|
-
"
|
|
210
|
-
"
|
|
211
|
-
"
|
|
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
|
+
}
|
|
212
194
|
}
|
|
213
195
|
```
|
|
214
196
|
|
|
215
197
|
---
|
|
216
198
|
|
|
199
|
+
## 📜 Supported Models (Auto-Priced)
|
|
200
|
+
|
|
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()` | ✅ | ✅ |
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
217
211
|
## 📄 License
|
|
218
212
|
|
|
219
|
-
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 };
|