vibezcheck 0.2.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 +131 -197
- package/bin/vibezcheck.js +4 -0
- package/dist/ai-sdk/index.d.mts +78 -9
- package/dist/ai-sdk/index.d.ts +78 -9
- package/dist/ai-sdk/index.js +278 -64
- package/dist/ai-sdk/index.js.map +1 -1
- package/dist/ai-sdk/index.mjs +282 -64
- 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--iq93FQg.d.mts} +1 -1
- package/dist/{client-txrE0D_D.d.ts → client-kJN_Znan.d.ts} +1 -1
- package/dist/index.d.mts +50 -26
- package/dist/index.d.ts +50 -26
- package/dist/index.js +299 -104
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +303 -104
- 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 +28 -7
- package/dist/meter/index.js.map +1 -1
- package/dist/meter/index.mjs +28 -7
- package/dist/meter/index.mjs.map +1 -1
- package/dist/pricing/index.d.mts +8 -2
- package/dist/pricing/index.d.ts +8 -2
- package/dist/pricing/index.js +28 -7
- package/dist/pricing/index.js.map +1 -1
- package/dist/pricing/index.mjs +28 -7
- package/dist/pricing/index.mjs.map +1 -1
- package/dist/react/index.d.mts +95 -17
- package/dist/react/index.d.ts +95 -17
- package/dist/react/index.js +468 -7
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +468 -10
- package/dist/react/index.mjs.map +1 -1
- package/dist/types-Zbzxg-Ka.d.mts +261 -0
- package/dist/types-Zbzxg-Ka.d.ts +261 -0
- package/package.json +6 -2
- package/dist/types-CSrSmsd1.d.mts +0 -159
- package/dist/types-CSrSmsd1.d.ts +0 -159
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import Stripe from 'stripe';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Known supported model identifiers with full IDE autocomplete
|
|
5
|
+
*/
|
|
6
|
+
type SupportedOpenAIModel = 'openai/gpt-4o' | 'openai/gpt-4o-mini' | 'openai/o1' | 'openai/o1-mini' | 'openai/o3' | 'openai/o3-mini' | 'openai/gpt-5' | 'openai/gpt-5-mini' | 'openai/gpt-5.6-sol' | 'openai/gpt-5.6-terra' | 'openai/gpt-5.6-luna' | 'gpt-4o' | 'gpt-4o-mini' | 'o1' | 'o1-mini' | 'o3' | 'o3-mini' | 'gpt-5' | 'gpt-5-mini' | 'gpt-5.6-sol' | 'gpt-5.6-terra' | 'gpt-5.6-luna';
|
|
7
|
+
type SupportedAnthropicModel = 'anthropic/claude-3-7-sonnet' | 'anthropic/claude-3-5-sonnet' | 'anthropic/claude-3-5-haiku' | 'anthropic/claude-opus-5' | 'anthropic/haiku-4.5' | 'claude-3-7-sonnet' | 'claude-3-5-sonnet' | 'claude-3-5-haiku' | 'claude-opus-5' | 'haiku-4.5';
|
|
8
|
+
type SupportedGoogleModel = 'google/gemini-2.0-flash' | 'google/gemini-1.5-pro' | 'google/gemini-3.7-flash' | 'google/gemini-3.1-pro' | 'gemini-2.0-flash' | 'gemini-1.5-pro' | 'gemini-3.7-flash' | 'gemini-3.1-pro';
|
|
9
|
+
type SupportedDeepSeekModel = 'deepseek/deepseek-chat' | 'deepseek/deepseek-reasoner' | 'deepseek/deepseek-v4-pro' | 'deepseek-chat' | 'deepseek-reasoner' | 'deepseek-v4-pro';
|
|
10
|
+
type KnownModel = SupportedOpenAIModel | SupportedAnthropicModel | SupportedGoogleModel | SupportedDeepSeekModel;
|
|
11
|
+
/**
|
|
12
|
+
* Union of all known model IDs with loose string fallback for custom / future models
|
|
13
|
+
*/
|
|
14
|
+
type SupportedModel = KnownModel | (string & {});
|
|
15
|
+
/**
|
|
16
|
+
* Detailed token usage breakdown
|
|
17
|
+
*/
|
|
18
|
+
interface TokenUsage {
|
|
19
|
+
/** Input/Prompt tokens */
|
|
20
|
+
inputTokens: number;
|
|
21
|
+
/** Total output/completion tokens (including reasoning) */
|
|
22
|
+
outputTokens: number;
|
|
23
|
+
/** Total tokens (input + output) */
|
|
24
|
+
totalTokens: number;
|
|
25
|
+
/** Hidden reasoning / thinking tokens (e.g. o1/o3/GPT-5, Claude 3.7 Thinking, Gemini 3.7 Thoughts) */
|
|
26
|
+
reasoningTokens?: number;
|
|
27
|
+
/** Visible output tokens (outputTokens - reasoningTokens) */
|
|
28
|
+
visibleOutputTokens?: number;
|
|
29
|
+
/** Cached input tokens read from KV cache / prompt cache */
|
|
30
|
+
cachedTokens?: number;
|
|
31
|
+
/** Cache write / creation tokens */
|
|
32
|
+
cacheWriteTokens?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Calculated inference cost breakdown
|
|
36
|
+
*/
|
|
37
|
+
interface InferenceCost {
|
|
38
|
+
/** Cost for standard input prompt tokens in USD */
|
|
39
|
+
inputCostUSD: number;
|
|
40
|
+
/** Cost for output completion tokens in USD */
|
|
41
|
+
outputCostUSD: number;
|
|
42
|
+
/** Cost for reasoning/thinking tokens in USD (if applicable) */
|
|
43
|
+
reasoningCostUSD?: number;
|
|
44
|
+
/** Savings from prompt caching in USD */
|
|
45
|
+
cachedDiscountUSD?: number;
|
|
46
|
+
/** Total computed base inference cost in USD */
|
|
47
|
+
totalUSD: number;
|
|
48
|
+
/** Retail price after developer markup (if markup applied) */
|
|
49
|
+
retailUSD?: number;
|
|
50
|
+
/** Currency (defaults to 'USD') */
|
|
51
|
+
currency: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Full usage event emitted upon completion of an LLM call or stream
|
|
55
|
+
*/
|
|
56
|
+
interface UsageEvent {
|
|
57
|
+
/** Unique ID for the event */
|
|
58
|
+
id?: string;
|
|
59
|
+
/** Timestamp ISO string */
|
|
60
|
+
timestamp: string;
|
|
61
|
+
/** Model name (e.g. 'gpt-5.6-sol', 'claude-3-7-sonnet') */
|
|
62
|
+
model: string;
|
|
63
|
+
/** Provider (e.g. 'openai', 'anthropic', 'google', 'mistral', 'groq', 'deepseek', 'generic') */
|
|
64
|
+
provider: string;
|
|
65
|
+
/** Token breakdown */
|
|
66
|
+
usage: TokenUsage;
|
|
67
|
+
/** Computed cost */
|
|
68
|
+
cost: InferenceCost;
|
|
69
|
+
/** Customer ID (Stripe customer ID, internal userId, or anonymous) */
|
|
70
|
+
customerId?: string;
|
|
71
|
+
/** Optional customer email */
|
|
72
|
+
customerEmail?: string;
|
|
73
|
+
/** Custom developer metadata (e.g. userId, orgId, feature, session) */
|
|
74
|
+
metadata?: Record<string, string | number | boolean>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Customer identification parameter: can be a string ('cus_xxx' or 'user@example.com') or an object
|
|
78
|
+
*/
|
|
79
|
+
type CustomerParam = string | {
|
|
80
|
+
id?: string;
|
|
81
|
+
userId?: string;
|
|
82
|
+
email?: string;
|
|
83
|
+
name?: string;
|
|
84
|
+
metadata?: Record<string, string>;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Event emitted when a circuit breaker budget or token limit is reached
|
|
88
|
+
*/
|
|
89
|
+
interface BudgetExceededEvent {
|
|
90
|
+
reason: 'cost_per_call_exceeded' | 'total_budget_exceeded' | 'max_tokens_exceeded';
|
|
91
|
+
limit: number;
|
|
92
|
+
current: number;
|
|
93
|
+
model: string;
|
|
94
|
+
customerId?: string;
|
|
95
|
+
message: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Error thrown when an Agent Circuit Breaker trips
|
|
99
|
+
*/
|
|
100
|
+
declare class VibezCircuitBreakerError extends Error {
|
|
101
|
+
readonly event: BudgetExceededEvent;
|
|
102
|
+
constructor(event: BudgetExceededEvent);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Circuit Breaker / Budget Guardrail Configuration
|
|
106
|
+
*/
|
|
107
|
+
interface CircuitBreakerOptions {
|
|
108
|
+
/** Maximum allowed USD cost for a single generation or stream (default: 0.50) */
|
|
109
|
+
maxCostPerCallUSD?: number;
|
|
110
|
+
/** Cumulative budget limit for customer/session in USD (e.g. 5.00) */
|
|
111
|
+
maxBudgetUSD?: number;
|
|
112
|
+
/** Hard ceiling on total tokens per generation (e.g. 10000) */
|
|
113
|
+
maxTokensPerCall?: number;
|
|
114
|
+
/** Model to gracefully fall back to if budget limit is exceeded instead of hard erroring */
|
|
115
|
+
fallbackModelOnBudget?: string;
|
|
116
|
+
/** Callback fired when circuit breaker trips */
|
|
117
|
+
onBudgetExceeded?: (event: BudgetExceededEvent) => void | Promise<void>;
|
|
118
|
+
/** Whether to throw a VibezCircuitBreakerError if limit exceeded (default: false) */
|
|
119
|
+
throwOnBudgetExceeded?: boolean;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Billing Configuration (Postpaid metered invoice vs Prepaid credit wallet)
|
|
123
|
+
*/
|
|
124
|
+
interface BillingConfig {
|
|
125
|
+
/** 'postpaid' = Invoiced at month's end; 'prepaid' = Deducted from credit wallet, locks at $0 */
|
|
126
|
+
mode?: 'postpaid' | 'prepaid';
|
|
127
|
+
/** Available prepaid credit balance in USD */
|
|
128
|
+
balanceUSD?: number;
|
|
129
|
+
/** Action when balance is low: 'warn' logs/sends event, 'throw' throws CreditExhaustedError */
|
|
130
|
+
onLowBalance?: 'warn' | 'throw';
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Profit Pricing & Markup Configuration
|
|
134
|
+
*/
|
|
135
|
+
interface PricingConfig {
|
|
136
|
+
/** Profit margin multiplier (e.g. 1.5 = Cost + 50% profit margin automatically added) */
|
|
137
|
+
margin?: number;
|
|
138
|
+
/** Minimum charge in USD for any single call (e.g. 0.01 = at least 1 cent) */
|
|
139
|
+
minimumChargeUSD?: number;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Inline Rate Card Configuration for 1-line custom/newly released model pricing
|
|
143
|
+
*/
|
|
144
|
+
interface InlineRateConfig {
|
|
145
|
+
/** Input tokens price per 1 Million tokens in USD */
|
|
146
|
+
in: number;
|
|
147
|
+
/** Output tokens price per 1 Million tokens in USD */
|
|
148
|
+
out?: number;
|
|
149
|
+
output?: number;
|
|
150
|
+
/** Reasoning/thinking tokens price per 1 Million tokens in USD (optional) */
|
|
151
|
+
reasoning?: number;
|
|
152
|
+
/** Cached input tokens price per 1 Million tokens in USD (optional) */
|
|
153
|
+
cached?: number;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Non-LLM Tool execution metering options
|
|
157
|
+
*/
|
|
158
|
+
interface ToolMeterOptions {
|
|
159
|
+
/** Fixed cost in USD for this tool execution (e.g. 0.01 for search, 0.04 for image) */
|
|
160
|
+
costUSD: number;
|
|
161
|
+
/** Customer identifier to attribute tool cost to */
|
|
162
|
+
customer?: CustomerParam;
|
|
163
|
+
/** Additional metadata */
|
|
164
|
+
metadata?: Record<string, string | number | boolean>;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Configuration options for the VibezCheck Meter
|
|
168
|
+
*/
|
|
169
|
+
interface MeterOptions extends CircuitBreakerOptions {
|
|
170
|
+
/** Stripe API Key (sk_* or rk_*). If omitted, runs in local telemetry/free mode */
|
|
171
|
+
apiKey?: string;
|
|
172
|
+
/** Existing Stripe SDK instance (optional) */
|
|
173
|
+
stripe?: Stripe;
|
|
174
|
+
/** Default Stripe Meter Event Name (default: 'token-billing-tokens') */
|
|
175
|
+
eventName?: string;
|
|
176
|
+
/** Batching options to optimize Stripe API calls */
|
|
177
|
+
batching?: {
|
|
178
|
+
/** Max events per batch (default: 50) */
|
|
179
|
+
maxBatchSize?: number;
|
|
180
|
+
/** Flush interval in milliseconds (default: 50ms) */
|
|
181
|
+
flushIntervalMs?: number;
|
|
182
|
+
};
|
|
183
|
+
/** Callback fired whenever usage is extracted (works with or without Stripe) */
|
|
184
|
+
onUsage?: (event: UsageEvent) => void | Promise<void>;
|
|
185
|
+
/** Error handler callback */
|
|
186
|
+
onError?: (error: Error, events: UsageEvent[]) => void;
|
|
187
|
+
/** Markup multiplier for retail price calculations (e.g. 1.3 for 30% profit) */
|
|
188
|
+
markupMultiplier?: number;
|
|
189
|
+
/** Enable debug console logging (default: false) */
|
|
190
|
+
debug?: boolean;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Stream wrap options
|
|
194
|
+
*/
|
|
195
|
+
interface StreamWrapOptions extends CircuitBreakerOptions {
|
|
196
|
+
/** Customer identifier or email or object */
|
|
197
|
+
customer?: CustomerParam;
|
|
198
|
+
/** Direct customer ID string */
|
|
199
|
+
customerId?: string;
|
|
200
|
+
/** Model override if not automatically detectable */
|
|
201
|
+
model?: string;
|
|
202
|
+
/** Provider override if not automatically detectable */
|
|
203
|
+
provider?: string;
|
|
204
|
+
/** Billing mode configuration (postpaid vs prepaid) */
|
|
205
|
+
billing?: BillingConfig;
|
|
206
|
+
/** Profit margin & minimum charge configuration */
|
|
207
|
+
pricing?: PricingConfig;
|
|
208
|
+
/** 1-line inline pricing rate card */
|
|
209
|
+
rate?: InlineRateConfig;
|
|
210
|
+
/** Whether to capture tokens if the client aborts or closes tab mid-stream (default: true) */
|
|
211
|
+
captureOnAbort?: boolean;
|
|
212
|
+
/** Execution runtime environment (default: 'auto') */
|
|
213
|
+
runtime?: 'auto' | 'serverless' | 'edge' | 'node';
|
|
214
|
+
/** Custom metadata attached to the usage event */
|
|
215
|
+
metadata?: Record<string, string | number | boolean>;
|
|
216
|
+
/** Custom usage callback for this specific stream */
|
|
217
|
+
onUsage?: (event: UsageEvent) => void | Promise<void>;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Direct usage recording options
|
|
221
|
+
*/
|
|
222
|
+
interface RecordUsageOptions {
|
|
223
|
+
model: string;
|
|
224
|
+
provider?: string;
|
|
225
|
+
inputTokens: number;
|
|
226
|
+
outputTokens: number;
|
|
227
|
+
reasoningTokens?: number;
|
|
228
|
+
cachedTokens?: number;
|
|
229
|
+
customer?: CustomerParam;
|
|
230
|
+
customerId?: string;
|
|
231
|
+
metadata?: Record<string, string | number | boolean>;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Model Pricing Rates (per 1 Million Tokens in USD)
|
|
235
|
+
*/
|
|
236
|
+
interface ModelPricingRates {
|
|
237
|
+
inputPer1M: number;
|
|
238
|
+
outputPer1M: number;
|
|
239
|
+
cachedInputPer1M?: number;
|
|
240
|
+
reasoningPer1M?: number;
|
|
241
|
+
cacheWritePer1M?: number;
|
|
242
|
+
currency?: string;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Aggregated Usage Summary
|
|
246
|
+
*/
|
|
247
|
+
interface UsageSummary {
|
|
248
|
+
totalRequests: number;
|
|
249
|
+
totalTokens: number;
|
|
250
|
+
totalInputTokens: number;
|
|
251
|
+
totalOutputTokens: number;
|
|
252
|
+
totalReasoningTokens: number;
|
|
253
|
+
totalCostUSD: number;
|
|
254
|
+
byModel: Record<string, {
|
|
255
|
+
requests: number;
|
|
256
|
+
tokens: number;
|
|
257
|
+
costUSD: number;
|
|
258
|
+
}>;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export { type BillingConfig as B, type CustomerParam as C, type InferenceCost as I, type KnownModel as K, type MeterOptions as M, type PricingConfig as P, type RecordUsageOptions as R, type StreamWrapOptions as S, type TokenUsage as T, type UsageEvent as U, VibezCircuitBreakerError as V, type UsageSummary as a, type BudgetExceededEvent as b, type CircuitBreakerOptions as c, type InlineRateConfig as d, type ModelPricingRates as e, type SupportedAnthropicModel as f, type SupportedDeepSeekModel as g, type SupportedGoogleModel as h, type SupportedModel as i, type SupportedOpenAIModel as j, type ToolMeterOptions as k };
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vibezcheck",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "The 1-line Stripe Billing and Token Metering engine for LLMs. Track tokens, compute real-time dollar costs, and bill customers with 0ms added latency.",
|
|
5
5
|
"author": "VibezCheck <dev@vibezcheck.xyz> (https://vibezcheck.xyz)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/seeyouin2x5x/vibezcheck-sdk.git"
|
|
9
|
+
"url": "git+https://github.com/seeyouin2x5x/vibezcheck-sdk.git"
|
|
10
10
|
},
|
|
11
11
|
"keywords": [
|
|
12
12
|
"stripe",
|
|
@@ -71,8 +71,12 @@
|
|
|
71
71
|
"require": "./dist/react/index.js"
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
|
+
"bin": {
|
|
75
|
+
"vibezcheck": "./bin/vibezcheck.js"
|
|
76
|
+
},
|
|
74
77
|
"files": [
|
|
75
78
|
"dist",
|
|
79
|
+
"bin",
|
|
76
80
|
"README.md",
|
|
77
81
|
"LICENSE",
|
|
78
82
|
"package.json"
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import Stripe from 'stripe';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Detailed token usage breakdown
|
|
5
|
-
*/
|
|
6
|
-
interface TokenUsage {
|
|
7
|
-
/** Input/Prompt tokens */
|
|
8
|
-
inputTokens: number;
|
|
9
|
-
/** Total output/completion tokens (including reasoning) */
|
|
10
|
-
outputTokens: number;
|
|
11
|
-
/** Total tokens (input + output) */
|
|
12
|
-
totalTokens: number;
|
|
13
|
-
/** Hidden reasoning / thinking tokens (e.g. o1/o3/GPT-5, Claude 3.7 Thinking, Gemini 3.7 Thoughts) */
|
|
14
|
-
reasoningTokens?: number;
|
|
15
|
-
/** Visible output tokens (outputTokens - reasoningTokens) */
|
|
16
|
-
visibleOutputTokens?: number;
|
|
17
|
-
/** Cached input tokens read from KV cache / prompt cache */
|
|
18
|
-
cachedTokens?: number;
|
|
19
|
-
/** Cache write / creation tokens */
|
|
20
|
-
cacheWriteTokens?: number;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Calculated inference cost breakdown
|
|
24
|
-
*/
|
|
25
|
-
interface InferenceCost {
|
|
26
|
-
/** Cost for standard input prompt tokens in USD */
|
|
27
|
-
inputCostUSD: number;
|
|
28
|
-
/** Cost for output completion tokens in USD */
|
|
29
|
-
outputCostUSD: number;
|
|
30
|
-
/** Cost for reasoning/thinking tokens in USD (if applicable) */
|
|
31
|
-
reasoningCostUSD?: number;
|
|
32
|
-
/** Savings from prompt caching in USD */
|
|
33
|
-
cachedDiscountUSD?: number;
|
|
34
|
-
/** Total computed base inference cost in USD */
|
|
35
|
-
totalUSD: number;
|
|
36
|
-
/** Retail price after developer markup (if markup applied) */
|
|
37
|
-
retailUSD?: number;
|
|
38
|
-
/** Currency (defaults to 'USD') */
|
|
39
|
-
currency: string;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Full usage event emitted upon completion of an LLM call or stream
|
|
43
|
-
*/
|
|
44
|
-
interface UsageEvent {
|
|
45
|
-
/** Unique ID for the event */
|
|
46
|
-
id?: string;
|
|
47
|
-
/** Timestamp ISO string */
|
|
48
|
-
timestamp: string;
|
|
49
|
-
/** Model name (e.g. 'gpt-5.6-sol', 'claude-3-7-sonnet') */
|
|
50
|
-
model: string;
|
|
51
|
-
/** Provider (e.g. 'openai', 'anthropic', 'google', 'mistral', 'groq', 'deepseek', 'generic') */
|
|
52
|
-
provider: string;
|
|
53
|
-
/** Token breakdown */
|
|
54
|
-
usage: TokenUsage;
|
|
55
|
-
/** Computed cost */
|
|
56
|
-
cost: InferenceCost;
|
|
57
|
-
/** Customer ID (Stripe customer ID, internal userId, or anonymous) */
|
|
58
|
-
customerId?: string;
|
|
59
|
-
/** Optional customer email */
|
|
60
|
-
customerEmail?: string;
|
|
61
|
-
/** Custom developer metadata (e.g. userId, orgId, feature, session) */
|
|
62
|
-
metadata?: Record<string, string | number | boolean>;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Customer identification parameter: can be a string ('cus_xxx' or 'user@example.com') or an object
|
|
66
|
-
*/
|
|
67
|
-
type CustomerParam = string | {
|
|
68
|
-
id?: string;
|
|
69
|
-
userId?: string;
|
|
70
|
-
email?: string;
|
|
71
|
-
name?: string;
|
|
72
|
-
metadata?: Record<string, string>;
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Configuration options for the VibezCheck Meter
|
|
76
|
-
*/
|
|
77
|
-
interface MeterOptions {
|
|
78
|
-
/** Stripe API Key (sk_* or rk_*). If omitted, runs in local telemetry/free mode */
|
|
79
|
-
apiKey?: string;
|
|
80
|
-
/** Existing Stripe SDK instance (optional) */
|
|
81
|
-
stripe?: Stripe;
|
|
82
|
-
/** Default Stripe Meter Event Name (default: 'token-billing-tokens') */
|
|
83
|
-
eventName?: string;
|
|
84
|
-
/** Batching options to optimize Stripe API calls */
|
|
85
|
-
batching?: {
|
|
86
|
-
/** Max events per batch (default: 50) */
|
|
87
|
-
maxBatchSize?: number;
|
|
88
|
-
/** Flush interval in milliseconds (default: 50ms) */
|
|
89
|
-
flushIntervalMs?: number;
|
|
90
|
-
};
|
|
91
|
-
/** Callback fired whenever usage is extracted (works with or without Stripe) */
|
|
92
|
-
onUsage?: (event: UsageEvent) => void | Promise<void>;
|
|
93
|
-
/** Error handler callback */
|
|
94
|
-
onError?: (error: Error, events: UsageEvent[]) => void;
|
|
95
|
-
/** Markup multiplier for retail price calculations (e.g. 1.3 for 30% profit) */
|
|
96
|
-
markupMultiplier?: number;
|
|
97
|
-
/** Enable debug console logging (default: false) */
|
|
98
|
-
debug?: boolean;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Stream wrap options
|
|
102
|
-
*/
|
|
103
|
-
interface StreamWrapOptions {
|
|
104
|
-
/** Customer identifier or email or object */
|
|
105
|
-
customer?: CustomerParam;
|
|
106
|
-
/** Direct customer ID string */
|
|
107
|
-
customerId?: string;
|
|
108
|
-
/** Model override if not automatically detectable */
|
|
109
|
-
model?: string;
|
|
110
|
-
/** Provider override if not automatically detectable */
|
|
111
|
-
provider?: string;
|
|
112
|
-
/** Custom metadata attached to the usage event */
|
|
113
|
-
metadata?: Record<string, string | number | boolean>;
|
|
114
|
-
/** Custom usage callback for this specific stream */
|
|
115
|
-
onUsage?: (event: UsageEvent) => void | Promise<void>;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Direct usage recording options
|
|
119
|
-
*/
|
|
120
|
-
interface RecordUsageOptions {
|
|
121
|
-
model: string;
|
|
122
|
-
provider?: string;
|
|
123
|
-
inputTokens: number;
|
|
124
|
-
outputTokens: number;
|
|
125
|
-
reasoningTokens?: number;
|
|
126
|
-
cachedTokens?: number;
|
|
127
|
-
customer?: CustomerParam;
|
|
128
|
-
customerId?: string;
|
|
129
|
-
metadata?: Record<string, string | number | boolean>;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Model Pricing Rates (per 1 Million Tokens in USD)
|
|
133
|
-
*/
|
|
134
|
-
interface ModelPricingRates {
|
|
135
|
-
inputPer1M: number;
|
|
136
|
-
outputPer1M: number;
|
|
137
|
-
cachedInputPer1M?: number;
|
|
138
|
-
reasoningPer1M?: number;
|
|
139
|
-
cacheWritePer1M?: number;
|
|
140
|
-
currency?: string;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Aggregated Usage Summary
|
|
144
|
-
*/
|
|
145
|
-
interface UsageSummary {
|
|
146
|
-
totalRequests: number;
|
|
147
|
-
totalTokens: number;
|
|
148
|
-
totalInputTokens: number;
|
|
149
|
-
totalOutputTokens: number;
|
|
150
|
-
totalReasoningTokens: number;
|
|
151
|
-
totalCostUSD: number;
|
|
152
|
-
byModel: Record<string, {
|
|
153
|
-
requests: number;
|
|
154
|
-
tokens: number;
|
|
155
|
-
costUSD: number;
|
|
156
|
-
}>;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export type { CustomerParam as C, InferenceCost as I, MeterOptions as M, RecordUsageOptions as R, StreamWrapOptions as S, TokenUsage as T, UsageEvent as U, UsageSummary as a, ModelPricingRates as b };
|
package/dist/types-CSrSmsd1.d.ts
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import Stripe from 'stripe';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Detailed token usage breakdown
|
|
5
|
-
*/
|
|
6
|
-
interface TokenUsage {
|
|
7
|
-
/** Input/Prompt tokens */
|
|
8
|
-
inputTokens: number;
|
|
9
|
-
/** Total output/completion tokens (including reasoning) */
|
|
10
|
-
outputTokens: number;
|
|
11
|
-
/** Total tokens (input + output) */
|
|
12
|
-
totalTokens: number;
|
|
13
|
-
/** Hidden reasoning / thinking tokens (e.g. o1/o3/GPT-5, Claude 3.7 Thinking, Gemini 3.7 Thoughts) */
|
|
14
|
-
reasoningTokens?: number;
|
|
15
|
-
/** Visible output tokens (outputTokens - reasoningTokens) */
|
|
16
|
-
visibleOutputTokens?: number;
|
|
17
|
-
/** Cached input tokens read from KV cache / prompt cache */
|
|
18
|
-
cachedTokens?: number;
|
|
19
|
-
/** Cache write / creation tokens */
|
|
20
|
-
cacheWriteTokens?: number;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Calculated inference cost breakdown
|
|
24
|
-
*/
|
|
25
|
-
interface InferenceCost {
|
|
26
|
-
/** Cost for standard input prompt tokens in USD */
|
|
27
|
-
inputCostUSD: number;
|
|
28
|
-
/** Cost for output completion tokens in USD */
|
|
29
|
-
outputCostUSD: number;
|
|
30
|
-
/** Cost for reasoning/thinking tokens in USD (if applicable) */
|
|
31
|
-
reasoningCostUSD?: number;
|
|
32
|
-
/** Savings from prompt caching in USD */
|
|
33
|
-
cachedDiscountUSD?: number;
|
|
34
|
-
/** Total computed base inference cost in USD */
|
|
35
|
-
totalUSD: number;
|
|
36
|
-
/** Retail price after developer markup (if markup applied) */
|
|
37
|
-
retailUSD?: number;
|
|
38
|
-
/** Currency (defaults to 'USD') */
|
|
39
|
-
currency: string;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Full usage event emitted upon completion of an LLM call or stream
|
|
43
|
-
*/
|
|
44
|
-
interface UsageEvent {
|
|
45
|
-
/** Unique ID for the event */
|
|
46
|
-
id?: string;
|
|
47
|
-
/** Timestamp ISO string */
|
|
48
|
-
timestamp: string;
|
|
49
|
-
/** Model name (e.g. 'gpt-5.6-sol', 'claude-3-7-sonnet') */
|
|
50
|
-
model: string;
|
|
51
|
-
/** Provider (e.g. 'openai', 'anthropic', 'google', 'mistral', 'groq', 'deepseek', 'generic') */
|
|
52
|
-
provider: string;
|
|
53
|
-
/** Token breakdown */
|
|
54
|
-
usage: TokenUsage;
|
|
55
|
-
/** Computed cost */
|
|
56
|
-
cost: InferenceCost;
|
|
57
|
-
/** Customer ID (Stripe customer ID, internal userId, or anonymous) */
|
|
58
|
-
customerId?: string;
|
|
59
|
-
/** Optional customer email */
|
|
60
|
-
customerEmail?: string;
|
|
61
|
-
/** Custom developer metadata (e.g. userId, orgId, feature, session) */
|
|
62
|
-
metadata?: Record<string, string | number | boolean>;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Customer identification parameter: can be a string ('cus_xxx' or 'user@example.com') or an object
|
|
66
|
-
*/
|
|
67
|
-
type CustomerParam = string | {
|
|
68
|
-
id?: string;
|
|
69
|
-
userId?: string;
|
|
70
|
-
email?: string;
|
|
71
|
-
name?: string;
|
|
72
|
-
metadata?: Record<string, string>;
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Configuration options for the VibezCheck Meter
|
|
76
|
-
*/
|
|
77
|
-
interface MeterOptions {
|
|
78
|
-
/** Stripe API Key (sk_* or rk_*). If omitted, runs in local telemetry/free mode */
|
|
79
|
-
apiKey?: string;
|
|
80
|
-
/** Existing Stripe SDK instance (optional) */
|
|
81
|
-
stripe?: Stripe;
|
|
82
|
-
/** Default Stripe Meter Event Name (default: 'token-billing-tokens') */
|
|
83
|
-
eventName?: string;
|
|
84
|
-
/** Batching options to optimize Stripe API calls */
|
|
85
|
-
batching?: {
|
|
86
|
-
/** Max events per batch (default: 50) */
|
|
87
|
-
maxBatchSize?: number;
|
|
88
|
-
/** Flush interval in milliseconds (default: 50ms) */
|
|
89
|
-
flushIntervalMs?: number;
|
|
90
|
-
};
|
|
91
|
-
/** Callback fired whenever usage is extracted (works with or without Stripe) */
|
|
92
|
-
onUsage?: (event: UsageEvent) => void | Promise<void>;
|
|
93
|
-
/** Error handler callback */
|
|
94
|
-
onError?: (error: Error, events: UsageEvent[]) => void;
|
|
95
|
-
/** Markup multiplier for retail price calculations (e.g. 1.3 for 30% profit) */
|
|
96
|
-
markupMultiplier?: number;
|
|
97
|
-
/** Enable debug console logging (default: false) */
|
|
98
|
-
debug?: boolean;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Stream wrap options
|
|
102
|
-
*/
|
|
103
|
-
interface StreamWrapOptions {
|
|
104
|
-
/** Customer identifier or email or object */
|
|
105
|
-
customer?: CustomerParam;
|
|
106
|
-
/** Direct customer ID string */
|
|
107
|
-
customerId?: string;
|
|
108
|
-
/** Model override if not automatically detectable */
|
|
109
|
-
model?: string;
|
|
110
|
-
/** Provider override if not automatically detectable */
|
|
111
|
-
provider?: string;
|
|
112
|
-
/** Custom metadata attached to the usage event */
|
|
113
|
-
metadata?: Record<string, string | number | boolean>;
|
|
114
|
-
/** Custom usage callback for this specific stream */
|
|
115
|
-
onUsage?: (event: UsageEvent) => void | Promise<void>;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Direct usage recording options
|
|
119
|
-
*/
|
|
120
|
-
interface RecordUsageOptions {
|
|
121
|
-
model: string;
|
|
122
|
-
provider?: string;
|
|
123
|
-
inputTokens: number;
|
|
124
|
-
outputTokens: number;
|
|
125
|
-
reasoningTokens?: number;
|
|
126
|
-
cachedTokens?: number;
|
|
127
|
-
customer?: CustomerParam;
|
|
128
|
-
customerId?: string;
|
|
129
|
-
metadata?: Record<string, string | number | boolean>;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Model Pricing Rates (per 1 Million Tokens in USD)
|
|
133
|
-
*/
|
|
134
|
-
interface ModelPricingRates {
|
|
135
|
-
inputPer1M: number;
|
|
136
|
-
outputPer1M: number;
|
|
137
|
-
cachedInputPer1M?: number;
|
|
138
|
-
reasoningPer1M?: number;
|
|
139
|
-
cacheWritePer1M?: number;
|
|
140
|
-
currency?: string;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Aggregated Usage Summary
|
|
144
|
-
*/
|
|
145
|
-
interface UsageSummary {
|
|
146
|
-
totalRequests: number;
|
|
147
|
-
totalTokens: number;
|
|
148
|
-
totalInputTokens: number;
|
|
149
|
-
totalOutputTokens: number;
|
|
150
|
-
totalReasoningTokens: number;
|
|
151
|
-
totalCostUSD: number;
|
|
152
|
-
byModel: Record<string, {
|
|
153
|
-
requests: number;
|
|
154
|
-
tokens: number;
|
|
155
|
-
costUSD: number;
|
|
156
|
-
}>;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export type { CustomerParam as C, InferenceCost as I, MeterOptions as M, RecordUsageOptions as R, StreamWrapOptions as S, TokenUsage as T, UsageEvent as U, UsageSummary as a, ModelPricingRates as b };
|