@revenium/perplexity 2.0.3 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +39 -1
  2. package/README.md +86 -681
  3. package/dist/cjs/constants.js +70 -0
  4. package/dist/cjs/constants.js.map +1 -0
  5. package/dist/cjs/core/config/perplexity-config.js.map +1 -0
  6. package/dist/cjs/core/config/revenium-config.js.map +1 -0
  7. package/dist/cjs/core/tracking/metering.js +86 -6
  8. package/dist/cjs/core/tracking/metering.js.map +1 -0
  9. package/dist/cjs/core/wrapper/perplexity-client.js +11 -1
  10. package/dist/cjs/core/wrapper/perplexity-client.js.map +1 -0
  11. package/dist/cjs/index.js +9 -4
  12. package/dist/cjs/index.js.map +1 -0
  13. package/dist/cjs/types/index.js +0 -15
  14. package/dist/cjs/types/index.js.map +1 -0
  15. package/dist/cjs/utils/logger.js.map +1 -0
  16. package/dist/esm/constants.js +67 -0
  17. package/dist/esm/constants.js.map +1 -0
  18. package/dist/esm/core/config/perplexity-config.js.map +1 -0
  19. package/dist/esm/core/config/revenium-config.js.map +1 -0
  20. package/dist/esm/core/tracking/metering.js +86 -6
  21. package/dist/esm/core/tracking/metering.js.map +1 -0
  22. package/dist/esm/core/wrapper/perplexity-client.js +11 -1
  23. package/dist/esm/core/wrapper/perplexity-client.js.map +1 -0
  24. package/dist/esm/index.js +4 -1
  25. package/dist/esm/index.js.map +1 -0
  26. package/dist/esm/types/index.js +1 -14
  27. package/dist/esm/types/index.js.map +1 -0
  28. package/dist/esm/utils/logger.js.map +1 -0
  29. package/dist/types/constants.d.ts +67 -0
  30. package/dist/types/constants.d.ts.map +1 -0
  31. package/dist/types/core/config/perplexity-config.d.ts.map +1 -0
  32. package/dist/types/core/config/revenium-config.d.ts.map +1 -0
  33. package/dist/types/core/tracking/metering.d.ts.map +1 -0
  34. package/dist/types/core/wrapper/perplexity-client.d.ts.map +1 -0
  35. package/dist/types/index.d.ts +2 -2
  36. package/dist/types/index.d.ts.map +1 -0
  37. package/dist/types/types/index.d.ts +3 -11
  38. package/dist/types/types/index.d.ts.map +1 -0
  39. package/dist/types/utils/logger.d.ts.map +1 -0
  40. package/examples/README.md +220 -221
  41. package/examples/advanced-features.ts +148 -0
  42. package/examples/basic.ts +16 -21
  43. package/examples/chat.ts +11 -25
  44. package/examples/getting_started.ts +64 -0
  45. package/examples/metadata.ts +33 -40
  46. package/examples/streaming.ts +6 -17
  47. package/package.json +7 -11
@@ -1,323 +1,322 @@
1
- # Revenium Perplexity AI Middleware Examples
1
+ # Running Examples - Revenium Middleware for Perplexity (Node.js)
2
2
 
3
- Comprehensive examples demonstrating how to use the @revenium/perplexity middleware with automatic usage tracking and metering.
3
+ This guide shows you how to run the Node.js/TypeScript examples in this repository.
4
4
 
5
- ## TypeScript-First Approach
5
+ ## Prerequisites
6
6
 
7
- These examples are written in TypeScript to showcase type-safe development patterns. You can use them in both TypeScript and JavaScript projects:
7
+ - Node.js 20+ installed
8
+ - Perplexity API key
9
+ - Revenium API key
8
10
 
9
- - **TypeScript projects**: Run examples directly with `tsx` or `ts-node`
10
- - **JavaScript projects**: See playground/ directory for JavaScript versions
11
+ ## Setup
11
12
 
12
- **For npm users:** These examples are included in your `node_modules/@revenium/perplexity/examples/` directory after installation.
13
+ ### 1. Clone the Repository
13
14
 
14
- **For GitHub users:** Clone the repository to run examples directly with the included npm scripts.
15
-
16
- ## Quick Start
15
+ ```bash
16
+ git clone https://github.com/revenium/revenium-middleware-perplexity-node.git
17
+ cd revenium-middleware-perplexity-node
18
+ ```
17
19
 
18
- ### 1. Installation
20
+ ### 2. Install Dependencies
19
21
 
20
22
  ```bash
21
- npm install @revenium/perplexity dotenv
22
- npm install --save-dev tsx # For TypeScript projects
23
+ npm install
23
24
  ```
24
25
 
25
- ### 2. Environment Setup
26
+ ### 3. Configure Environment Variables
26
27
 
27
- Create a `.env` file in your project root:
28
+ Create a `.env` file in the root directory:
28
29
 
29
- ```env
30
- # Required: Your Perplexity API key
31
- PERPLEXITY_API_KEY=pplx_your_perplexity_key
30
+ ```bash
31
+ # Create .env file
32
+ cp .env.example .env
33
+ ```
32
34
 
33
- # Required: Revenium metering API key
34
- REVENIUM_METERING_API_KEY=hak_your_revenium_key
35
- REVENIUM_METERING_BASE_URL=https://api.revenium.io/meter/v2
35
+ See [`.env.example`](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/.env.example) for the complete list of environment variables and where to get your API keys.
36
36
 
37
- # Optional: Perplexity base URL (defaults to https://api.perplexity.ai)
38
- PERPLEXITY_API_BASE_URL=https://api.perplexity.ai
37
+ **Replace the placeholder values with your actual keys!**
39
38
 
40
- # Optional: Enable debug logging
41
- DEBUG=true
42
- ```
39
+ ## Running Examples
43
40
 
44
- ### 3. Run Examples
41
+ ### Available Examples
45
42
 
46
- From the repository:
47
43
  ```bash
48
- npm run example:basic # Basic chat completion
49
- npm run example:streaming # Streaming responses
50
- npm run example:chat # Multi-turn conversations
51
- npm run example:metadata # Custom usage metadata
44
+ npm run example:basic # Basic chat completion
45
+ npm run example:streaming # Streaming response
46
+ npm run example:chat # Multi-turn conversation
47
+ npm run example:metadata # With custom metadata
48
+ npm run example:advanced # Advanced features
49
+ npm run example:getting-started # Quick start example
50
+ npm test # Run all examples
52
51
  ```
53
52
 
54
- Or run all examples:
55
- ```bash
56
- npm test
57
- ```
53
+ ## Example Structure
58
54
 
59
- ## Getting Started - Step by Step
55
+ ```
56
+ examples/
57
+ ├── basic.ts # Basic chat completion
58
+ ├── streaming.ts # Streaming response
59
+ ├── chat.ts # Multi-turn conversation
60
+ ├── metadata.ts # With custom metadata
61
+ ├── advanced-features.ts # Advanced features
62
+ ├── getting_started.ts # Quick start example
63
+ └── README.md # This file
64
+ ```
60
65
 
61
- ### Step 1: Create Your First Test
66
+ ## Examples Included
62
67
 
63
- **TypeScript:**
64
- ```typescript
65
- // test-perplexity.ts
66
- import { config } from "dotenv";
67
- import {
68
- initializeReveniumFromEnv,
69
- initializePerplexityFromEnv,
70
- createChatCompletion,
71
- } from "@revenium/perplexity";
68
+ ### 1. Basic Usage
72
69
 
73
- config(); // Load .env file
70
+ **Location**: `examples/basic.ts`
74
71
 
75
- async function test() {
76
- // Initialize configurations
77
- initializeReveniumFromEnv();
78
- initializePerplexityFromEnv();
72
+ **What it demonstrates:**
79
73
 
80
- // Create chat completion
81
- const result = await createChatCompletion({
82
- messages: [{ role: "user", content: "Hello!" }],
83
- model: "sonar-pro",
84
- });
74
+ - Simple chat completion
75
+ - Automatic metering
76
+ - Basic error handling
85
77
 
86
- console.log(result.choices[0].message.content);
87
- }
78
+ **Run it:**
88
79
 
89
- test();
80
+ ```bash
81
+ npm run example:basic
90
82
  ```
91
83
 
92
- **JavaScript (CommonJS):**
93
- ```javascript
94
- // test-perplexity.js
95
- require("dotenv").config();
96
- const {
97
- initializeReveniumFromEnv,
98
- initializePerplexityFromEnv,
99
- createChatCompletion
100
- } = require("@revenium/perplexity");
101
-
102
- async function test() {
103
- initializeReveniumFromEnv();
104
- initializePerplexityFromEnv();
105
-
106
- const result = await createChatCompletion({
107
- messages: [{ role: "user", content: "Hello!" }],
108
- model: "sonar-pro",
109
- });
110
-
111
- console.log(result.choices[0].message.content);
112
- }
113
-
114
- test();
84
+ **Expected output:**
85
+
86
+ ```
87
+ ✓ Chat Completion Successful
88
+ Response: [AI response here]
89
+ Model: sonar-pro
90
+ Tokens Used: 50 (prompt: 10, completion: 40)
115
91
  ```
116
92
 
117
- ### Step 2: Update package.json
93
+ ---
118
94
 
119
- Add scripts to run your tests:
95
+ ### 2. Streaming
120
96
 
121
- ```json
122
- {
123
- "scripts": {
124
- "test:perplexity": "tsx test-perplexity.ts"
125
- }
126
- }
127
- ```
97
+ **Location**: `examples/streaming.ts`
128
98
 
129
- Or for JavaScript:
130
- ```json
131
- {
132
- "scripts": {
133
- "test:perplexity": "node test-perplexity.js"
134
- }
135
- }
136
- ```
99
+ **What it demonstrates:**
100
+
101
+ - Real-time streaming responses
102
+ - Token tracking for streamed content
103
+ - Automatic usage tracking when stream completes
137
104
 
138
- ### Step 3: Run Your Tests
105
+ **Run it:**
139
106
 
140
107
  ```bash
141
- npm run test:perplexity
108
+ npm run example:streaming
142
109
  ```
143
110
 
144
- ### Step 4: Explore Advanced Features
111
+ **Expected output:**
145
112
 
146
- Once basic integration works, explore the included examples:
147
- - `basic.ts` - Simple chat completions
148
- - `streaming.ts` - Real-time streaming responses
149
- - `chat.ts` - Multi-turn conversations with context
150
- - `metadata.ts` - Custom usage tracking and analytics
151
-
152
- ### Step 5: Project Structure
113
+ ```
114
+ Model: sonar-pro
115
+ Streaming response:
153
116
 
154
- Recommended structure for your Perplexity AI project:
117
+ [Streaming text appears here in real-time]
155
118
 
119
+ ✓ Streaming completed
156
120
  ```
157
- your-project/
158
- ├── .env # Your API keys (DON'T COMMIT!)
159
- ├── .env.example # Template for others
160
- ├── .gitignore # Include .env
161
- ├── package.json
162
- ├── src/
163
- │ ├── perplexity/
164
- │ │ ├── client.ts # Perplexity client setup
165
- │ │ └── prompts.ts # Your prompts
166
- │ └── index.ts
167
- └── tests/
168
- └── perplexity.test.ts
169
- ```
170
121
 
171
- ## Available Examples
122
+ ---
123
+
124
+ ### 3. Multi-turn Chat
125
+
126
+ **Location**: `examples/chat.ts`
172
127
 
173
- ### basic.ts - Start Here
128
+ **What it demonstrates:**
174
129
 
175
- Simple chat completion with automatic usage tracking.
130
+ - Conversation history management
131
+ - Context-aware responses
132
+ - Multi-message interactions
176
133
 
177
- **Features:**
178
- - Basic configuration initialization
179
- - Simple chat completion request
180
- - Automatic metering to Revenium
134
+ **Run it:**
181
135
 
182
- **Run:**
183
136
  ```bash
184
- npm run example:basic
137
+ npm run example:chat
185
138
  ```
186
139
 
187
- ### streaming.ts
140
+ **Expected output:**
188
141
 
189
- Real-time streaming responses with usage tracking.
142
+ ```
143
+ --- Turn 1 ---
144
+ User: What is the capital of France?
145
+ Assistant: [Response]
190
146
 
191
- **Features:**
192
- - Streaming chat completions
193
- - Real-time content delivery
194
- - Automatic tracking when stream completes
147
+ --- Turn 2 ---
148
+ User: What is its population?
149
+ Assistant: [Response]
195
150
 
196
- **Run:**
197
- ```bash
198
- npm run example:streaming
151
+ ✓ Chat completed - Total tokens used: 120
199
152
  ```
200
153
 
201
- ### chat.ts
154
+ ---
202
155
 
203
- Multi-turn conversations with context.
156
+ ### 4. Custom Metadata
204
157
 
205
- **Features:**
206
- - Conversation history management
207
- - Context-aware responses
208
- - Multi-message interactions
209
-
210
- **Run:**
211
- ```bash
212
- npm run example:chat
213
- ```
158
+ **Location**: `examples/metadata.ts`
214
159
 
215
- ### metadata.ts
160
+ **What it demonstrates:**
216
161
 
217
- Custom usage metadata for advanced tracking.
162
+ - Custom metadata tracking
163
+ - Business context in metering
164
+ - Subscriber and organization tracking
218
165
 
219
- **Features:**
220
- - Custom subscriber information
221
- - Organization and product tracking
222
- - Quality scoring
223
- - Business analytics integration
166
+ **Run it:**
224
167
 
225
- **Run:**
226
168
  ```bash
227
169
  npm run example:metadata
228
170
  ```
229
171
 
230
- ## TypeScript Integration Patterns
231
-
232
- ### Pattern A: Direct Import (Recommended)
172
+ **Expected output:**
233
173
 
234
- ```typescript
235
- import {
236
- initializeReveniumFromEnv,
237
- initializePerplexityFromEnv,
238
- createChatCompletion
239
- } from "@revenium/perplexity";
174
+ ```
175
+ Chat Completion Successful
176
+ Response: [AI response]
177
+ Model: sonar-pro
178
+ Tokens Used: 50 (prompt: 10, completion: 40)
179
+ Metadata tracked: subscriber, organization, product, agent, trace
240
180
  ```
241
181
 
242
- ### Pattern B: Manual Configuration
182
+ **Note:** Custom metadata (subscriber, organizationId, productId, agent, traceId) is automatically sent to Revenium in the background.
243
183
 
244
- ```typescript
245
- import {
246
- initializeRevenium,
247
- initializePerplexity,
248
- createChatCompletion
249
- } from "@revenium/perplexity";
184
+ ---
250
185
 
251
186
  // Manual configuration
252
187
  initializeRevenium({
253
- apiKey: process.env.REVENIUM_METERING_API_KEY!,
254
- baseUrl: "https://api.revenium.io/meter/v2"
188
+ meteringApiKey: process.env.REVENIUM_METERING_API_KEY!,
189
+ meteringBaseUrl:
190
+ process.env.REVENIUM_METERING_BASE_URL || "https://api.revenium.ai",
255
191
  });
256
192
 
257
- initializePerplexity({
258
- apiKey: process.env.PERPLEXITY_API_KEY!
259
- });
193
+ **Location**: `examples/advanced-features.ts`
194
+
195
+ **What it demonstrates:**
196
+
197
+ - Streaming with metadata
198
+ - Multiple model comparisons
199
+ - Advanced configuration
200
+
201
+ **Run it:**
202
+
203
+ ```bash
204
+ npm run example:advanced
260
205
  ```
261
206
 
262
- ### Pattern C: With Custom Metadata
263
-
264
- ```typescript
265
- const result = await createChatCompletion({
266
- messages: [{ role: "user", content: "Hello" }],
267
- model: "sonar-pro",
268
- usageMetadata: {
269
- subscriberId: "user-123",
270
- subscriberEmail: "user@example.com",
271
- organizationId: "acme-corp",
272
- productId: "chat-app"
273
- }
274
- });
207
+ **Expected output:**
208
+
275
209
  ```
210
+ === Advanced Features Example ===
211
+
212
+ --- Streaming Responses ---
213
+ Model: sonar-pro
214
+ Response:
215
+ [Streaming text appears here in real-time]
216
+ ✓ Streaming completed
217
+
218
+ --- Comprehensive Metadata Tracking ---
219
+ Response: [First 100 characters]...
220
+ ✓ Metadata tracked successfully
221
+
222
+ --- Multiple Model Types ---
223
+ Using sonar (lightweight search)...
224
+ Response: [First 80 characters]...
225
+
226
+ Using sonar-reasoning (real-time reasoning)...
227
+ Response: [First 80 characters]...
228
+
229
+ ✓ Multiple models demonstrated
230
+
231
+ === All Advanced Features Demonstrated ===
232
+ ```
233
+
234
+ ---
235
+
236
+ ### 6. Getting Started
237
+
238
+ **Location**: `examples/getting_started.ts`
239
+
240
+ **What it demonstrates:**
241
+
242
+ - Quick start example
243
+ - Minimal configuration
244
+ - Basic usage pattern
245
+
246
+ **Run it:**
247
+
248
+ ```bash
249
+ npm run example:getting-started
250
+ ```
251
+
252
+ ---
276
253
 
277
254
  ## Troubleshooting
278
255
 
279
- ### Common Issues
256
+ ### "Missing API Key" Error
257
+
258
+ Make sure you've created a `.env` file with your API keys:
259
+
260
+ ```bash
261
+ # Check if .env exists
262
+ ls .env
280
263
 
281
- 1. **Module not found**: Ensure you've run `npm install @revenium/perplexity`
282
- 2. **Environment variables not loading**: Verify your `.env` file exists and `dotenv` is configured
283
- 3. **API key errors**: Check both Perplexity and Revenium API keys are valid
284
- 4. **TypeScript errors**: Ensure you have `tsx` or `ts-node` installed for TypeScript projects
264
+ # Verify it has the required keys
265
+ cat .env
266
+ ```
285
267
 
286
- ### Debug Mode
268
+ ### "Module not found" Error
287
269
 
288
- Enable debug logging to troubleshoot issues:
270
+ Install dependencies first:
289
271
 
290
272
  ```bash
291
- DEBUG=true npm run example:basic
273
+ npm install
292
274
  ```
293
275
 
294
- ### Expected Output
276
+ ### "Requests not being tracked"
277
+
278
+ 1. Check your `.env` file has correct values:
279
+
280
+ - `PERPLEXITY_API_KEY` is set
281
+ - `REVENIUM_METERING_API_KEY` is set
282
+ - `REVENIUM_METERING_BASE_URL` is set to `https://api.revenium.ai`
295
283
 
296
- When running examples successfully:
284
+ 2. Enable debug logging:
285
+
286
+ ```bash
287
+ DEBUG=true npm run example:basic
297
288
  ```
298
- Basic Chat Completion Example
299
289
 
300
- Initializing configurations...
301
- Configurations initialized
290
+ ### TypeScript Errors
302
291
 
303
- Creating chat completion...
304
- Chat completion created
292
+ Ensure you have TypeScript and tsx installed:
305
293
 
306
- Response: [AI response here]
307
- Usage: { prompt_tokens: X, completion_tokens: Y, total_tokens: Z }
294
+ ```bash
295
+ npm install -D typescript tsx @types/node
308
296
  ```
309
297
 
310
- ## JavaScript Playground
298
+ ---
311
299
 
312
- For JavaScript users, see the `playground/` directory for CommonJS versions of all examples:
300
+ ## Getting Your API Keys
313
301
 
314
- - `playground/basic.js`
315
- - `playground/streaming.js`
316
- - `playground/chat.js`
317
- - `playground/metadata.js`
302
+ ### Perplexity API Key
303
+
304
+ 1. Go to [Perplexity AI Settings](https://www.perplexity.ai/settings/api)
305
+ 2. Create a new API key
306
+ 3. Add to `.env` as `PERPLEXITY_API_KEY`
307
+
308
+ ### Revenium API Key
309
+
310
+ 1. Sign up at [Revenium](https://ai.revenium.io)
311
+ 2. Create a new API key in your dashboard
312
+ 3. Add to `.env` as `REVENIUM_METERING_API_KEY`
313
+
314
+ ---
318
315
 
319
316
  ## Support
320
317
 
321
- - Documentation: https://docs.revenium.io
322
- - GitHub Issues: https://github.com/revenium/revenium-middleware-perplexity-node/issues
323
- - Email: support@revenium.io
318
+ For issues or questions:
319
+
320
+ - [GitHub Issues](https://github.com/revenium/revenium-middleware-perplexity-node/issues)
321
+ - [Documentation](https://docs.revenium.io)
322
+ - Contact: Reach out to the Revenium team for additional support
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Advanced Features Example
3
+ *
4
+ * This example demonstrates advanced middleware features:
5
+ * - Streaming responses with real-time content
6
+ * - Comprehensive metadata for analytics
7
+ * - Multiple model types (search, reasoning, research)
8
+ * - Session and quality tracking
9
+ *
10
+ * For complete documentation, see:
11
+ * https://revenium.readme.io/reference/meter_ai_completion
12
+ */
13
+
14
+ import {
15
+ initializeReveniumFromEnv,
16
+ initializePerplexityFromEnv,
17
+ createChatCompletion,
18
+ createStreamingChatCompletion,
19
+ UsageMetadata,
20
+ } from "../src";
21
+
22
+ async function demonstrateStreaming() {
23
+ console.log("\n--- Streaming Responses ---");
24
+ const usageMetadata: UsageMetadata = {
25
+ subscriber: { id: "user-streaming-demo" },
26
+ traceId: "streaming-session-" + Date.now(),
27
+ taskType: "list-generation",
28
+ };
29
+
30
+ const result = await createStreamingChatCompletion({
31
+ messages: [
32
+ {
33
+ role: "user",
34
+ content: "List the first 3 planets in our solar system.",
35
+ },
36
+ ],
37
+ model: "sonar-pro",
38
+ maxTokens: 400,
39
+ usageMetadata,
40
+ });
41
+
42
+ console.log(`Model: ${result.model}`);
43
+ console.log("Response: ");
44
+
45
+ let fullContent = "";
46
+ for await (const chunk of result.stream) {
47
+ const content = chunk.choices[0]?.delta?.content || "";
48
+ if (content) {
49
+ process.stdout.write(content);
50
+ fullContent += content;
51
+ }
52
+ }
53
+
54
+ console.log("\n✓ Streaming completed\n");
55
+ }
56
+
57
+ async function demonstrateComprehensiveMetadata() {
58
+ console.log("\n--- Comprehensive Metadata Tracking ---");
59
+
60
+ const usageMetadata: UsageMetadata = {
61
+ traceId: "session-advanced-demo-" + Date.now(),
62
+ taskType: "educational-query",
63
+ subscriber: {
64
+ id: "user-456",
65
+ email: "advanced-user@example.com",
66
+ credential: {
67
+ name: "premium-api-key",
68
+ value: "key-premium-abc123",
69
+ },
70
+ },
71
+ organizationId: "org-enterprise-789",
72
+ subscriptionId: "sub-enterprise-2024",
73
+ productId: "learning-platform",
74
+ agent: "educational-assistant-v2",
75
+ responseQualityScore: 0.92,
76
+ };
77
+
78
+ const result = await createChatCompletion({
79
+ messages: [
80
+ {
81
+ role: "user",
82
+ content: "What is machine learning?",
83
+ },
84
+ ],
85
+ model: "sonar-pro",
86
+ maxTokens: 400,
87
+ usageMetadata,
88
+ });
89
+
90
+ console.log(`Response: ${result.content.substring(0, 100)}...`);
91
+ console.log(`✓ Metadata tracked successfully\n`);
92
+ }
93
+
94
+ async function demonstrateMultipleModels() {
95
+ console.log("\n--- Multiple Model Types ---");
96
+
97
+ const usageMetadata: UsageMetadata = {
98
+ subscriber: { id: "model-comparison-user" },
99
+ taskType: "weather-search",
100
+ };
101
+
102
+ // Search model
103
+ console.log("Using sonar (lightweight search)...");
104
+ const searchResult = await createChatCompletion({
105
+ messages: [{ role: "user", content: "Current weather in Tokyo" }],
106
+ model: "sonar-pro",
107
+ maxTokens: 400,
108
+ usageMetadata,
109
+ });
110
+ console.log(`Response: ${searchResult.content.substring(0, 80)}...`);
111
+
112
+ // Reasoning model
113
+ console.log("\nUsing sonar-reasoning (real-time reasoning)...");
114
+ const reasoningResult = await createChatCompletion({
115
+ messages: [
116
+ { role: "user", content: "Why is the sky blue? Explain briefly." },
117
+ ],
118
+ model: "sonar-reasoning",
119
+ maxTokens: 400,
120
+ usageMetadata: {
121
+ ...usageMetadata,
122
+ taskType: "reasoning-query",
123
+ },
124
+ });
125
+ console.log(`Response: ${reasoningResult.content.substring(0, 80)}...`);
126
+
127
+ console.log("\n✓ Multiple models demonstrated\n");
128
+ }
129
+
130
+ async function main() {
131
+ console.log("\n=== Advanced Features Example ===");
132
+
133
+ // Initialize configurations
134
+ initializeReveniumFromEnv();
135
+ initializePerplexityFromEnv();
136
+
137
+ // Demonstrate features
138
+ await demonstrateStreaming();
139
+ await demonstrateComprehensiveMetadata();
140
+ await demonstrateMultipleModels();
141
+
142
+ console.log("=== All Advanced Features Demonstrated ===\n");
143
+ }
144
+
145
+ main().catch((error) => {
146
+ console.error("\nError:", error.message);
147
+ process.exit(1);
148
+ });