@revenium/anthropic 1.0.4 → 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.
- package/CHANGELOG.md +8 -0
- package/README.md +41 -254
- package/dist/cjs/constants.js +2 -2
- package/dist/cjs/utils/validation.js +1 -1
- package/dist/esm/constants.js +2 -2
- package/dist/esm/utils/validation.js +1 -1
- package/dist/types/constants.d.ts +2 -2
- package/dist/types/types.d.ts +1 -1
- package/examples/README.md +16 -13
- package/examples/advanced-features.ts +1 -1
- package/examples/basic-usage.ts +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.0.5] - 2025-10-23
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
- Updated .gitignore to GitHub official standard for professional presentation
|
|
9
|
+
- Improved .env.example with realistic key format examples (hak_, sk-ant-)
|
|
10
|
+
- Created initial public repository structure
|
|
11
|
+
|
|
5
12
|
## [1.0.4] - 2025-10-21
|
|
6
13
|
|
|
7
14
|
### Changed
|
|
@@ -45,6 +52,7 @@ All notable changes to this project will be documented in this file.
|
|
|
45
52
|
- Configurable retry logic
|
|
46
53
|
- Debug logging support
|
|
47
54
|
|
|
55
|
+
[1.0.5]: https://github.com/revenium/revenium-middleware-anthropic-node/releases/tag/v1.0.5
|
|
48
56
|
[1.0.4]: https://github.com/revenium/revenium-middleware-anthropic-node/releases/tag/v1.0.4
|
|
49
57
|
[1.0.3]: https://github.com/revenium/revenium-middleware-anthropic-node/releases/tag/v1.0.3
|
|
50
58
|
[1.0.2]: https://github.com/revenium/revenium-middleware-anthropic-node/releases/tag/v1.0.2
|
package/README.md
CHANGED
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
Automatically track and meter your Anthropic Claude API usage with Revenium. This middleware provides seamless integration with **Anthropic Claude SDK**, requiring minimal code changes and featuring native TypeScript support.
|
|
9
9
|
|
|
10
|
-
> **Note - Package Renamed**: This package has been renamed from `revenium-middleware-anthropic-node` to `@revenium/anthropic` for better organization and simpler naming. Please update your dependencies accordingly.
|
|
11
|
-
|
|
12
10
|
## Features
|
|
13
11
|
|
|
14
12
|
- **Seamless Integration**: Drop-in replacement with zero code changes required
|
|
@@ -21,134 +19,39 @@ Automatically track and meter your Anthropic Claude API usage with Revenium. Thi
|
|
|
21
19
|
- **Fire-and-forget**: Never blocks your application flow
|
|
22
20
|
- **Analytics**: Detailed usage analytics and reporting
|
|
23
21
|
|
|
24
|
-
## Package Migration
|
|
25
|
-
|
|
26
|
-
This package has been renamed from `revenium-middleware-anthropic-node` to `@revenium/anthropic` for better organization and simpler naming.
|
|
27
|
-
|
|
28
|
-
### Migration Steps
|
|
29
|
-
|
|
30
|
-
If you're upgrading from the old package:
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
# Uninstall the old package
|
|
34
|
-
npm uninstall revenium-middleware-anthropic-node
|
|
35
|
-
|
|
36
|
-
# Install the new package
|
|
37
|
-
npm install @revenium/anthropic
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
**Update your imports:**
|
|
41
|
-
|
|
42
|
-
```typescript
|
|
43
|
-
// Old import
|
|
44
|
-
import "revenium-middleware-anthropic-node";
|
|
45
|
-
|
|
46
|
-
// New import
|
|
47
|
-
import "@revenium/anthropic";
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
All functionality remains exactly the same - only the package name has changed.
|
|
51
|
-
|
|
52
22
|
## Getting Started
|
|
53
23
|
|
|
54
|
-
|
|
24
|
+
**Installation:**
|
|
55
25
|
|
|
56
26
|
```bash
|
|
57
27
|
npm install @revenium/anthropic @anthropic-ai/sdk
|
|
58
28
|
```
|
|
59
29
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
### Step-by-Step Guide
|
|
63
|
-
|
|
64
|
-
The following guide walks you through creating a new project from scratch:
|
|
65
|
-
|
|
66
|
-
### Step 1: Create Your Project
|
|
67
|
-
|
|
68
|
-
```bash
|
|
69
|
-
# Create project directory
|
|
70
|
-
mkdir my-anthropic-project
|
|
71
|
-
cd my-anthropic-project
|
|
72
|
-
|
|
73
|
-
# Initialize Node.js project
|
|
74
|
-
npm init -y
|
|
75
|
-
```
|
|
30
|
+
**Quick Start:**
|
|
76
31
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
# Install Revenium middleware and Anthropic SDK
|
|
81
|
-
npm install @revenium/anthropic @anthropic-ai/sdk@^0.55.1 dotenv
|
|
82
|
-
|
|
83
|
-
# For TypeScript projects (optional)
|
|
84
|
-
npm install -D typescript tsx @types/node
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### Step 3: Setup Environment Variables
|
|
88
|
-
|
|
89
|
-
Create a `.env` file in your project root:
|
|
90
|
-
|
|
91
|
-
```bash
|
|
92
|
-
# Create .env file
|
|
93
|
-
echo. > .env # On Windows (CMD)
|
|
94
|
-
touch .env # On Mac/Linux
|
|
95
|
-
# OR PowerShell
|
|
96
|
-
New-Item -Path .env -ItemType File
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
Copy and paste the following into `.env`:
|
|
100
|
-
|
|
101
|
-
```env
|
|
102
|
-
# Anthropic Configuration
|
|
103
|
-
ANTHROPIC_API_KEY=sk-ant-your_anthropic_api_key_here
|
|
104
|
-
|
|
105
|
-
# Revenium Configuration
|
|
106
|
-
REVENIUM_METERING_API_KEY=hak_your_revenium_api_key_here
|
|
107
|
-
REVENIUM_METERING_BASE_URL=https://api.revenium.io/meter
|
|
32
|
+
```typescript
|
|
33
|
+
import "@revenium/anthropic";
|
|
34
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
108
35
|
|
|
109
|
-
|
|
110
|
-
|
|
36
|
+
const client = new Anthropic();
|
|
37
|
+
// Middleware automatically tracks all requests
|
|
111
38
|
```
|
|
112
39
|
|
|
113
|
-
**
|
|
114
|
-
|
|
115
|
-
### Step 4: Protect Your API Keys
|
|
116
|
-
|
|
117
|
-
**CRITICAL**: Create a `.gitignore` file to prevent committing sensitive data like API keys.
|
|
118
|
-
|
|
119
|
-
**Recommended**: Use the industry-standard [GitHub Node.gitignore](https://github.com/github/gitignore/blob/main/Node.gitignore)
|
|
40
|
+
**Environment Setup:**
|
|
120
41
|
|
|
121
42
|
```bash
|
|
122
|
-
|
|
123
|
-
|
|
43
|
+
export ANTHROPIC_API_KEY="sk-ant-your_anthropic_key"
|
|
44
|
+
export REVENIUM_METERING_API_KEY="hak_your_revenium_key"
|
|
124
45
|
```
|
|
125
46
|
|
|
126
|
-
**
|
|
127
|
-
|
|
128
|
-
```gitignore
|
|
129
|
-
# Environment variables - CRITICAL for API key protection
|
|
130
|
-
.env
|
|
131
|
-
.env.*
|
|
132
|
-
!.env.example
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
Never commit `.env` files containing your API keys to version control.
|
|
136
|
-
|
|
137
|
-
### Step 5: Follow the Examples
|
|
47
|
+
**For complete step-by-step setup, TypeScript configuration, and running examples, see [examples/README.md](https://github.com/revenium/revenium-middleware-anthropic-node/blob/HEAD/examples/README.md).**
|
|
138
48
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
**Cloned from GitHub?** Run examples with:
|
|
142
|
-
|
|
143
|
-
```bash
|
|
144
|
-
npm install
|
|
145
|
-
npm run example:basic
|
|
146
|
-
npm run example:advanced
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
**Browse online:** [`examples/` directory](https://github.com/revenium/revenium-middleware-anthropic-node/tree/HEAD/examples)
|
|
49
|
+
## Requirements
|
|
150
50
|
|
|
151
|
-
|
|
51
|
+
- Node.js 18+
|
|
52
|
+
- TypeScript 5.0+ (for TypeScript projects)
|
|
53
|
+
- Anthropic SDK (@anthropic-ai/sdk) v0.20.0+
|
|
54
|
+
- Revenium API key
|
|
152
55
|
|
|
153
56
|
## What Gets Tracked
|
|
154
57
|
|
|
@@ -168,166 +71,57 @@ The middleware automatically captures:
|
|
|
168
71
|
|
|
169
72
|
The middleware supports three initialization patterns:
|
|
170
73
|
|
|
171
|
-
|
|
74
|
+
**Automatic (Recommended)** - Simply import the middleware and it auto-initializes:
|
|
172
75
|
|
|
173
76
|
```typescript
|
|
174
|
-
// Simply import - auto-initializes with graceful fallback
|
|
175
77
|
import "@revenium/anthropic";
|
|
176
78
|
import Anthropic from "@anthropic-ai/sdk";
|
|
177
79
|
|
|
178
|
-
// If env vars are set, tracking works automatically
|
|
179
80
|
const anthropic = new Anthropic();
|
|
81
|
+
// Tracking works automatically if env vars are set
|
|
180
82
|
```
|
|
181
83
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
```typescript
|
|
185
|
-
import { initialize } from "@revenium/anthropic";
|
|
186
|
-
import Anthropic from "@anthropic-ai/sdk";
|
|
187
|
-
|
|
188
|
-
try {
|
|
189
|
-
initialize();
|
|
190
|
-
// Middleware initialized successfully
|
|
191
|
-
} catch (error) {
|
|
192
|
-
// Handle initialization error appropriately
|
|
193
|
-
throw new Error(`Initialization failed: ${error.message}`);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const anthropic = new Anthropic();
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
#### Option C: Manual Configuration (Full Control)
|
|
200
|
-
|
|
201
|
-
```typescript
|
|
202
|
-
import { configure } from "@revenium/anthropic";
|
|
203
|
-
import Anthropic from "@anthropic-ai/sdk";
|
|
84
|
+
**Explicit** - Call `initialize()` for error handling control
|
|
204
85
|
|
|
205
|
-
configure(
|
|
206
|
-
reveniumApiKey: "hak_your_api_key_here",
|
|
207
|
-
reveniumBaseUrl: "https://api.revenium.io/meter",
|
|
208
|
-
anthropicApiKey: "sk-ant-your_key_here",
|
|
209
|
-
apiTimeout: 5000,
|
|
210
|
-
failSilent: true,
|
|
211
|
-
maxRetries: 3,
|
|
212
|
-
});
|
|
86
|
+
**Manual** - Use `configure()` to set all options programmatically
|
|
213
87
|
|
|
214
|
-
|
|
215
|
-
```
|
|
88
|
+
For detailed examples of all initialization patterns, see [examples/](https://github.com/revenium/revenium-middleware-anthropic-node/blob/HEAD/examples/README.md).
|
|
216
89
|
|
|
217
90
|
### Streaming Responses
|
|
218
91
|
|
|
219
|
-
|
|
220
|
-
import "@revenium/anthropic";
|
|
221
|
-
import Anthropic from "@anthropic-ai/sdk";
|
|
92
|
+
Streaming is fully supported with real-time token tracking and time-to-first-token metrics. The middleware automatically tracks streaming responses without any additional configuration.
|
|
222
93
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const stream = await anthropic.messages.create({
|
|
226
|
-
model: "claude-3-5-sonnet-latest",
|
|
227
|
-
max_tokens: 1000,
|
|
228
|
-
messages: [{ role: "user", content: "Write a story about AI" }],
|
|
229
|
-
stream: true,
|
|
230
|
-
usageMetadata: {
|
|
231
|
-
subscriber: {
|
|
232
|
-
id: "user-123",
|
|
233
|
-
email: "user@example.com",
|
|
234
|
-
},
|
|
235
|
-
organizationId: "story-org",
|
|
236
|
-
taskType: "creative-writing",
|
|
237
|
-
agent: "story-writer",
|
|
238
|
-
},
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
for await (const event of stream) {
|
|
242
|
-
if (
|
|
243
|
-
event.type === "content_block_delta" &&
|
|
244
|
-
event.delta.type === "text_delta"
|
|
245
|
-
) {
|
|
246
|
-
process.stdout.write(event.delta.text);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
```
|
|
94
|
+
See [examples/advanced-features.ts](https://github.com/revenium/revenium-middleware-anthropic-node/blob/HEAD/examples/advanced-features.ts) for working streaming examples.
|
|
250
95
|
|
|
251
96
|
### Custom Metadata Tracking
|
|
252
97
|
|
|
253
|
-
Add business context to
|
|
254
|
-
|
|
255
|
-
```typescript
|
|
256
|
-
// Custom metadata for enhanced tracking (following project structure)
|
|
257
|
-
const customMetadata = {
|
|
258
|
-
subscriber: {
|
|
259
|
-
id: "user-789",
|
|
260
|
-
email: "user@company.com",
|
|
261
|
-
credential: {
|
|
262
|
-
name: "premium-user",
|
|
263
|
-
value: "tier-1",
|
|
264
|
-
},
|
|
265
|
-
},
|
|
266
|
-
organizationId: "org-456",
|
|
267
|
-
productId: "premium-plan",
|
|
268
|
-
taskType: "CUSTOMER_SUPPORT",
|
|
269
|
-
agent: "CustomerSupportBot",
|
|
270
|
-
traceId: "user-session-123",
|
|
271
|
-
responseQualityScore: 9.2,
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
const response = await anthropic.messages.create({
|
|
275
|
-
model: "claude-3-5-sonnet-latest",
|
|
276
|
-
max_tokens: 1024,
|
|
277
|
-
messages: [{ role: "user", content: "Help me with my account" }],
|
|
278
|
-
usageMetadata: customMetadata,
|
|
279
|
-
});
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
### Usage Metadata Interface
|
|
98
|
+
Add business context to track usage by organization, user, task type, or custom fields. Pass a `usageMetadata` object with any of these optional fields:
|
|
283
99
|
|
|
284
|
-
|
|
100
|
+
- **subscriber**: User ID, email, and credentials
|
|
101
|
+
- **organizationId**: Organization or company identifier
|
|
102
|
+
- **taskType**: Type of AI task (e.g., chat, analysis, generation)
|
|
103
|
+
- **agent**: AI agent or bot identifier
|
|
104
|
+
- **traceId**: Session or conversation tracking
|
|
105
|
+
- **productId**: Your product or feature identifier
|
|
106
|
+
- **responseQualityScore**: Custom quality metrics
|
|
285
107
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
traceId?: string; // Session or conversation ID
|
|
289
|
-
taskType?: string; // Type of AI task (e.g., "chat", "analysis")
|
|
290
|
-
organizationId?: string; // Organization/company ID
|
|
291
|
-
subscriptionId?: string; // Billing plan ID
|
|
292
|
-
productId?: string; // Your product/feature ID
|
|
293
|
-
agent?: string; // AI agent identifier
|
|
294
|
-
responseQualityScore?: number; // Quality score (0-1)
|
|
295
|
-
subscriber?: {
|
|
296
|
-
id?: string; // User ID from your system
|
|
297
|
-
email?: string; // User's email address
|
|
298
|
-
credential?: {
|
|
299
|
-
name?: string; // Credential name
|
|
300
|
-
value?: string; // Credential value
|
|
301
|
-
};
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
```
|
|
108
|
+
**Resources:**
|
|
109
|
+
- [API Reference](https://revenium.readme.io/reference/meter_ai_completion) - Complete metadata field documentation
|
|
305
110
|
|
|
306
111
|
## Configuration Options
|
|
307
112
|
|
|
308
113
|
### Environment Variables
|
|
309
114
|
|
|
310
|
-
| Variable | Required | Default
|
|
311
|
-
| ---------------------------- | -------- |
|
|
312
|
-
| `REVENIUM_METERING_API_KEY` | Yes | -
|
|
313
|
-
| `ANTHROPIC_API_KEY` | Yes | -
|
|
314
|
-
| `REVENIUM_METERING_BASE_URL` | No | `https://api.revenium.io
|
|
315
|
-
| `REVENIUM_DEBUG` | No | `false`
|
|
115
|
+
| Variable | Required | Default | Description |
|
|
116
|
+
| ---------------------------- | -------- | -------------------------- | --------------------------------- |
|
|
117
|
+
| `REVENIUM_METERING_API_KEY` | Yes | - | Your Revenium API key |
|
|
118
|
+
| `ANTHROPIC_API_KEY` | Yes | - | Anthropic Claude API key |
|
|
119
|
+
| `REVENIUM_METERING_BASE_URL` | No | `https://api.revenium.io` | Revenium metering API base URL |
|
|
120
|
+
| `REVENIUM_DEBUG` | No | `false` | Enable debug logging (true/false) |
|
|
316
121
|
|
|
317
122
|
### Manual Configuration
|
|
318
123
|
|
|
319
|
-
|
|
320
|
-
import { configure } from "@revenium/anthropic";
|
|
321
|
-
|
|
322
|
-
configure({
|
|
323
|
-
reveniumApiKey: "hak_your_api_key",
|
|
324
|
-
reveniumBaseUrl: "https://api.revenium.io/meter",
|
|
325
|
-
anthropicApiKey: "sk-ant-your_key",
|
|
326
|
-
apiTimeout: 5000,
|
|
327
|
-
failSilent: true,
|
|
328
|
-
maxRetries: 3,
|
|
329
|
-
});
|
|
330
|
-
```
|
|
124
|
+
For programmatic configuration instead of environment variables, use the `configure()` function. See the initialization options above and [examples/](https://github.com/revenium/revenium-middleware-anthropic-node/blob/HEAD/examples/README.md) for details.
|
|
331
125
|
|
|
332
126
|
## Troubleshooting
|
|
333
127
|
|
|
@@ -411,13 +205,6 @@ All examples are in the `examples/` directory of the installed package. For deta
|
|
|
411
205
|
|
|
412
206
|
The middleware never blocks your application - if Revenium tracking fails, your Anthropic requests continue normally.
|
|
413
207
|
|
|
414
|
-
## Requirements
|
|
415
|
-
|
|
416
|
-
- Node.js 16+
|
|
417
|
-
- Anthropic SDK (@anthropic-ai/sdk) v0.20.0+
|
|
418
|
-
- TypeScript 5.0+ (for TypeScript projects)
|
|
419
|
-
- Revenium API key
|
|
420
|
-
|
|
421
208
|
## Documentation
|
|
422
209
|
|
|
423
210
|
For detailed documentation, visit [docs.revenium.io](https://docs.revenium.io)
|
|
@@ -445,7 +232,7 @@ For issues, feature requests, or contributions:
|
|
|
445
232
|
- **GitHub Repository**: [revenium/revenium-middleware-anthropic-node](https://github.com/revenium/revenium-middleware-anthropic-node)
|
|
446
233
|
- **Issues**: [Report bugs or request features](https://github.com/revenium/revenium-middleware-anthropic-node/issues)
|
|
447
234
|
- **Documentation**: [docs.revenium.io](https://docs.revenium.io)
|
|
448
|
-
- **
|
|
235
|
+
- **Email**: support@revenium.io
|
|
449
236
|
|
|
450
237
|
## Development
|
|
451
238
|
|
package/dist/cjs/constants.js
CHANGED
|
@@ -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
|
|
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
|
|
164
|
+
suggestions.push('Use format: https://api.revenium.io');
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
// Validate optional Anthropic API key
|
package/dist/esm/constants.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
package/dist/types/types.d.ts
CHANGED
|
@@ -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
|
|
55
|
+
* reveniumBaseUrl: 'https://api.revenium.io',
|
|
56
56
|
* anthropicApiKey: 'sk-ant-1234567890abcdef',
|
|
57
57
|
* apiTimeout: 8000,
|
|
58
58
|
* failSilent: true,
|
package/examples/README.md
CHANGED
|
@@ -2,16 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
**TypeScript-first** examples demonstrating automatic Revenium usage tracking with the Anthropic SDK.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Getting Started - Step by Step
|
|
6
6
|
|
|
7
|
-
### 1.
|
|
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
|
|
8
19
|
|
|
9
20
|
```bash
|
|
10
21
|
npm install @revenium/anthropic @anthropic-ai/sdk dotenv
|
|
11
22
|
npm install -D typescript tsx @types/node # For TypeScript
|
|
12
23
|
```
|
|
13
24
|
|
|
14
|
-
###
|
|
25
|
+
### 3. Environment Setup
|
|
15
26
|
|
|
16
27
|
Create a `.env` file in your project root:
|
|
17
28
|
|
|
@@ -21,11 +32,11 @@ REVENIUM_METERING_API_KEY=hak_your_revenium_api_key
|
|
|
21
32
|
ANTHROPIC_API_KEY=sk-ant-your_anthropic_api_key
|
|
22
33
|
|
|
23
34
|
# Optional
|
|
24
|
-
REVENIUM_METERING_BASE_URL=https://api.revenium.io
|
|
35
|
+
REVENIUM_METERING_BASE_URL=https://api.revenium.io
|
|
25
36
|
REVENIUM_DEBUG=false
|
|
26
37
|
```
|
|
27
38
|
|
|
28
|
-
###
|
|
39
|
+
### 4. Run Examples
|
|
29
40
|
|
|
30
41
|
**If you cloned from GitHub:**
|
|
31
42
|
|
|
@@ -152,14 +163,6 @@ import Anthropic from "@anthropic-ai/sdk";
|
|
|
152
163
|
}
|
|
153
164
|
```
|
|
154
165
|
|
|
155
|
-
### IntelliSense Not Working
|
|
156
|
-
|
|
157
|
-
**Solutions:**
|
|
158
|
-
1. Restart TypeScript language server in your IDE
|
|
159
|
-
2. Ensure `@revenium/anthropic` is imported at the top
|
|
160
|
-
3. Verify `@anthropic-ai/sdk` types are installed
|
|
161
|
-
4. Check TypeScript version is 4.5 or higher
|
|
162
|
-
|
|
163
166
|
### Debug Mode
|
|
164
167
|
|
|
165
168
|
Enable detailed logging to troubleshoot issues:
|
|
@@ -462,7 +462,7 @@ function checkEnvironment(): void {
|
|
|
462
462
|
console.error(" ANTHROPIC_API_KEY=sk-ant-your_anthropic_key");
|
|
463
463
|
console.error("\nOptional (uses defaults if not set):");
|
|
464
464
|
console.error(
|
|
465
|
-
" REVENIUM_METERING_BASE_URL=https://api.revenium.io
|
|
465
|
+
" REVENIUM_METERING_BASE_URL=https://api.revenium.io"
|
|
466
466
|
);
|
|
467
467
|
console.error(" REVENIUM_DEBUG=true # For detailed logging");
|
|
468
468
|
process.exit(1);
|
package/examples/basic-usage.ts
CHANGED
|
@@ -200,7 +200,7 @@ async function demonstrateManualConfiguration() {
|
|
|
200
200
|
process.env.REVENIUM_METERING_API_KEY || "hak_your_api_key_here",
|
|
201
201
|
reveniumBaseUrl:
|
|
202
202
|
process.env.REVENIUM_METERING_BASE_URL ||
|
|
203
|
-
"https://api.revenium.io
|
|
203
|
+
"https://api.revenium.io",
|
|
204
204
|
|
|
205
205
|
// Optional: Anthropic API key (can also be set in Anthropic client)
|
|
206
206
|
anthropicApiKey: process.env.ANTHROPIC_API_KEY,
|
|
@@ -286,7 +286,7 @@ function checkEnvironment() {
|
|
|
286
286
|
console.error(" ANTHROPIC_API_KEY=sk-ant-your_anthropic_key");
|
|
287
287
|
console.error("\nOptional (uses defaults if not set):");
|
|
288
288
|
console.error(
|
|
289
|
-
" REVENIUM_METERING_BASE_URL=https://api.revenium.io
|
|
289
|
+
" REVENIUM_METERING_BASE_URL=https://api.revenium.io"
|
|
290
290
|
);
|
|
291
291
|
console.error(" REVENIUM_DEBUG=true # For detailed logging");
|
|
292
292
|
process.exit(1);
|
package/package.json
CHANGED