@revenium/anthropic 1.0.3 → 1.0.5

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.
@@ -10,7 +10,7 @@ exports.ANTHROPIC_PATTERNS = exports.API_ENDPOINTS = exports.ENV_VARS = exports.
10
10
  */
11
11
  exports.DEFAULT_CONFIG = {
12
12
  /** Default Revenium API base URL */
13
- REVENIUM_BASE_URL: 'https://api.revenium.io/meter',
13
+ REVENIUM_BASE_URL: 'https://api.revenium.io',
14
14
  /** Default API timeout in milliseconds */
15
15
  API_TIMEOUT: 5000,
16
16
  /** Default maximum retries for failed API calls */
@@ -118,7 +118,7 @@ exports.ENV_VARS = {
118
118
  */
119
119
  exports.API_ENDPOINTS = {
120
120
  /** Revenium AI completions endpoint */
121
- AI_COMPLETIONS: '/v2/ai/completions',
121
+ AI_COMPLETIONS: '/meter/v2/ai/completions',
122
122
  };
123
123
  /**
124
124
  * Anthropic model patterns
@@ -161,7 +161,7 @@ function validateReveniumConfig(config) {
161
161
  }
162
162
  catch {
163
163
  errors.push('reveniumBaseUrl must be a valid URL');
164
- suggestions.push('Use format: https://api.revenium.io/meter');
164
+ suggestions.push('Use format: https://api.revenium.io');
165
165
  }
166
166
  }
167
167
  // Validate optional Anthropic API key
@@ -7,7 +7,7 @@
7
7
  */
8
8
  export const DEFAULT_CONFIG = {
9
9
  /** Default Revenium API base URL */
10
- REVENIUM_BASE_URL: 'https://api.revenium.io/meter',
10
+ REVENIUM_BASE_URL: 'https://api.revenium.io',
11
11
  /** Default API timeout in milliseconds */
12
12
  API_TIMEOUT: 5000,
13
13
  /** Default maximum retries for failed API calls */
@@ -115,7 +115,7 @@ export const ENV_VARS = {
115
115
  */
116
116
  export const API_ENDPOINTS = {
117
117
  /** Revenium AI completions endpoint */
118
- AI_COMPLETIONS: '/v2/ai/completions',
118
+ AI_COMPLETIONS: '/meter/v2/ai/completions',
119
119
  };
120
120
  /**
121
121
  * Anthropic model patterns
@@ -150,7 +150,7 @@ export function validateReveniumConfig(config) {
150
150
  }
151
151
  catch {
152
152
  errors.push('reveniumBaseUrl must be a valid URL');
153
- suggestions.push('Use format: https://api.revenium.io/meter');
153
+ suggestions.push('Use format: https://api.revenium.io');
154
154
  }
155
155
  }
156
156
  // Validate optional Anthropic API key
@@ -7,7 +7,7 @@
7
7
  */
8
8
  export declare const DEFAULT_CONFIG: {
9
9
  /** Default Revenium API base URL */
10
- readonly REVENIUM_BASE_URL: "https://api.revenium.io/meter";
10
+ readonly REVENIUM_BASE_URL: "https://api.revenium.io";
11
11
  /** Default API timeout in milliseconds */
12
12
  readonly API_TIMEOUT: 5000;
13
13
  /** Default maximum retries for failed API calls */
@@ -115,7 +115,7 @@ export declare const ENV_VARS: {
115
115
  */
116
116
  export declare const API_ENDPOINTS: {
117
117
  /** Revenium AI completions endpoint */
118
- readonly AI_COMPLETIONS: "/v2/ai/completions";
118
+ readonly AI_COMPLETIONS: "/meter/v2/ai/completions";
119
119
  };
120
120
  /**
121
121
  * Anthropic model patterns
@@ -52,7 +52,7 @@ export interface Subscriber {
52
52
  * ```typescript
53
53
  * const config: ReveniumConfig = {
54
54
  * reveniumApiKey: 'hak_1234567890abcdef',
55
- * reveniumBaseUrl: 'https://api.revenium.io/meter/v2',
55
+ * reveniumBaseUrl: 'https://api.revenium.io',
56
56
  * anthropicApiKey: 'sk-ant-1234567890abcdef',
57
57
  * apiTimeout: 8000,
58
58
  * failSilent: true,
@@ -0,0 +1,182 @@
1
+ # Revenium Anthropic Middleware - Examples
2
+
3
+ **TypeScript-first** examples demonstrating automatic Revenium usage tracking with the Anthropic SDK.
4
+
5
+ ## Getting Started - Step by Step
6
+
7
+ ### 1. Create Your Project
8
+
9
+ ```bash
10
+ # Create project directory
11
+ mkdir my-anthropic-project
12
+ cd my-anthropic-project
13
+
14
+ # Initialize Node.js project
15
+ npm init -y
16
+ ```
17
+
18
+ ### 2. Install Dependencies
19
+
20
+ ```bash
21
+ npm install @revenium/anthropic @anthropic-ai/sdk dotenv
22
+ npm install -D typescript tsx @types/node # For TypeScript
23
+ ```
24
+
25
+ ### 3. Environment Setup
26
+
27
+ Create a `.env` file in your project root:
28
+
29
+ ```bash
30
+ # Required
31
+ REVENIUM_METERING_API_KEY=hak_your_revenium_api_key
32
+ ANTHROPIC_API_KEY=sk-ant-your_anthropic_api_key
33
+
34
+ # Optional
35
+ REVENIUM_METERING_BASE_URL=https://api.revenium.io
36
+ REVENIUM_DEBUG=false
37
+ ```
38
+
39
+ ### 4. Run Examples
40
+
41
+ **If you cloned from GitHub:**
42
+
43
+ ```bash
44
+ # Run included examples directly
45
+ npm run example:basic
46
+ npm run example:advanced
47
+
48
+ # Or use tsx directly
49
+ npx tsx examples/basic-usage.ts
50
+ npx tsx examples/advanced-features.ts
51
+ ```
52
+
53
+ **If you installed via npm:**
54
+
55
+ Examples are included in your `node_modules/@revenium/anthropic/examples/` directory:
56
+
57
+ ```bash
58
+ npx tsx node_modules/@revenium/anthropic/examples/basic-usage.ts
59
+ npx tsx node_modules/@revenium/anthropic/examples/advanced-features.ts
60
+ ```
61
+
62
+ ## Available Examples
63
+
64
+ ### `basic-usage.ts` - Initialization Methods
65
+
66
+ Demonstrates the three ways to initialize the Revenium middleware:
67
+
68
+ - **Auto-initialization** (Recommended) - Import and go, uses environment variables
69
+ - **Explicit initialization** - Call `initialize()` for error handling control
70
+ - **Manual configuration** - Use `configure()` for custom settings
71
+
72
+ **Key Features:**
73
+ - TypeScript module augmentation for native `usageMetadata` support
74
+ - Full type safety with IntelliSense
75
+ - Interface validation using `satisfies` operator
76
+ - Comprehensive error handling patterns
77
+
78
+ **See the file for complete code examples.**
79
+
80
+ ### `advanced-features.ts` - Streaming, Tools, and Manual Tracking
81
+
82
+ Demonstrates advanced Anthropic SDK features with automatic tracking:
83
+
84
+ - **Streaming responses** - Real-time response tracking with type safety
85
+ - **Tool use (function calling)** - Function calls with metadata tracking
86
+ - **Manual tracking** - Custom tracking for edge cases
87
+ - **Error handling** - Comprehensive error handling patterns
88
+
89
+ **Key Features:**
90
+ - Type-safe event handling and stream processing
91
+ - Advanced metadata patterns with interface extensions
92
+ - Generic functions with type constraints
93
+ - Custom logger integration
94
+
95
+ **See the file for complete code examples.**
96
+
97
+ ## TypeScript Configuration
98
+
99
+ Ensure your `tsconfig.json` includes:
100
+
101
+ ```json
102
+ {
103
+ "compilerOptions": {
104
+ "target": "ES2020",
105
+ "module": "ESNext",
106
+ "moduleResolution": "node",
107
+ "esModuleInterop": true,
108
+ "allowSyntheticDefaultImports": true,
109
+ "strict": true,
110
+ "skipLibCheck": true
111
+ }
112
+ }
113
+ ```
114
+
115
+ ## Requirements
116
+
117
+ - **Node.js 16+** with TypeScript support
118
+ - **TypeScript 4.5+** for module augmentation features
119
+ - **Valid Revenium API key** (starts with `hak_`)
120
+ - **Valid Anthropic API key** (starts with `sk-ant-`)
121
+
122
+ ## Troubleshooting
123
+
124
+ ### Module Augmentation Not Working
125
+
126
+ **Problem:** TypeScript doesn't recognize `usageMetadata` in Anthropic SDK calls
127
+
128
+ **Solution:**
129
+
130
+ ```typescript
131
+ // ❌ Wrong - missing module augmentation import
132
+ import { configure } from "@revenium/anthropic";
133
+
134
+ // ✅ Correct - import for module augmentation
135
+ import "@revenium/anthropic";
136
+ import Anthropic from "@anthropic-ai/sdk";
137
+ ```
138
+
139
+ ### Environment Variables Not Loading
140
+
141
+ **Problem:** `REVENIUM_METERING_API_KEY` or `ANTHROPIC_API_KEY` not found
142
+
143
+ **Solutions:**
144
+ - Ensure `.env` file is in project root
145
+ - Check variable names match exactly
146
+ - Verify you're importing `dotenv/config` before the middleware
147
+ - Check API keys have correct prefixes (`hak_` for Revenium, `sk-ant-` for Anthropic)
148
+
149
+ ### TypeScript Compilation Errors
150
+
151
+ **Problem:** Module resolution or import errors
152
+
153
+ **Solution:** Verify your `tsconfig.json` settings:
154
+
155
+ ```json
156
+ {
157
+ "compilerOptions": {
158
+ "moduleResolution": "node",
159
+ "esModuleInterop": true,
160
+ "allowSyntheticDefaultImports": true,
161
+ "strict": true
162
+ }
163
+ }
164
+ ```
165
+
166
+ ### Debug Mode
167
+
168
+ Enable detailed logging to troubleshoot issues:
169
+
170
+ ```bash
171
+ # In .env file
172
+ REVENIUM_DEBUG=true
173
+
174
+ # Then run examples
175
+ npm run example:basic
176
+ ```
177
+
178
+ ## Additional Resources
179
+
180
+ - **Main Documentation**: See root [README.md](https://github.com/revenium/revenium-middleware-anthropic-node/blob/HEAD/README.md)
181
+ - **API Reference**: Full TypeScript types and JSDoc in the package
182
+ - **Issues**: [Report bugs](https://github.com/revenium/revenium-middleware-anthropic-node/issues)