@revenium/perplexity 2.0.7 → 2.0.8

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/SECURITY.md CHANGED
@@ -1,34 +1,34 @@
1
- # Security Policy
2
-
3
- ## Reporting a Vulnerability
4
-
5
- If you discover a security vulnerability in this package, please report it to us.
6
-
7
- **DO NOT** create a public GitHub issue for security vulnerabilities.
8
-
9
- ### How to Report
10
-
11
- Email: support@revenium.io
12
-
13
- Please include:
14
- - Package name and version
15
- - Description of the vulnerability
16
- - Steps to reproduce (if applicable)
17
- - Potential impact
18
- - Suggested fix (if available)
19
-
20
- We will review and respond to security reports in a timely manner.
21
-
22
- ## Security Best Practices
23
-
24
- When using this middleware:
25
-
26
- 1. **API Keys**: Never commit API keys to version control
27
- 2. **Environment Variables**: Use environment variables for sensitive configuration
28
- 3. **PII Handling**: Ensure no PII is sent to Revenium unless explicitly configured for billing purposes
29
- 4. **Network Security**: Always use HTTPS connections
30
- 5. **Updates**: Keep the package updated to the latest version
31
-
32
- ## Additional Resources
33
-
34
- - [Revenium Documentation](https://docs.revenium.io)
1
+ # Security Policy
2
+
3
+ ## Reporting a Vulnerability
4
+
5
+ If you discover a security vulnerability in this package, please report it to us.
6
+
7
+ **DO NOT** create a public GitHub issue for security vulnerabilities.
8
+
9
+ ### How to Report
10
+
11
+ Email: support@revenium.io
12
+
13
+ Please include:
14
+ - Package name and version
15
+ - Description of the vulnerability
16
+ - Steps to reproduce (if applicable)
17
+ - Potential impact
18
+ - Suggested fix (if available)
19
+
20
+ We will review and respond to security reports in a timely manner.
21
+
22
+ ## Security Best Practices
23
+
24
+ When using this middleware:
25
+
26
+ 1. **API Keys**: Never commit API keys to version control
27
+ 2. **Environment Variables**: Use environment variables for sensitive configuration
28
+ 3. **PII Handling**: Ensure no PII is sent to Revenium unless explicitly configured for billing purposes
29
+ 4. **Network Security**: Always use HTTPS connections
30
+ 5. **Updates**: Keep the package updated to the latest version
31
+
32
+ ## Additional Resources
33
+
34
+ - [Revenium Documentation](https://docs.revenium.io)
@@ -1,230 +1,274 @@
1
- # Revenium Perplexity Middleware - Examples
2
-
3
- This directory contains examples demonstrating how to use the Revenium Perplexity middleware.
4
-
5
- ## Prerequisites
6
-
7
- Before running the examples, make sure you have:
8
-
9
- 1. **Node.js 20+** installed
10
- 2. **Revenium API Key** - Get one from [Revenium Dashboard](https://app.revenium.ai)
11
- 3. **Perplexity API Key** - Get one from [Perplexity Platform](https://www.perplexity.ai)
12
-
13
- ## Setup
14
-
15
- 1. **Clone the repository** (if you haven't already):
16
-
17
- ```bash
18
- git clone https://github.com/revenium/revenium-middleware-perplexity-node.git
19
- cd revenium-middleware-perplexity-node
20
- ```
21
-
22
- 2. **Install dependencies**:
23
-
24
- ```bash
25
- npm install
26
- ```
27
-
28
- 3. **Configure environment variables**:
29
-
30
- Create a `.env` file in the project root with your API keys:
31
-
32
- ```bash
33
- # .env
34
- PERPLEXITY_API_KEY=pplx_your_perplexity_api_key
35
- REVENIUM_METERING_API_KEY=hak_your_revenium_api_key
36
- REVENIUM_METERING_BASE_URL=https://api.revenium.ai # Optional, defaults to https://api.revenium.ai
37
- REVENIUM_DEBUG=true # Optional, enables debug logging
38
- ```
39
-
40
- **Note:** The middleware automatically loads `.env` files via `Initialize()`, so no additional configuration is needed.
41
-
42
- ## Examples
43
-
44
- ### 1. Getting Started
45
-
46
- **File:** `getting_started.ts`
47
-
48
- The simplest example to get you started with Revenium tracking:
49
-
50
- - Initialize the middleware
51
- - Create a basic chat completion
52
- - Display response and usage metrics
53
-
54
- **Run:**
55
-
56
- ```bash
57
- npm run example:getting-started
58
- # or
59
- npx tsx examples/getting_started.ts
60
- ```
61
-
62
- **What it does:**
63
-
64
- - Loads configuration from environment variables
65
- - Creates a simple chat completion request
66
- - Automatically sends metering data to Revenium API
67
- - Displays the response
68
-
69
- ---
70
-
71
- ### 2. Basic Usage
72
-
73
- **File:** `basic.ts`
74
-
75
- Demonstrates standard Perplexity API usage:
76
-
77
- - Chat completions with metadata
78
- - Simple metadata tracking
79
-
80
- **Run:**
81
-
82
- ```bash
83
- npm run example:basic
84
- # or
85
- npx tsx examples/basic.ts
86
- ```
87
-
88
- **What it does:**
89
-
90
- - Creates chat completions with metadata tracking
91
- - Demonstrates basic metadata usage
92
-
93
- ---
94
-
95
- ### 3. Metadata
96
-
97
- **File:** `metadata.ts`
98
-
99
- Demonstrates all available metadata fields:
100
-
101
- - Complete metadata structure
102
- - All optional fields documented
103
- - Subscriber information
104
-
105
- **Run:**
106
-
107
- ```bash
108
- npm run example:metadata
109
- # or
110
- npx tsx examples/metadata.ts
111
- ```
112
-
113
- **What it does:**
114
-
115
- - Shows all available metadata fields
116
- - Demonstrates subscriber tracking
117
- - Includes organization and product tracking
118
-
119
- **Metadata fields supported:**
120
-
121
- - `traceId` - Session or conversation tracking identifier
122
- - `taskType` - Type of AI task being performed
123
- - `agent` - AI agent or bot identifier
124
- - `organizationId` - Organization identifier
125
- - `productId` - Product or service identifier
126
- - `subscriptionId` - Subscription tier identifier
127
- - `responseQualityScore` - Quality rating (0.0-1.0)
128
- - `subscriber` - Nested subscriber object with `id`, `email`, `credential` (with `name` and `value`)
129
-
130
- ---
131
-
132
- ### 4. Streaming
133
-
134
- **File:** `stream.ts`
135
-
136
- Demonstrates streaming responses:
137
-
138
- - Real-time token streaming
139
- - Accumulating responses
140
- - Streaming metrics
141
-
142
- **Run:**
143
-
144
- ```bash
145
- npm run example:stream
146
- # or
147
- npx tsx examples/stream.ts
148
- ```
149
-
150
- **What it does:**
151
-
152
- - Creates a streaming chat completion
153
- - Displays tokens as they arrive in real-time
154
- - Tracks streaming metrics
155
- - Sends metering data after stream completes
156
-
157
- ---
158
-
159
- ### 5. Advanced Features
160
-
161
- **File:** `advanced.ts`
162
-
163
- Demonstrates advanced Perplexity features:
164
-
165
- - Multi-turn conversations
166
- - Different temperature settings
167
- - Multiple Perplexity models
168
-
169
- **Run:**
170
-
171
- ```bash
172
- npm run example:advanced
173
- # or
174
- npx tsx examples/advanced.ts
175
- ```
176
-
177
- **What it does:**
178
-
179
- - Demonstrates multi-turn conversation with system prompt
180
- - Shows creative responses with higher temperature
181
- - Uses sonar-reasoning model for complex reasoning tasks
182
-
183
- ---
184
-
185
- ## Common Issues
186
-
187
- ### "Client not initialized" error
188
-
189
- **Solution:** Make sure to call `Initialize()` before using `GetClient()`.
190
-
191
- ### "REVENIUM_METERING_API_KEY is required" error
192
-
193
- **Solution:** Set the `REVENIUM_METERING_API_KEY` environment variable in your `.env` file.
194
-
195
- ### "invalid Revenium API key format" error
196
-
197
- **Solution:** Revenium API keys should start with `hak_`. Check your API key format.
198
-
199
- ### Environment variables not loading
200
-
201
- **Solution:** Make sure your `.env` file is in the project root directory and contains the required variables.
202
-
203
- ### Perplexity API errors
204
-
205
- **Solution:** Make sure you have set `PERPLEXITY_API_KEY` in your `.env` file and that it starts with `pplx-`.
206
-
207
- ### Debug Mode
208
-
209
- Enable detailed logging to troubleshoot issues:
210
-
211
- ```bash
212
- # In .env file
213
- REVENIUM_DEBUG=true
214
-
215
- # Then run examples
216
- npm run example:getting-started
217
- ```
218
-
219
- ## Next Steps
220
-
221
- - Check the [main README](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/README.md) for detailed documentation
222
- - Visit the [Revenium Dashboard](https://app.revenium.ai) to view your metering data
223
- - See [.env.example](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/.env.example) for all configuration options
224
-
225
- ## Support
226
-
227
- For issues or questions:
228
-
229
- - Documentation: https://docs.revenium.io
230
- - Email: support@revenium.io
1
+ # Revenium Perplexity Middleware - Examples
2
+
3
+ This directory contains examples demonstrating how to use the Revenium Perplexity middleware.
4
+
5
+ ## Prerequisites
6
+
7
+ Before running the examples, make sure you have:
8
+
9
+ 1. **Node.js 20+** installed
10
+ 2. **Revenium API Key** - Get one from [Revenium Dashboard](https://app.revenium.ai)
11
+ 3. **Perplexity API Key** - Get one from [Perplexity Platform](https://www.perplexity.ai)
12
+
13
+ ## Setup
14
+
15
+ Choose one of the following approaches:
16
+
17
+ ### Option 1: Create a New Project (Recommended)
18
+
19
+ Follow the step-by-step guide below to create a new project and install the middleware from npm.
20
+
21
+ ### Option 2: Clone the Repository (Optional)
22
+
23
+ If you want to explore the source code or contribute to the project:
24
+
25
+ ```bash
26
+ git clone https://github.com/revenium/revenium-middleware-perplexity-node.git
27
+ cd revenium-middleware-perplexity-node
28
+ npm install
29
+ npm run build
30
+ ```
31
+
32
+ Then skip to [Step 3: Environment Setup](#3-environment-setup) below.
33
+
34
+ ---
35
+
36
+ ## Getting Started - Step by Step
37
+
38
+ ### 1. Create Your Project
39
+
40
+ ```bash
41
+ # Create project directory
42
+ mkdir my-perplexity-project
43
+ cd my-perplexity-project
44
+
45
+ # Initialize Node.js project
46
+ npm init -y
47
+ ```
48
+
49
+ ### 2. Install Dependencies
50
+
51
+ ```bash
52
+ npm install @revenium/perplexity openai
53
+ npm install -D typescript tsx @types/node # For TypeScript
54
+ ```
55
+
56
+ ### 3. Environment Setup
57
+
58
+ Create a `.env` file in the project root with your API keys:
59
+
60
+ ```bash
61
+ # Required
62
+ REVENIUM_METERING_API_KEY=hak_your_revenium_api_key
63
+ PERPLEXITY_API_KEY=pplx_your_perplexity_api_key
64
+
65
+ # Optional
66
+ REVENIUM_METERING_BASE_URL=https://api.revenium.ai
67
+ PERPLEXITY_API_BASE_URL=https://api.perplexity.ai
68
+ REVENIUM_DEBUG=false
69
+ ```
70
+
71
+ ### 4. Run Examples
72
+
73
+ **If you cloned from GitHub:**
74
+
75
+ ```bash
76
+ # Run examples directly (or use npm run example:<name> scripts)
77
+ npx tsx examples/getting_started.ts
78
+ npx tsx examples/basic.ts
79
+ npx tsx examples/metadata.ts
80
+ npx tsx examples/stream.ts
81
+ npx tsx examples/advanced.ts
82
+ ```
83
+
84
+ **If you installed via npm:**
85
+
86
+ Examples are included in your `node_modules/@revenium/perplexity/examples/` directory:
87
+
88
+ ```bash
89
+ npx tsx node_modules/@revenium/perplexity/examples/getting_started.ts
90
+ npx tsx node_modules/@revenium/perplexity/examples/basic.ts
91
+ npx tsx node_modules/@revenium/perplexity/examples/metadata.ts
92
+ npx tsx node_modules/@revenium/perplexity/examples/stream.ts
93
+ npx tsx node_modules/@revenium/perplexity/examples/advanced.ts
94
+ ```
95
+
96
+ ## Examples
97
+
98
+ ### 1. Getting Started
99
+
100
+ **File:** `getting_started.ts`
101
+
102
+ The simplest example to get you started with Revenium tracking:
103
+
104
+ - Initialize the middleware
105
+ - Create a basic chat completion
106
+ - Display response and usage metrics
107
+
108
+ **Run:**
109
+
110
+ ```bash
111
+ npx tsx examples/getting_started.ts
112
+ ```
113
+
114
+ **What it does:**
115
+
116
+ - Loads configuration from environment variables
117
+ - Creates a simple chat completion request
118
+ - Automatically sends metering data to Revenium API
119
+ - Displays the response
120
+
121
+ ---
122
+
123
+ ### 2. Basic Usage
124
+
125
+ **File:** `basic.ts`
126
+
127
+ Demonstrates standard Perplexity API usage:
128
+
129
+ - Chat completions with metadata
130
+ - Simple metadata tracking
131
+
132
+ **Run:**
133
+
134
+ ```bash
135
+ npx tsx examples/basic.ts
136
+ ```
137
+
138
+ **What it does:**
139
+
140
+ - Creates chat completions with metadata tracking
141
+ - Demonstrates basic metadata usage
142
+
143
+ ---
144
+
145
+ ### 3. Metadata
146
+
147
+ **File:** `metadata.ts`
148
+
149
+ Demonstrates all available metadata fields:
150
+
151
+ - Complete metadata structure
152
+ - All optional fields documented
153
+ - Subscriber information
154
+
155
+ **Run:**
156
+
157
+ ```bash
158
+ npx tsx examples/metadata.ts
159
+ ```
160
+
161
+ **What it does:**
162
+
163
+ - Shows all available metadata fields
164
+ - Demonstrates subscriber tracking
165
+ - Includes organization and product tracking
166
+
167
+ **Metadata fields supported:**
168
+
169
+ - `traceId` - Session or conversation tracking identifier
170
+ - `taskType` - Type of AI task being performed
171
+ - `agent` - AI agent or bot identifier
172
+ - `organizationId` - Organization identifier
173
+ - `productId` - Product or service identifier
174
+ - `subscriptionId` - Subscription tier identifier
175
+ - `responseQualityScore` - Quality rating (0.0-1.0)
176
+ - `subscriber` - Nested subscriber object with `id`, `email`, `credential` (with `name` and `value`)
177
+
178
+ ---
179
+
180
+ ### 4. Streaming
181
+
182
+ **File:** `stream.ts`
183
+
184
+ Demonstrates streaming responses:
185
+
186
+ - Real-time token streaming
187
+ - Accumulating responses
188
+ - Streaming metrics
189
+
190
+ **Run:**
191
+
192
+ ```bash
193
+ npx tsx examples/stream.ts
194
+ ```
195
+
196
+ **What it does:**
197
+
198
+ - Creates a streaming chat completion
199
+ - Displays tokens as they arrive in real-time
200
+ - Tracks streaming metrics
201
+ - Sends metering data after stream completes
202
+
203
+ ---
204
+
205
+ ### 5. Advanced Features
206
+
207
+ **File:** `advanced.ts`
208
+
209
+ Demonstrates advanced Perplexity features:
210
+
211
+ - Multi-turn conversations
212
+ - Different temperature settings
213
+ - Multiple Perplexity models
214
+
215
+ **Run:**
216
+
217
+ ```bash
218
+ npx tsx examples/advanced.ts
219
+ ```
220
+
221
+ **What it does:**
222
+
223
+ - Demonstrates multi-turn conversation with system prompt
224
+ - Shows creative responses with higher temperature
225
+ - Uses sonar-reasoning model for complex reasoning tasks
226
+
227
+ ---
228
+
229
+ ## Common Issues
230
+
231
+ ### "Client not initialized" error
232
+
233
+ **Solution:** Make sure to call `Initialize()` before using `GetClient()`.
234
+
235
+ ### "REVENIUM_METERING_API_KEY is required" error
236
+
237
+ **Solution:** Set the `REVENIUM_METERING_API_KEY` environment variable in your `.env` file.
238
+
239
+ ### "invalid Revenium API key format" error
240
+
241
+ **Solution:** Revenium API keys should start with `hak_`. Check your API key format.
242
+
243
+ ### Environment variables not loading
244
+
245
+ **Solution:** Make sure your `.env` file is in the project root directory and contains the required variables.
246
+
247
+ ### Perplexity API errors
248
+
249
+ **Solution:** Make sure you have set `PERPLEXITY_API_KEY` in your `.env` file and that it starts with `pplx-`.
250
+
251
+ ### Debug Mode
252
+
253
+ Enable detailed logging to troubleshoot issues:
254
+
255
+ ```bash
256
+ # In .env file
257
+ REVENIUM_DEBUG=true
258
+
259
+ # Then run examples
260
+ npm run example:getting-started
261
+ ```
262
+
263
+ ## Next Steps
264
+
265
+ - Check the [main README](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/README.md) for detailed documentation
266
+ - Visit the [Revenium Dashboard](https://app.revenium.ai) to view your metering data
267
+ - See [.env.example](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/.env.example) for all configuration options
268
+
269
+ ## Support
270
+
271
+ For issues or questions:
272
+
273
+ - Documentation: https://docs.revenium.io
274
+ - Email: support@revenium.io