vibezcheck 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +219 -0
  3. package/dist/ai-sdk/index.d.mts +34 -0
  4. package/dist/ai-sdk/index.d.ts +34 -0
  5. package/dist/ai-sdk/index.js +982 -0
  6. package/dist/ai-sdk/index.js.map +1 -0
  7. package/dist/ai-sdk/index.mjs +944 -0
  8. package/dist/ai-sdk/index.mjs.map +1 -0
  9. package/dist/auth/index.d.mts +59 -0
  10. package/dist/auth/index.d.ts +59 -0
  11. package/dist/auth/index.js +129 -0
  12. package/dist/auth/index.js.map +1 -0
  13. package/dist/auth/index.mjs +90 -0
  14. package/dist/auth/index.mjs.map +1 -0
  15. package/dist/billing/index.d.mts +48 -0
  16. package/dist/billing/index.d.ts +48 -0
  17. package/dist/billing/index.js +128 -0
  18. package/dist/billing/index.js.map +1 -0
  19. package/dist/billing/index.mjs +90 -0
  20. package/dist/billing/index.mjs.map +1 -0
  21. package/dist/client-MJ3tl7bz.d.mts +44 -0
  22. package/dist/client-txrE0D_D.d.ts +44 -0
  23. package/dist/customers/index.d.mts +49 -0
  24. package/dist/customers/index.d.ts +49 -0
  25. package/dist/customers/index.js +158 -0
  26. package/dist/customers/index.js.map +1 -0
  27. package/dist/customers/index.mjs +119 -0
  28. package/dist/customers/index.mjs.map +1 -0
  29. package/dist/index.d.mts +92 -0
  30. package/dist/index.d.ts +92 -0
  31. package/dist/index.js +1458 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/index.mjs +1386 -0
  34. package/dist/index.mjs.map +1 -0
  35. package/dist/meter/index.d.mts +131 -0
  36. package/dist/meter/index.d.ts +131 -0
  37. package/dist/meter/index.js +895 -0
  38. package/dist/meter/index.js.map +1 -0
  39. package/dist/meter/index.mjs +843 -0
  40. package/dist/meter/index.mjs.map +1 -0
  41. package/dist/pricing/index.d.mts +40 -0
  42. package/dist/pricing/index.d.ts +40 -0
  43. package/dist/pricing/index.js +178 -0
  44. package/dist/pricing/index.js.map +1 -0
  45. package/dist/pricing/index.mjs +146 -0
  46. package/dist/pricing/index.mjs.map +1 -0
  47. package/dist/types-CSrSmsd1.d.mts +159 -0
  48. package/dist/types-CSrSmsd1.d.ts +159 -0
  49. package/package.json +131 -0
@@ -0,0 +1,159 @@
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 };
@@ -0,0 +1,159 @@
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/package.json ADDED
@@ -0,0 +1,131 @@
1
+ {
2
+ "name": "vibezcheck",
3
+ "version": "0.1.0",
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
+ "author": "VibezCheck <dev@vibezcheck.xyz> (https://vibezcheck.xyz)",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/seeyouin2x5x/vibezcheck-sdk.git"
10
+ },
11
+ "keywords": [
12
+ "stripe",
13
+ "ai",
14
+ "billing",
15
+ "tokens",
16
+ "metering",
17
+ "llm",
18
+ "openai",
19
+ "anthropic",
20
+ "gemini",
21
+ "vercel-ai",
22
+ "ai-sdk",
23
+ "reasoning",
24
+ "cost-calculator"
25
+ ],
26
+ "engines": {
27
+ "node": ">=18.0.0"
28
+ },
29
+ "main": "./dist/index.js",
30
+ "module": "./dist/index.mjs",
31
+ "types": "./dist/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "import": "./dist/index.mjs",
36
+ "require": "./dist/index.js"
37
+ },
38
+ "./meter": {
39
+ "types": "./dist/meter/index.d.ts",
40
+ "import": "./dist/meter/index.mjs",
41
+ "require": "./dist/meter/index.js"
42
+ },
43
+ "./pricing": {
44
+ "types": "./dist/pricing/index.d.ts",
45
+ "import": "./dist/pricing/index.mjs",
46
+ "require": "./dist/pricing/index.js"
47
+ },
48
+ "./ai-sdk": {
49
+ "types": "./dist/ai-sdk/index.d.ts",
50
+ "import": "./dist/ai-sdk/index.mjs",
51
+ "require": "./dist/ai-sdk/index.js"
52
+ },
53
+ "./customers": {
54
+ "types": "./dist/customers/index.d.ts",
55
+ "import": "./dist/customers/index.mjs",
56
+ "require": "./dist/customers/index.js"
57
+ },
58
+ "./auth": {
59
+ "types": "./dist/auth/index.d.ts",
60
+ "import": "./dist/auth/index.mjs",
61
+ "require": "./dist/auth/index.js"
62
+ },
63
+ "./billing": {
64
+ "types": "./dist/billing/index.d.ts",
65
+ "import": "./dist/billing/index.mjs",
66
+ "require": "./dist/billing/index.js"
67
+ }
68
+ },
69
+ "files": [
70
+ "dist",
71
+ "README.md",
72
+ "LICENSE",
73
+ "package.json"
74
+ ],
75
+ "scripts": {
76
+ "build": "tsup",
77
+ "clean": "rm -rf dist",
78
+ "test": "jest",
79
+ "test:watch": "jest --watch",
80
+ "test:coverage": "jest --coverage",
81
+ "prepublishOnly": "npm run build"
82
+ },
83
+ "dependencies": {
84
+ "stripe": "^17.5.0"
85
+ },
86
+ "devDependencies": {
87
+ "@ai-sdk/anthropic": "^2.0.35",
88
+ "@ai-sdk/google": "^2.0.23",
89
+ "@ai-sdk/openai": "^2.0.53",
90
+ "@ai-sdk/provider": "^3.0.0",
91
+ "@anthropic-ai/sdk": "^0.67.0",
92
+ "@google/generative-ai": "^0.24.1",
93
+ "@types/jest": "^29.5.14",
94
+ "@types/node": "^22.10.5",
95
+ "ai": "^5.0.76",
96
+ "jest": "^29.7.0",
97
+ "openai": "^6.6.0",
98
+ "ts-jest": "^29.2.5",
99
+ "ts-node": "^10.9.2",
100
+ "tsup": "^8.3.5",
101
+ "typescript": "^5.8.3"
102
+ },
103
+ "peerDependencies": {
104
+ "@ai-sdk/provider": "^3.0.0",
105
+ "@anthropic-ai/sdk": "^0.32.0 || ^0.67.0",
106
+ "@google/generative-ai": "^0.21.0 || ^0.24.0",
107
+ "ai": "^3.0.0 || ^4.0.0 || ^5.0.0",
108
+ "openai": "^4.0.0 || ^6.0.0",
109
+ "stripe": "^16.0.0 || ^17.0.0 || ^18.0.0"
110
+ },
111
+ "peerDependenciesMeta": {
112
+ "@ai-sdk/provider": {
113
+ "optional": true
114
+ },
115
+ "@anthropic-ai/sdk": {
116
+ "optional": true
117
+ },
118
+ "@google/generative-ai": {
119
+ "optional": true
120
+ },
121
+ "ai": {
122
+ "optional": true
123
+ },
124
+ "openai": {
125
+ "optional": true
126
+ },
127
+ "stripe": {
128
+ "optional": true
129
+ }
130
+ }
131
+ }