@revenium/perplexity 2.0.2 → 2.0.3

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 CHANGED
@@ -1,625 +1,866 @@
1
- # Revenium Middleware for Perplexity
2
-
3
- A lightweight, production-ready middleware that adds **Revenium metering and tracking** to Perplexity AI API calls.
4
-
5
- [![npm version](https://img.shields.io/npm/v/@revenium/perplexity.svg)](https://www.npmjs.com/package/@revenium/perplexity)
6
- [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)
7
-
8
- ## 🚀 Features
9
-
10
- - ✅ **Zero Configuration** - Works out of the box with environment variables
11
- - ✅ **Automatic Metering** - Tracks all API calls with detailed usage metrics
12
- - ✅ **Streaming Support** - Full support for streaming responses
13
- - ✅ **TypeScript First** - Built with TypeScript, includes full type definitions
14
- - ✅ **Multi-Format** - Supports both ESM and CommonJS
15
- - ✅ **Custom Metadata** - Add custom tracking metadata to any request
16
- - ✅ **Production Ready** - Battle-tested and optimized for production use
17
-
18
- ## 📋 Table of Contents
19
-
20
- - [Installation](https://github.com/revenium/revenium-middleware-perplexity-node#-installation)
21
- - [Three Ways to Use This Middleware](https://github.com/revenium/revenium-middleware-perplexity-node#-three-ways-to-use-this-middleware)
22
- - [Option 1: New Project with npm Package](https://github.com/revenium/revenium-middleware-perplexity-node#option-1-new-project-with-npm-package-recommended)
23
- - [Option 2: Clone and Use Locally](https://github.com/revenium/revenium-middleware-perplexity-node#option-2-clone-and-use-locally)
24
- - [Option 3: Add to Existing Project](https://github.com/revenium/revenium-middleware-perplexity-node#option-3-add-to-existing-project)
25
- - [Quick Start](https://github.com/revenium/revenium-middleware-perplexity-node#-quick-start)
26
- - [API Reference](https://github.com/revenium/revenium-middleware-perplexity-node#-api-reference)
27
- - [Examples](https://github.com/revenium/revenium-middleware-perplexity-node#-examples)
28
- - [Environment Variables](https://github.com/revenium/revenium-middleware-perplexity-node#-environment-variables)
29
-
30
- ## 📦 Installation
31
-
32
- ```bash
33
- npm install @revenium/perplexity
34
- ```
35
-
36
- ## 🎯 Three Ways to Use This Middleware
37
-
38
- ### Option 1: New Project with npm Package (Recommended)
39
-
40
- **Best for:** Starting a new project or adding Perplexity with Revenium to an existing project.
41
-
42
- #### Step 1: Create a new project
43
-
44
- ```bash
45
- mkdir my-perplexity-project
46
- cd my-perplexity-project
47
- npm init -y
48
- ```
49
-
50
- #### Step 2: Install the middleware
51
-
52
- ```bash
53
- npm install @revenium/perplexity dotenv
54
- ```
55
-
56
- #### Step 3: Create `.env` file
57
-
58
- ```env
59
- # Perplexity API Configuration
60
- PERPLEXITY_API_KEY=your_perplexity_api_key
61
-
62
- # Revenium Metering Configuration
63
- REVENIUM_METERING_API_KEY=your_revenium_api_key
64
- REVENIUM_METERING_BASE_URL=https://api.revenium.io/meter
65
- ```
66
-
67
- #### Step 4: Create `index.js`
68
-
69
- ```javascript
70
- const {
71
- initializeReveniumFromEnv,
72
- initializePerplexityFromEnv,
73
- createChatCompletion,
74
- PERPLEXITY_MODELS,
75
- } = require("@revenium/perplexity");
76
-
77
- async function main() {
78
- // Initialize configurations
79
- initializeReveniumFromEnv();
80
- initializePerplexityFromEnv();
81
-
82
- // Create a chat completion
83
- const result = await createChatCompletion({
84
- messages: [{ role: "user", content: "What is the capital of France?" }],
85
- model: PERPLEXITY_MODELS.SONAR_PRO,
86
- });
87
-
88
- console.log("Response:", result.content);
89
- console.log("Tokens used:", result.usage.totalTokens);
90
- }
91
-
92
- main().catch(console.error);
93
- ```
94
-
95
- #### Step 5: Run your project
96
-
97
- ```bash
98
- node index.js
99
- ```
100
-
101
- ---
102
-
103
- ### Option 2: Clone and Use Locally
104
-
105
- **Best for:** Development, testing, or contributing to the middleware.
106
-
107
- #### Step 1: Clone the repository
108
-
109
- ```bash
110
- git clone https://github.com/revenium/revenium-middleware-perplexity-node.git
111
- cd revenium-middleware-perplexity-node
112
- ```
113
-
114
- #### Step 2: Install dependencies
115
-
116
- ```bash
117
- npm install
118
- ```
119
-
120
- #### Step 3: Create `.env` file
121
-
122
- ```env
123
- # Perplexity API Configuration
124
- PERPLEXITY_API_KEY=your_perplexity_api_key
125
-
126
- # Revenium Metering Configuration
127
- REVENIUM_METERING_API_KEY=your_revenium_api_key
128
- REVENIUM_METERING_BASE_URL=https://api.revenium.io/meter
129
- ```
130
-
131
- #### Step 4: Build the project
132
-
133
- ```bash
134
- npm run build
135
- ```
136
-
137
- #### Step 5: Run examples
138
-
139
- **TypeScript Examples:**
140
-
141
- ```bash
142
- npm run example:basic # Basic chat completion
143
- npm run example:streaming # Streaming response
144
- npm run example:chat # Multi-turn conversation
145
- npm run example:metadata # Custom metadata
146
- ```
147
-
148
- **JavaScript Playground:**
149
-
150
- ```bash
151
- npm run playground:basic # Basic chat completion
152
- npm run playground:streaming # Streaming response
153
- npm run playground:chat # Multi-turn conversation
154
- npm run playground:metadata # Custom metadata
155
- ```
156
-
157
- #### Step 6: Use in your own code
158
-
159
- After building, you can import from the local build:
160
-
161
- ```javascript
162
- const {
163
- initializeReveniumFromEnv,
164
- initializePerplexityFromEnv,
165
- createChatCompletion,
166
- } = require("./dist/cjs");
167
-
168
- // Your code here...
169
- ```
170
-
171
- ---
172
-
173
- ### Option 3: Add to Existing Project
174
-
175
- **Best for:** Integrating Perplexity with Revenium into an existing Node.js project.
176
-
177
- #### Step 1: Install the middleware
178
-
179
- ```bash
180
- npm install @revenium/perplexity
181
- ```
182
-
183
- #### Step 2: Add environment variables
184
-
185
- Add to your existing `.env` file:
186
-
187
- ```env
188
- # Perplexity API Configuration
189
- PERPLEXITY_API_KEY=your_perplexity_api_key
190
-
191
- # Revenium Metering Configuration
192
- REVENIUM_METERING_API_KEY=your_revenium_api_key
193
- REVENIUM_METERING_BASE_URL=https://api.revenium.io/meter
194
- ```
195
-
196
- #### Step 3: Initialize in your application
197
-
198
- **For CommonJS projects:**
199
-
200
- ```javascript
201
- require("dotenv").config();
202
- const {
203
- initializeReveniumFromEnv,
204
- initializePerplexityFromEnv,
205
- createChatCompletion,
206
- PERPLEXITY_MODELS,
207
- } = require("@revenium/perplexity");
208
-
209
- // Initialize once at app startup
210
- initializeReveniumFromEnv();
211
- initializePerplexityFromEnv();
212
-
213
- // Use anywhere in your app
214
- async function askPerplexity(question) {
215
- const result = await createChatCompletion({
216
- messages: [{ role: "user", content: question }],
217
- model: PERPLEXITY_MODELS.SONAR_PRO,
218
- });
219
- return result.content;
220
- }
221
- ```
222
-
223
- **For ES Modules projects:**
224
-
225
- ```javascript
226
- import "dotenv/config";
227
- import {
228
- initializeReveniumFromEnv,
229
- initializePerplexityFromEnv,
230
- createChatCompletion,
231
- PERPLEXITY_MODELS,
232
- } from "@revenium/perplexity";
233
-
234
- // Initialize once at app startup
235
- initializeReveniumFromEnv();
236
- initializePerplexityFromEnv();
237
-
238
- // Use anywhere in your app
239
- export async function askPerplexity(question) {
240
- const result = await createChatCompletion({
241
- messages: [{ role: "user", content: question }],
242
- model: PERPLEXITY_MODELS.SONAR_PRO,
243
- });
244
- return result.content;
245
- }
246
- ```
247
-
248
- **For TypeScript projects:**
249
-
250
- ```typescript
251
- import "dotenv/config";
252
- import {
253
- initializeReveniumFromEnv,
254
- initializePerplexityFromEnv,
255
- createChatCompletion,
256
- PERPLEXITY_MODELS,
257
- type ChatCompletionResult,
258
- } from "@revenium/perplexity";
259
-
260
- // Initialize once at app startup
261
- initializeReveniumFromEnv();
262
- initializePerplexityFromEnv();
263
-
264
- // Use anywhere in your app
265
- export async function askPerplexity(question: string): Promise<string> {
266
- const result: ChatCompletionResult = await createChatCompletion({
267
- messages: [{ role: "user", content: question }],
268
- model: PERPLEXITY_MODELS.SONAR_PRO,
269
- });
270
- return result.content;
271
- }
272
- ```
273
-
274
- ---
275
-
276
- ## 🔧 Quick Start
277
-
278
- ### 1. Set up environment variables
279
-
280
- Create a `.env` file in your project root:
281
-
282
- ```env
283
- # Perplexity API Configuration
284
- PERPLEXITY_API_KEY=your_perplexity_api_key
285
-
286
- # Revenium Metering Configuration
287
- REVENIUM_METERING_API_KEY=your_revenium_api_key
288
- REVENIUM_METERING_BASE_URL=https://api.revenium.io/meter
289
- ```
290
-
291
- ### 2. Initialize and use
292
-
293
- ```typescript
294
- import {
295
- initializeReveniumFromEnv,
296
- initializePerplexityFromEnv,
297
- createChatCompletion,
298
- PERPLEXITY_MODELS,
299
- } from "@revenium/perplexity";
300
-
301
- // Initialize configurations
302
- initializeReveniumFromEnv();
303
- initializePerplexityFromEnv();
304
-
305
- // Create a chat completion
306
- const result = await createChatCompletion({
307
- messages: [{ role: "user", content: "What is the capital of France?" }],
308
- model: PERPLEXITY_MODELS.SONAR_PRO,
309
- });
310
-
311
- console.log(result.content);
312
- // Output: "The capital of France is Paris."
313
- ```
314
-
315
- ## 📚 API Reference
316
-
317
- ### Configuration
318
-
319
- #### `initializeReveniumFromEnv()`
320
-
321
- Initialize Revenium configuration from environment variables.
322
-
323
- ```typescript
324
- const config = initializeReveniumFromEnv();
325
- ```
326
-
327
- #### `initializePerplexityFromEnv()`
328
-
329
- Initialize Perplexity configuration from environment variables.
330
-
331
- ```typescript
332
- const config = initializePerplexityFromEnv();
333
- ```
334
-
335
- #### `initializeRevenium(config)`
336
-
337
- Initialize Revenium with custom configuration.
338
-
339
- ```typescript
340
- initializeRevenium({
341
- meteringApiKey: "your_api_key",
342
- meteringBaseUrl: "https://api.revenium.io/meter",
343
- teamId: "your_team_id", // Optional
344
- });
345
- ```
346
-
347
- #### `initializePerplexity(config)`
348
-
349
- Initialize Perplexity with custom configuration.
350
-
351
- ```typescript
352
- initializePerplexity({
353
- apiKey: "your_perplexity_api_key",
354
- baseUrl: "https://api.perplexity.ai", // Optional
355
- });
356
- ```
357
-
358
- ### Chat Completions
359
-
360
- #### `createChatCompletion(params)`
361
-
362
- Create a chat completion with automatic metering.
363
-
364
- ```typescript
365
- const result = await createChatCompletion({
366
- messages: [
367
- { role: "system", content: "You are a helpful assistant." },
368
- { role: "user", content: "Hello!" },
369
- ],
370
- model: PERPLEXITY_MODELS.SONAR_PRO,
371
- maxTokens: 100,
372
- temperature: 0.7,
373
- usageMetadata: {
374
- // Optional
375
- subscriber: { id: "user-123" },
376
- organizationId: "org-456",
377
- productId: "product-789",
378
- },
379
- });
380
-
381
- console.log(result.content);
382
- console.log(result.usage);
383
- console.log(result.transactionId);
384
- ```
385
-
386
- **Parameters:**
387
-
388
- - `messages` - Array of message objects with `role` and `content`
389
- - `model` - Perplexity model to use (see [Available Models](https://github.com/revenium/revenium-middleware-perplexity-node#available-models))
390
- - `maxTokens` - Maximum tokens to generate (optional)
391
- - `temperature` - Sampling temperature 0-2 (optional)
392
- - `topP` - Nucleus sampling parameter (optional)
393
- - `presencePenalty` - Presence penalty -2 to 2 (optional)
394
- - `frequencyPenalty` - Frequency penalty -2 to 2 (optional)
395
- - `usageMetadata` - Custom metadata for tracking (optional)
396
-
397
- **Returns:**
398
-
399
- ```typescript
400
- {
401
- content: string;
402
- role: string;
403
- finishReason: string | null;
404
- usage: {
405
- promptTokens: number;
406
- completionTokens: number;
407
- totalTokens: number;
408
- }
409
- model: string;
410
- transactionId: string;
411
- rawResponse: PerplexityResponse;
412
- }
413
- ```
414
-
415
- #### `createStreamingChatCompletion(params)`
416
-
417
- Create a streaming chat completion.
418
-
419
- ```typescript
420
- const result = await createStreamingChatCompletion({
421
- messages: [{ role: "user", content: "Count from 1 to 5" }],
422
- model: PERPLEXITY_MODELS.SONAR_PRO,
423
- });
424
-
425
- for await (const chunk of result.stream) {
426
- const content = chunk.choices[0]?.delta?.content || "";
427
- process.stdout.write(content);
428
- }
429
- ```
430
-
431
- **Returns:**
432
-
433
- ```typescript
434
- {
435
- stream: AsyncGenerator<PerplexityStreamChunk>;
436
- transactionId: string;
437
- model: string;
438
- }
439
- ```
440
-
441
- ### Available Models
442
-
443
- ```typescript
444
- import { PERPLEXITY_MODELS } from "@revenium/perplexity";
445
-
446
- // Online Models (with internet access)
447
- PERPLEXITY_MODELS.SONAR; // "sonar"
448
- PERPLEXITY_MODELS.SONAR_PRO; // "sonar-pro"
449
- PERPLEXITY_MODELS.SONAR_REASONING; // "sonar-reasoning"
450
-
451
- // Chat Models (offline)
452
- PERPLEXITY_MODELS.LLAMA_3_1_SONAR_SMALL_128K_CHAT; // "llama-3.1-sonar-small-128k-chat"
453
- PERPLEXITY_MODELS.LLAMA_3_1_SONAR_LARGE_128K_CHAT; // "llama-3.1-sonar-large-128k-chat"
454
- PERPLEXITY_MODELS.LLAMA_3_1_SONAR_HUGE_128K_CHAT; // "llama-3.1-sonar-huge-128k-chat"
455
- ```
456
-
457
- ### Utility Functions
458
-
459
- #### `disableRevenium()` / `enableRevenium()`
460
-
461
- Temporarily disable or enable Revenium metering.
462
-
463
- ```typescript
464
- import { disableRevenium, enableRevenium } from "@revenium/perplexity";
465
-
466
- disableRevenium(); // Stop sending metering data
467
- // ... make API calls ...
468
- enableRevenium(); // Resume sending metering data
469
- ```
470
-
471
- #### `generateTransactionId()`
472
-
473
- Generate a unique transaction ID.
474
-
475
- ```typescript
476
- import { generateTransactionId } from "@revenium/perplexity";
477
-
478
- const txnId = generateTransactionId();
479
- ```
480
-
481
- ## 📖 Examples
482
-
483
- ### Basic Chat Completion
484
-
485
- ```typescript
486
- import {
487
- initializeReveniumFromEnv,
488
- initializePerplexityFromEnv,
489
- createChatCompletion,
490
- PERPLEXITY_MODELS,
491
- } from "@revenium/perplexity";
492
-
493
- initializeReveniumFromEnv();
494
- initializePerplexityFromEnv();
495
-
496
- const result = await createChatCompletion({
497
- messages: [{ role: "user", content: "What is the capital of France?" }],
498
- model: PERPLEXITY_MODELS.SONAR_PRO,
499
- });
500
-
501
- console.log(result.content);
502
- ```
503
-
504
- ### Streaming Response
505
-
506
- ```typescript
507
- const result = await createStreamingChatCompletion({
508
- messages: [{ role: "user", content: "Write a short poem about AI" }],
509
- model: PERPLEXITY_MODELS.SONAR_PRO,
510
- });
511
-
512
- for await (const chunk of result.stream) {
513
- const content = chunk.choices[0]?.delta?.content || "";
514
- process.stdout.write(content);
515
- }
516
- ```
517
-
518
- ### Multi-turn Conversation
519
-
520
- ```typescript
521
- const messages = [
522
- { role: "system", content: "You are a helpful assistant." },
523
- { role: "user", content: "What is the capital of France?" },
524
- ];
525
-
526
- const response1 = await createChatCompletion({
527
- messages,
528
- model: PERPLEXITY_MODELS.SONAR_PRO,
529
- });
530
-
531
- messages.push({ role: "assistant", content: response1.content });
532
- messages.push({ role: "user", content: "What is its population?" });
533
-
534
- const response2 = await createChatCompletion({
535
- messages,
536
- model: PERPLEXITY_MODELS.SONAR_PRO,
537
- });
538
- ```
539
-
540
- ### Custom Metadata
541
-
542
- ```typescript
543
- const result = await createChatCompletion({
544
- messages: [{ role: "user", content: "Hello!" }],
545
- model: PERPLEXITY_MODELS.SONAR_PRO,
546
- usageMetadata: {
547
- subscriber: {
548
- id: "user-123",
549
- email: "user@example.com",
550
- },
551
- organizationId: "org-456",
552
- productId: "premium-plan",
553
- traceId: "trace-abc-123",
554
- },
555
- });
556
- ```
557
-
558
- ## 🏗️ Project Structure
559
-
560
- ```
561
- revenium-middleware-perplexity-node/
562
- ├── src/
563
- │ ├── core/
564
- │ │ ├── config/ # Configuration management
565
- │ │ ├── tracking/ # Metering and tracking
566
- │ │ └── wrapper/ # Perplexity API wrapper
567
- │ ├── types/ # TypeScript type definitions
568
- │ ├── utils/ # Utility functions
569
- │ └── index.ts # Main entry point
570
- ├── examples/ # TypeScript examples
571
- ├── playground/ # JavaScript examples
572
- └── dist/
573
- ├── cjs/ # CommonJS build
574
- ├── esm/ # ES Modules build
575
- └── types/ # TypeScript definitions
576
- ```
577
-
578
- ## 🧪 Running Examples
579
-
580
- ### TypeScript Examples
581
-
582
- ```bash
583
- npm run example:basic # Basic chat completion
584
- npm run example:streaming # Streaming response
585
- npm run example:chat # Multi-turn conversation
586
- npm run example:metadata # Custom metadata
587
- ```
588
-
589
- ### JavaScript Playground
590
-
591
- ```bash
592
- npm run playground:basic # Basic chat completion
593
- npm run playground:streaming # Streaming response
594
- npm run playground:chat # Multi-turn conversation
595
- npm run playground:metadata # Custom metadata
596
- ```
597
-
598
- ## 🔒 Environment Variables
599
-
600
- | Variable | Required | Description |
601
- | ---------------------------- | -------- | ------------------------------------------------------------------ |
602
- | `PERPLEXITY_API_KEY` | Yes | Your Perplexity API key |
603
- | `REVENIUM_METERING_API_KEY` | Yes | Your Revenium metering API key |
604
- | `REVENIUM_METERING_BASE_URL` | Yes | Revenium metering endpoint (e.g., `https://api.revenium.io/meter`) |
605
-
606
- ## 📄 License
607
-
608
- ISC
609
-
610
- ## 🤝 Contributing
611
-
612
- Contributions are welcome! Please feel free to submit a Pull Request.
613
-
614
- ## 📞 Support
615
-
616
- For issues and questions:
617
-
618
- - GitHub Issues: [revenium-middleware-perplexity-node/issues](https://github.com/revenium/revenium-middleware-perplexity-node/issues)
619
- - Documentation: [Revenium Docs](https://docs.revenium.io)
620
-
621
- ## 🔗 Links
622
-
623
- - [Perplexity AI Documentation](https://docs.perplexity.ai)
624
- - [Revenium Platform](https://revenium.io)
625
- - [npm Package](https://www.npmjs.com/package/@revenium/perplexity)
1
+ # Revenium Middleware for Perplexity
2
+
3
+ A lightweight, production-ready middleware that adds **Revenium metering and tracking** to Perplexity AI API calls.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@revenium/perplexity.svg)](https://www.npmjs.com/package/@revenium/perplexity)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Features
9
+
10
+ - ✅ **Zero Configuration** - Works out of the box with environment variables
11
+ - ✅ **Automatic Metering** - Tracks all API calls with detailed usage metrics
12
+ - ✅ **Streaming Support** - Full support for streaming responses
13
+ - ✅ **TypeScript First** - Built with TypeScript, includes full type definitions
14
+ - ✅ **Multi-Format** - Supports both ESM and CommonJS
15
+ - ✅ **Custom Metadata** - Add custom tracking metadata to any request
16
+ - ✅ **Production Ready** - Battle-tested and optimized for production use
17
+
18
+ ## Package Migration
19
+
20
+ This package has been renamed from `revenium-middleware-perplexity-node` to `@revenium/perplexity` for better organization and simpler naming.
21
+
22
+ ### Migration Steps
23
+
24
+ If you're upgrading from the old package:
25
+
26
+ ```bash
27
+ # Uninstall the old package
28
+ npm uninstall revenium-middleware-perplexity-node
29
+
30
+ # Install the new package
31
+ npm install @revenium/perplexity
32
+ ```
33
+
34
+ **Update your imports:**
35
+
36
+ ```typescript
37
+ // Old import
38
+ import "revenium-middleware-perplexity-node";
39
+
40
+ // New import
41
+ import "@revenium/perplexity";
42
+ ```
43
+
44
+ All functionality remains exactly the same - only the package name has changed.
45
+
46
+ ## Table of Contents
47
+
48
+ - [Installation](https://github.com/revenium/revenium-middleware-perplexity-node#-installation)
49
+ - [Three Ways to Use This Middleware](https://github.com/revenium/revenium-middleware-perplexity-node#-three-ways-to-use-this-middleware)
50
+ - [Option 1: New Project with npm Package](https://github.com/revenium/revenium-middleware-perplexity-node#option-1-new-project-with-npm-package-recommended)
51
+ - [Option 2: Clone and Use Locally](https://github.com/revenium/revenium-middleware-perplexity-node#option-2-clone-and-use-locally)
52
+ - [Option 3: Add to Existing Project](https://github.com/revenium/revenium-middleware-perplexity-node#option-3-add-to-existing-project)
53
+ - [Quick Start](https://github.com/revenium/revenium-middleware-perplexity-node#-quick-start)
54
+ - [API Reference](https://github.com/revenium/revenium-middleware-perplexity-node#-api-reference)
55
+ - [Examples](https://github.com/revenium/revenium-middleware-perplexity-node#-examples)
56
+ - [Environment Variables](https://github.com/revenium/revenium-middleware-perplexity-node#-environment-variables)
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ npm install @revenium/perplexity
62
+ ```
63
+
64
+ ## Three Ways to Use This Middleware
65
+
66
+ ### Option 1: New Project with npm Package (Recommended)
67
+
68
+ **Best for:** Starting a new project or adding Perplexity with Revenium to an existing project.
69
+
70
+ #### Step 1: Create a new project
71
+
72
+ ```bash
73
+ mkdir my-perplexity-project
74
+ cd my-perplexity-project
75
+ npm init -y
76
+ ```
77
+
78
+ #### Step 2: Install the middleware
79
+
80
+ ```bash
81
+ npm install @revenium/perplexity dotenv
82
+ ```
83
+
84
+ #### Step 3: Create `.env` file
85
+
86
+ ```env
87
+ # Perplexity API Configuration
88
+ PERPLEXITY_API_KEY=your_perplexity_api_key
89
+
90
+ # Revenium Metering Configuration
91
+ REVENIUM_METERING_API_KEY=your_revenium_api_key
92
+ REVENIUM_METERING_BASE_URL=https://api.revenium.io/meter
93
+ ```
94
+
95
+ #### Step 4: Create `index.js`
96
+
97
+ ```javascript
98
+ const {
99
+ initializeReveniumFromEnv,
100
+ initializePerplexityFromEnv,
101
+ createChatCompletion,
102
+ PERPLEXITY_MODELS,
103
+ } = require("@revenium/perplexity");
104
+
105
+ async function main() {
106
+ // Initialize configurations
107
+ initializeReveniumFromEnv();
108
+ initializePerplexityFromEnv();
109
+
110
+ // Create a chat completion
111
+ const result = await createChatCompletion({
112
+ messages: [{ role: "user", content: "What is the capital of France?" }],
113
+ model: PERPLEXITY_MODELS.SONAR_PRO,
114
+ });
115
+
116
+ console.log("Response:", result.content);
117
+ console.log("Tokens used:", result.usage.totalTokens);
118
+ }
119
+
120
+ main().catch(console.error);
121
+ ```
122
+
123
+ #### Step 5: Run your project
124
+
125
+ ```bash
126
+ node index.js
127
+ ```
128
+
129
+ ---
130
+
131
+ ### Option 2: Clone and Use Locally
132
+
133
+ **Best for:** Development, testing, or contributing to the middleware.
134
+
135
+ #### Step 1: Clone the repository
136
+
137
+ ```bash
138
+ git clone https://github.com/revenium/revenium-middleware-perplexity-node.git
139
+ cd revenium-middleware-perplexity-node
140
+ ```
141
+
142
+ #### Step 2: Install dependencies
143
+
144
+ ```bash
145
+ npm install
146
+ ```
147
+
148
+ #### Step 3: Create `.env` file
149
+
150
+ ```env
151
+ # Perplexity API Configuration
152
+ PERPLEXITY_API_KEY=your_perplexity_api_key
153
+
154
+ # Revenium Metering Configuration
155
+ REVENIUM_METERING_API_KEY=your_revenium_api_key
156
+ REVENIUM_METERING_BASE_URL=https://api.revenium.io/meter
157
+ ```
158
+
159
+ #### Step 4: Build the project
160
+
161
+ ```bash
162
+ npm run build
163
+ ```
164
+
165
+ #### Step 5: Run examples
166
+
167
+ **TypeScript Examples:**
168
+
169
+ ```bash
170
+ npm run example:basic # Basic chat completion
171
+ npm run example:streaming # Streaming response
172
+ npm run example:chat # Multi-turn conversation
173
+ npm run example:metadata # Custom metadata
174
+ ```
175
+
176
+ **JavaScript Playground:**
177
+
178
+ ```bash
179
+ npm run playground:basic # Basic chat completion
180
+ npm run playground:streaming # Streaming response
181
+ npm run playground:chat # Multi-turn conversation
182
+ npm run playground:metadata # Custom metadata
183
+ ```
184
+
185
+ #### Step 6: Use in your own code
186
+
187
+ After building, you can import from the local build:
188
+
189
+ ```javascript
190
+ const {
191
+ initializeReveniumFromEnv,
192
+ initializePerplexityFromEnv,
193
+ createChatCompletion,
194
+ } = require("./dist/cjs");
195
+
196
+ // Your code here...
197
+ ```
198
+
199
+ ---
200
+
201
+ ### Option 3: Add to Existing Project
202
+
203
+ **Best for:** Integrating Perplexity with Revenium into an existing Node.js project.
204
+
205
+ #### Step 1: Install the middleware
206
+
207
+ ```bash
208
+ npm install @revenium/perplexity
209
+ ```
210
+
211
+ #### Step 2: Add environment variables
212
+
213
+ Add to your existing `.env` file:
214
+
215
+ ```env
216
+ # Perplexity API Configuration
217
+ PERPLEXITY_API_KEY=your_perplexity_api_key
218
+
219
+ # Revenium Metering Configuration
220
+ REVENIUM_METERING_API_KEY=your_revenium_api_key
221
+ REVENIUM_METERING_BASE_URL=https://api.revenium.io/meter
222
+ ```
223
+
224
+ #### Step 3: Initialize in your application
225
+
226
+ **For CommonJS projects:**
227
+
228
+ ```javascript
229
+ require("dotenv").config();
230
+ const {
231
+ initializeReveniumFromEnv,
232
+ initializePerplexityFromEnv,
233
+ createChatCompletion,
234
+ PERPLEXITY_MODELS,
235
+ } = require("@revenium/perplexity");
236
+
237
+ // Initialize once at app startup
238
+ initializeReveniumFromEnv();
239
+ initializePerplexityFromEnv();
240
+
241
+ // Use anywhere in your app
242
+ async function askPerplexity(question) {
243
+ const result = await createChatCompletion({
244
+ messages: [{ role: "user", content: question }],
245
+ model: PERPLEXITY_MODELS.SONAR_PRO,
246
+ });
247
+ return result.content;
248
+ }
249
+ ```
250
+
251
+ **For ES Modules projects:**
252
+
253
+ ```javascript
254
+ import "dotenv/config";
255
+ import {
256
+ initializeReveniumFromEnv,
257
+ initializePerplexityFromEnv,
258
+ createChatCompletion,
259
+ PERPLEXITY_MODELS,
260
+ } from "@revenium/perplexity";
261
+
262
+ // Initialize once at app startup
263
+ initializeReveniumFromEnv();
264
+ initializePerplexityFromEnv();
265
+
266
+ // Use anywhere in your app
267
+ export async function askPerplexity(question) {
268
+ const result = await createChatCompletion({
269
+ messages: [{ role: "user", content: question }],
270
+ model: PERPLEXITY_MODELS.SONAR_PRO,
271
+ });
272
+ return result.content;
273
+ }
274
+ ```
275
+
276
+ **For TypeScript projects:**
277
+
278
+ ```typescript
279
+ import "dotenv/config";
280
+ import {
281
+ initializeReveniumFromEnv,
282
+ initializePerplexityFromEnv,
283
+ createChatCompletion,
284
+ PERPLEXITY_MODELS,
285
+ type ChatCompletionResult,
286
+ } from "@revenium/perplexity";
287
+
288
+ // Initialize once at app startup
289
+ initializeReveniumFromEnv();
290
+ initializePerplexityFromEnv();
291
+
292
+ // Use anywhere in your app
293
+ export async function askPerplexity(question: string): Promise<string> {
294
+ const result: ChatCompletionResult = await createChatCompletion({
295
+ messages: [{ role: "user", content: question }],
296
+ model: PERPLEXITY_MODELS.SONAR_PRO,
297
+ });
298
+ return result.content;
299
+ }
300
+ ```
301
+
302
+ ---
303
+
304
+ ## Quick Start
305
+
306
+ ### 1. Set up environment variables
307
+
308
+ Create a `.env` file in your project root:
309
+
310
+ ```env
311
+ # Perplexity API Configuration
312
+ PERPLEXITY_API_KEY=your_perplexity_api_key
313
+
314
+ # Revenium Metering Configuration
315
+ REVENIUM_METERING_API_KEY=your_revenium_api_key
316
+ REVENIUM_METERING_BASE_URL=https://api.revenium.io/meter
317
+ ```
318
+
319
+ ### 2. Initialize and use
320
+
321
+ ```typescript
322
+ import {
323
+ initializeReveniumFromEnv,
324
+ initializePerplexityFromEnv,
325
+ createChatCompletion,
326
+ PERPLEXITY_MODELS,
327
+ } from "@revenium/perplexity";
328
+
329
+ // Initialize configurations
330
+ initializeReveniumFromEnv();
331
+ initializePerplexityFromEnv();
332
+
333
+ // Create a chat completion
334
+ const result = await createChatCompletion({
335
+ messages: [{ role: "user", content: "What is the capital of France?" }],
336
+ model: PERPLEXITY_MODELS.SONAR_PRO,
337
+ });
338
+
339
+ console.log(result.content);
340
+ // Output: "The capital of France is Paris."
341
+ ```
342
+
343
+ ## API Reference
344
+
345
+ ### Configuration
346
+
347
+ #### `initializeReveniumFromEnv()`
348
+
349
+ Initialize Revenium configuration from environment variables.
350
+
351
+ ```typescript
352
+ const config = initializeReveniumFromEnv();
353
+ ```
354
+
355
+ #### `initializePerplexityFromEnv()`
356
+
357
+ Initialize Perplexity configuration from environment variables.
358
+
359
+ ```typescript
360
+ const config = initializePerplexityFromEnv();
361
+ ```
362
+
363
+ #### `initializeRevenium(config)`
364
+
365
+ Initialize Revenium with custom configuration.
366
+
367
+ ```typescript
368
+ initializeRevenium({
369
+ meteringApiKey: "your_api_key",
370
+ meteringBaseUrl: "https://api.revenium.io/meter",
371
+ teamId: "your_team_id", // Optional
372
+ });
373
+ ```
374
+
375
+ #### `initializePerplexity(config)`
376
+
377
+ Initialize Perplexity with custom configuration.
378
+
379
+ ```typescript
380
+ initializePerplexity({
381
+ apiKey: "your_perplexity_api_key",
382
+ baseUrl: "https://api.perplexity.ai", // Optional
383
+ });
384
+ ```
385
+
386
+ ### Chat Completions
387
+
388
+ #### `createChatCompletion(params)`
389
+
390
+ Create a chat completion with automatic metering.
391
+
392
+ ```typescript
393
+ const result = await createChatCompletion({
394
+ messages: [
395
+ { role: "system", content: "You are a helpful assistant." },
396
+ { role: "user", content: "Hello!" },
397
+ ],
398
+ model: PERPLEXITY_MODELS.SONAR_PRO,
399
+ maxTokens: 100,
400
+ temperature: 0.7,
401
+ usageMetadata: {
402
+ // Optional
403
+ subscriber: { id: "user-123" },
404
+ organizationId: "org-456",
405
+ productId: "product-789",
406
+ },
407
+ });
408
+
409
+ console.log(result.content);
410
+ console.log(result.usage);
411
+ console.log(result.transactionId);
412
+ ```
413
+
414
+ **Parameters:**
415
+
416
+ - `messages` - Array of message objects with `role` and `content`
417
+ - `model` - Perplexity model to use (see [Available Models](https://github.com/revenium/revenium-middleware-perplexity-node#available-models))
418
+ - `maxTokens` - Maximum tokens to generate (optional)
419
+ - `temperature` - Sampling temperature 0-2 (optional)
420
+ - `topP` - Nucleus sampling parameter (optional)
421
+ - `presencePenalty` - Presence penalty -2 to 2 (optional)
422
+ - `frequencyPenalty` - Frequency penalty -2 to 2 (optional)
423
+ - `usageMetadata` - Custom metadata for tracking (optional)
424
+
425
+ **Returns:**
426
+
427
+ ```typescript
428
+ {
429
+ content: string;
430
+ role: string;
431
+ finishReason: string | null;
432
+ usage: {
433
+ promptTokens: number;
434
+ completionTokens: number;
435
+ totalTokens: number;
436
+ }
437
+ model: string;
438
+ transactionId: string;
439
+ rawResponse: PerplexityResponse;
440
+ }
441
+ ```
442
+
443
+ #### `createStreamingChatCompletion(params)`
444
+
445
+ Create a streaming chat completion.
446
+
447
+ ```typescript
448
+ const result = await createStreamingChatCompletion({
449
+ messages: [{ role: "user", content: "Count from 1 to 5" }],
450
+ model: PERPLEXITY_MODELS.SONAR_PRO,
451
+ });
452
+
453
+ for await (const chunk of result.stream) {
454
+ const content = chunk.choices[0]?.delta?.content || "";
455
+ process.stdout.write(content);
456
+ }
457
+ ```
458
+
459
+ **Returns:**
460
+
461
+ ```typescript
462
+ {
463
+ stream: AsyncGenerator<PerplexityStreamChunk>;
464
+ transactionId: string;
465
+ model: string;
466
+ }
467
+ ```
468
+
469
+ ### Available Models
470
+
471
+ ```typescript
472
+ import { PERPLEXITY_MODELS } from "@revenium/perplexity";
473
+
474
+ // Online Models (with internet access)
475
+ PERPLEXITY_MODELS.SONAR; // "sonar"
476
+ PERPLEXITY_MODELS.SONAR_PRO; // "sonar-pro"
477
+ PERPLEXITY_MODELS.SONAR_REASONING; // "sonar-reasoning"
478
+
479
+ // Chat Models (offline)
480
+ PERPLEXITY_MODELS.LLAMA_3_1_SONAR_SMALL_128K_CHAT; // "llama-3.1-sonar-small-128k-chat"
481
+ PERPLEXITY_MODELS.LLAMA_3_1_SONAR_LARGE_128K_CHAT; // "llama-3.1-sonar-large-128k-chat"
482
+ PERPLEXITY_MODELS.LLAMA_3_1_SONAR_HUGE_128K_CHAT; // "llama-3.1-sonar-huge-128k-chat"
483
+ ```
484
+
485
+ ### Utility Functions
486
+
487
+ #### `disableRevenium()` / `enableRevenium()`
488
+
489
+ Temporarily disable or enable Revenium metering.
490
+
491
+ ```typescript
492
+ import { disableRevenium, enableRevenium } from "@revenium/perplexity";
493
+
494
+ disableRevenium(); // Stop sending metering data
495
+ // ... make API calls ...
496
+ enableRevenium(); // Resume sending metering data
497
+ ```
498
+
499
+ #### `generateTransactionId()`
500
+
501
+ Generate a unique transaction ID.
502
+
503
+ ```typescript
504
+ import { generateTransactionId } from "@revenium/perplexity";
505
+
506
+ const txnId = generateTransactionId();
507
+ ```
508
+
509
+ ## Examples
510
+
511
+ ### Basic Chat Completion
512
+
513
+ ```typescript
514
+ import {
515
+ initializeReveniumFromEnv,
516
+ initializePerplexityFromEnv,
517
+ createChatCompletion,
518
+ PERPLEXITY_MODELS,
519
+ } from "@revenium/perplexity";
520
+
521
+ initializeReveniumFromEnv();
522
+ initializePerplexityFromEnv();
523
+
524
+ const result = await createChatCompletion({
525
+ messages: [{ role: "user", content: "What is the capital of France?" }],
526
+ model: PERPLEXITY_MODELS.SONAR_PRO,
527
+ });
528
+
529
+ console.log(result.content);
530
+ ```
531
+
532
+ ### Streaming Response
533
+
534
+ ```typescript
535
+ const result = await createStreamingChatCompletion({
536
+ messages: [{ role: "user", content: "Write a short poem about AI" }],
537
+ model: PERPLEXITY_MODELS.SONAR_PRO,
538
+ });
539
+
540
+ for await (const chunk of result.stream) {
541
+ const content = chunk.choices[0]?.delta?.content || "";
542
+ process.stdout.write(content);
543
+ }
544
+ ```
545
+
546
+ ### Multi-turn Conversation
547
+
548
+ ```typescript
549
+ const messages = [
550
+ { role: "system", content: "You are a helpful assistant." },
551
+ { role: "user", content: "What is the capital of France?" },
552
+ ];
553
+
554
+ const response1 = await createChatCompletion({
555
+ messages,
556
+ model: PERPLEXITY_MODELS.SONAR_PRO,
557
+ });
558
+
559
+ messages.push({ role: "assistant", content: response1.content });
560
+ messages.push({ role: "user", content: "What is its population?" });
561
+
562
+ const response2 = await createChatCompletion({
563
+ messages,
564
+ model: PERPLEXITY_MODELS.SONAR_PRO,
565
+ });
566
+ ```
567
+
568
+ ### Custom Metadata
569
+
570
+ ```typescript
571
+ const result = await createChatCompletion({
572
+ messages: [{ role: "user", content: "Hello!" }],
573
+ model: PERPLEXITY_MODELS.SONAR_PRO,
574
+ usageMetadata: {
575
+ subscriber: {
576
+ id: "user-123",
577
+ email: "user@example.com",
578
+ },
579
+ organizationId: "org-456",
580
+ productId: "premium-plan",
581
+ traceId: "trace-abc-123",
582
+ },
583
+ });
584
+ ```
585
+
586
+ ## What Gets Tracked
587
+
588
+ The middleware automatically captures:
589
+
590
+ - **Token Usage**: Prompt and completion tokens for accurate billing
591
+ - **Request Duration**: Total time for each API call
592
+ - **Model Information**: Which Perplexity model was used
593
+ - **Operation Type**: Chat completion, streaming, etc.
594
+ - **Error Tracking**: Failed requests and error details
595
+ - **Streaming Metrics**: Time to first token for streaming responses
596
+ - **Custom Metadata**: Business context you provide
597
+
598
+ ## Advanced Usage
599
+
600
+ ### Streaming Responses
601
+
602
+ ```typescript
603
+ import {
604
+ initializeReveniumFromEnv,
605
+ initializePerplexityFromEnv,
606
+ createStreamingChatCompletion,
607
+ PERPLEXITY_MODELS,
608
+ } from "@revenium/perplexity";
609
+
610
+ initializeReveniumFromEnv();
611
+ initializePerplexityFromEnv();
612
+
613
+ const result = await createStreamingChatCompletion({
614
+ messages: [{ role: "user", content: "Count from 1 to 5" }],
615
+ model: PERPLEXITY_MODELS.SONAR_PRO,
616
+ usageMetadata: {
617
+ subscriber: { id: "user-123" },
618
+ taskType: "counting-demo",
619
+ },
620
+ });
621
+
622
+ for await (const chunk of result.stream) {
623
+ const content = chunk.choices[0]?.delta?.content || "";
624
+ process.stdout.write(content);
625
+ }
626
+ ```
627
+
628
+ ### Custom Metadata Tracking
629
+
630
+ Add business context to your AI usage:
631
+
632
+ ```typescript
633
+ const customMetadata = {
634
+ subscriber: {
635
+ id: "user-789",
636
+ email: "user@company.com",
637
+ credential: {
638
+ name: "premium-user",
639
+ value: "tier-1",
640
+ },
641
+ },
642
+ organizationId: "org-456",
643
+ productId: "premium-plan",
644
+ taskType: "RESEARCH",
645
+ agent: "ResearchBot",
646
+ traceId: "session-123",
647
+ responseQualityScore: 9.2,
648
+ };
649
+
650
+ const result = await createChatCompletion({
651
+ messages: [{ role: "user", content: "Research AI trends" }],
652
+ model: PERPLEXITY_MODELS.SONAR_PRO,
653
+ usageMetadata: customMetadata,
654
+ });
655
+ ```
656
+
657
+ ### Usage Metadata Interface
658
+
659
+ All metadata fields are optional:
660
+
661
+ ```typescript
662
+ interface UsageMetadata {
663
+ traceId?: string; // Session or conversation ID
664
+ taskType?: string; // Type of AI task
665
+ organizationId?: string; // Organization/company ID
666
+ subscriptionId?: string; // Billing plan ID
667
+ productId?: string; // Your product/feature ID
668
+ agent?: string; // AI agent identifier
669
+ responseQualityScore?: number; // Quality score (0-1)
670
+ subscriber?: {
671
+ id?: string; // User ID from your system
672
+ email?: string; // User's email address
673
+ credential?: {
674
+ name?: string; // Credential name
675
+ value?: string; // Credential value
676
+ };
677
+ };
678
+ }
679
+ ```
680
+
681
+ ## Configuration Options
682
+
683
+ ### Environment Variables
684
+
685
+ | Variable | Required | Default | Description |
686
+ | ---------------------------- | -------- | ------------------------------- | --------------------------------- |
687
+ | `PERPLEXITY_API_KEY` | Yes | - | Your Perplexity API key |
688
+ | `REVENIUM_METERING_API_KEY` | Yes | - | Your Revenium API key |
689
+ | `REVENIUM_METERING_BASE_URL` | Yes | - | Revenium metering API base URL |
690
+ | `PERPLEXITY_API_BASE_URL` | No | `https://api.perplexity.ai` | Perplexity API base URL |
691
+ | `DEBUG` | No | `false` | Enable debug logging |
692
+
693
+ ### Manual Configuration
694
+
695
+ ```typescript
696
+ import {
697
+ initializeRevenium,
698
+ initializePerplexity,
699
+ createChatCompletion,
700
+ } from "@revenium/perplexity";
701
+
702
+ // Manual configuration
703
+ initializeRevenium({
704
+ meteringApiKey: "hak_your_revenium_key",
705
+ meteringBaseUrl: "https://api.revenium.io/meter/v2",
706
+ });
707
+
708
+ initializePerplexity({
709
+ apiKey: "pplx_your_perplexity_key",
710
+ baseUrl: "https://api.perplexity.ai",
711
+ });
712
+ ```
713
+
714
+ ## Troubleshooting
715
+
716
+ ### Common Issues
717
+
718
+ #### "Missing API Key" Error
719
+
720
+ ```bash
721
+ # Make sure you've set the API keys
722
+ export PERPLEXITY_API_KEY="pplx_your_actual_api_key"
723
+ export REVENIUM_METERING_API_KEY="hak_your_actual_revenium_key"
724
+
725
+ # Verify they're set
726
+ echo $PERPLEXITY_API_KEY
727
+ echo $REVENIUM_METERING_API_KEY
728
+ ```
729
+
730
+ #### "Requests not being tracked"
731
+
732
+ ```bash
733
+ # Verify Revenium configuration
734
+ export REVENIUM_METERING_API_KEY="hak_your_actual_revenium_key"
735
+ export REVENIUM_METERING_BASE_URL="https://api.revenium.io/meter/v2"
736
+
737
+ # Enable debug logging to see what's happening
738
+ export DEBUG="true"
739
+ ```
740
+
741
+ #### TypeScript errors with usageMetadata
742
+
743
+ - Ensure you're importing from `@revenium/perplexity`
744
+ - Check that your TypeScript version is 5.0+
745
+ - Verify you're using the latest version: `npm update @revenium/perplexity`
746
+
747
+ #### Build/Import Errors
748
+
749
+ ```bash
750
+ # Clean and reinstall
751
+ rm -rf node_modules
752
+ npm install
753
+
754
+ # For TypeScript projects
755
+ npm run build
756
+ ```
757
+
758
+ ### Debug Mode
759
+
760
+ Enable debug logging to troubleshoot issues:
761
+
762
+ ```bash
763
+ export DEBUG="true"
764
+ node your-script.js
765
+ ```
766
+
767
+ This will show:
768
+
769
+ - Initialization details
770
+ - Configuration loading
771
+ - API call information
772
+ - Error details
773
+
774
+ ## Project Structure
775
+
776
+ ```
777
+ revenium-middleware-perplexity-node/
778
+ ├── src/
779
+ │ ├── core/
780
+ │ │ ├── config/ # Configuration management
781
+ │ │ ├── tracking/ # Metering and tracking
782
+ │ │ └── wrapper/ # Perplexity API wrapper
783
+ │ ├── types/ # TypeScript type definitions
784
+ │ ├── utils/ # Utility functions
785
+ │ └── index.ts # Main entry point
786
+ ├── examples/ # TypeScript examples
787
+ ├── playground/ # JavaScript examples
788
+ └── dist/
789
+ ├── cjs/ # CommonJS build
790
+ ├── esm/ # ES Modules build
791
+ └── types/ # TypeScript definitions
792
+ ```
793
+
794
+ ## Running Examples
795
+
796
+ ### TypeScript Examples
797
+
798
+ ```bash
799
+ npm run example:basic # Basic chat completion
800
+ npm run example:streaming # Streaming response
801
+ npm run example:chat # Multi-turn conversation
802
+ npm run example:metadata # Custom metadata
803
+ ```
804
+
805
+ ### JavaScript Playground
806
+
807
+ ```bash
808
+ npm run playground:basic # Basic chat completion
809
+ npm run playground:streaming # Streaming response
810
+ npm run playground:chat # Multi-turn conversation
811
+ npm run playground:metadata # Custom metadata
812
+ ```
813
+
814
+ ## How It Works
815
+
816
+ 1. **Initialization**: When you call `initializePerplexityFromEnv()` and `initializeReveniumFromEnv()`, the middleware sets up configurations
817
+ 2. **Request Wrapping**: All Perplexity API calls go through the middleware wrapper
818
+ 3. **Usage Extraction**: Token counts, model info, and timing data are captured from responses
819
+ 4. **Async Tracking**: Usage data is sent to Revenium in the background (fire-and-forget)
820
+ 5. **Transparent Response**: Original Perplexity responses are returned unchanged
821
+
822
+ The middleware never blocks your application - if Revenium tracking fails, your Perplexity requests continue normally.
823
+
824
+ ## Requirements
825
+
826
+ - Node.js 16+
827
+ - TypeScript 5.0+ (for TypeScript projects)
828
+ - Revenium API key
829
+ - Perplexity API key
830
+
831
+ ## Documentation
832
+
833
+ For detailed documentation, visit [docs.revenium.io](https://docs.revenium.io)
834
+
835
+ ## Contributing
836
+
837
+ See [CONTRIBUTING.md](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/CONTRIBUTING.md)
838
+
839
+ ## Code of Conduct
840
+
841
+ See [CODE_OF_CONDUCT.md](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/CODE_OF_CONDUCT.md)
842
+
843
+ ## Security
844
+
845
+ See [SECURITY.md](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/SECURITY.md)
846
+
847
+ ## License
848
+
849
+ This project is licensed under the MIT License - see the [LICENSE](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/LICENSE) file for details.
850
+
851
+ ## Support
852
+
853
+ For issues, feature requests, or contributions:
854
+
855
+ - **GitHub Repository**: [revenium/revenium-middleware-perplexity-node](https://github.com/revenium/revenium-middleware-perplexity-node)
856
+ - **Issues**: [Report bugs or request features](https://github.com/revenium/revenium-middleware-perplexity-node/issues)
857
+ - **Documentation**: [docs.revenium.io](https://docs.revenium.io)
858
+ - **Contact**: Reach out to the Revenium team for additional support
859
+
860
+ ## Development
861
+
862
+ For development and testing instructions, see [DEVELOPMENT.md](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/DEVELOPMENT.md).
863
+
864
+ ---
865
+
866
+ **Built by Revenium**