@revenium/perplexity 1.0.23 โ 2.0.1
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 +468 -364
- package/dist/cjs/core/config/perplexity-config.js +45 -0
- package/dist/cjs/core/config/perplexity-config.js.map +1 -0
- package/dist/cjs/core/config/revenium-config.js +80 -0
- package/dist/cjs/core/config/revenium-config.js.map +1 -0
- package/dist/cjs/core/tracking/metering.js +131 -0
- package/dist/cjs/core/tracking/metering.js.map +1 -0
- package/dist/cjs/core/wrapper/perplexity-client.js +177 -0
- package/dist/cjs/core/wrapper/perplexity-client.js.map +1 -0
- package/dist/cjs/index.js +64 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/types/index.js +21 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/utils/logger.js +23 -0
- package/dist/cjs/utils/logger.js.map +1 -0
- package/dist/esm/core/config/perplexity-config.js +40 -0
- package/dist/esm/core/config/perplexity-config.js.map +1 -0
- package/dist/esm/core/config/revenium-config.js +72 -0
- package/dist/esm/core/config/revenium-config.js.map +1 -0
- package/dist/esm/core/tracking/metering.js +126 -0
- package/dist/esm/core/tracking/metering.js.map +1 -0
- package/dist/esm/core/wrapper/perplexity-client.js +170 -0
- package/dist/esm/core/wrapper/perplexity-client.js.map +1 -0
- package/dist/esm/index.js +44 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types/index.js +18 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/utils/logger.js +20 -0
- package/dist/esm/utils/logger.js.map +1 -0
- package/dist/types/core/config/perplexity-config.d.ts +24 -0
- package/dist/types/core/config/perplexity-config.d.ts.map +1 -0
- package/dist/types/core/config/revenium-config.d.ts +37 -0
- package/dist/types/core/config/revenium-config.d.ts.map +1 -0
- package/dist/types/core/tracking/metering.d.ts +31 -0
- package/dist/types/core/tracking/metering.d.ts.map +1 -0
- package/dist/types/core/wrapper/perplexity-client.d.ts +32 -0
- package/dist/types/core/wrapper/perplexity-client.d.ts.map +1 -0
- package/dist/types/index.d.ts +34 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +159 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/utils/logger.d.ts +10 -0
- package/dist/types/utils/logger.d.ts.map +1 -0
- package/package.json +36 -16
- package/.env.example +0 -3
- package/dist/index.js +0 -19
- package/dist/interfaces/chatCompletionRequest.d.ts +0 -9
- package/dist/interfaces/chatCompletionRequest.js +0 -2
- package/dist/interfaces/credential.d.ts +0 -4
- package/dist/interfaces/credential.js +0 -2
- package/dist/interfaces/meteringRequest.d.ts +0 -13
- package/dist/interfaces/meteringRequest.js +0 -2
- package/dist/interfaces/meteringResponse.d.ts +0 -27
- package/dist/interfaces/meteringResponse.js +0 -2
- package/dist/interfaces/operation.d.ts +0 -4
- package/dist/interfaces/operation.js +0 -8
- package/dist/interfaces/subscriber.d.ts +0 -8
- package/dist/interfaces/subscriber.js +0 -2
- package/dist/interfaces/tokenCounts.d.ts +0 -7
- package/dist/interfaces/tokenCounts.js +0 -2
- package/dist/interfaces/usageMetadata.d.ts +0 -27
- package/dist/interfaces/usageMetadata.js +0 -2
- package/dist/middleware.d.ts +0 -22
- package/dist/middleware.js +0 -129
- package/dist/models/Logger.js +0 -35
- package/dist/models/Metering.d.ts +0 -9
- package/dist/models/Metering.js +0 -80
- package/dist/utils/calculateDurationMs.d.ts +0 -1
- package/dist/utils/calculateDurationMs.js +0 -6
- package/dist/utils/constants/constants.d.ts +0 -6
- package/dist/utils/constants/constants.js +0 -11
- package/dist/utils/constants/logLevels.d.ts +0 -1
- package/dist/utils/constants/logLevels.js +0 -4
- package/dist/utils/constants/messages.d.ts +0 -5
- package/dist/utils/constants/messages.js +0 -8
- package/dist/utils/constants/models.d.ts +0 -1
- package/dist/utils/constants/models.js +0 -21
- package/dist/utils/extractTokenCount.d.ts +0 -2
- package/dist/utils/extractTokenCount.js +0 -28
- package/dist/utils/formatTimeStamp.d.ts +0 -1
- package/dist/utils/formatTimeStamp.js +0 -6
- package/dist/utils/generateTransactionId.d.ts +0 -1
- package/dist/utils/generateTransactionId.js +0 -7
- package/dist/utils/index.d.ts +0 -6
- package/dist/utils/index.js +0 -23
- package/dist/utils/loadEnv.d.ts +0 -1
- package/dist/utils/loadEnv.js +0 -7
- package/dist/utils/safeExtract.d.ts +0 -29
- package/dist/utils/safeExtract.js +0 -67
- package/examples/basic.ts +0 -17
- package/examples/chat-completions.ts +0 -22
- package/examples/enhanced.ts +0 -20
- package/examples/metadata.ts +0 -43
- package/examples/streaming.ts +0 -24
- package/playground/basic.js +0 -17
- package/playground/chat-completions.js +0 -22
- package/playground/enhanced.js +0 -20
- package/playground/metadata.js +0 -43
- package/playground/streaming.js +0 -24
- package/src/index.ts +0 -4
- package/src/interfaces/chatCompletionRequest.ts +0 -10
- package/src/interfaces/credential.ts +0 -4
- package/src/interfaces/meteringRequest.ts +0 -14
- package/src/interfaces/meteringResponse.ts +0 -28
- package/src/interfaces/operation.ts +0 -4
- package/src/interfaces/subscriber.ts +0 -8
- package/src/interfaces/tokenCounts.ts +0 -7
- package/src/interfaces/usageMetadata.ts +0 -27
- package/src/middleware.ts +0 -157
- package/src/models/Logger.ts +0 -38
- package/src/models/Metering.ts +0 -114
- package/src/utils/calculateDurationMs.ts +0 -3
- package/src/utils/constants/constants.ts +0 -10
- package/src/utils/constants/logLevels.ts +0 -1
- package/src/utils/constants/messages.ts +0 -11
- package/src/utils/constants/models.ts +0 -20
- package/src/utils/extractTokenCount.ts +0 -26
- package/src/utils/formatTimestamp.ts +0 -3
- package/src/utils/generateTransactionId.ts +0 -5
- package/src/utils/index.ts +0 -39
- package/src/utils/loadEnv.ts +0 -8
- package/src/utils/safeExtract.ts +0 -67
- package/tsconfig.json +0 -15
package/README.md
CHANGED
|
@@ -1,521 +1,625 @@
|
|
|
1
|
-
# Revenium Middleware for Perplexity
|
|
1
|
+
# Revenium Middleware for Perplexity
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://www.npmjs.com/package/@revenium/perplexity)
|
|
5
|
-
[](https://docs.revenium.io)
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
3
|
+
A lightweight, production-ready middleware that adds **Revenium metering and tracking** to Perplexity AI API calls.
|
|
7
4
|
|
|
8
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@revenium/perplexity)
|
|
6
|
+
[](https://opensource.org/licenses/ISC)
|
|
9
7
|
|
|
10
|
-
## ๐
|
|
8
|
+
## ๐ Features
|
|
11
9
|
|
|
12
|
-
|
|
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
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
| ----------------------------------------- | ----------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
|
|
16
|
-
| **Option 1: Create Project from Scratch** | Perfect for new projects. We'll guide you step-by-step from mkdir to running tests. | ๐ [Go to Step-by-Step Guide](#option-1-create-project-from-scratch) |
|
|
17
|
-
| **Option 2: Clone Our Repository** | Quick testing with pre-built examples and playground scripts. | ๐ [Go to Clone Guide](#option-2-clone-repository) |
|
|
18
|
-
| **Option 3: Add to Existing Project** | Already have a project? Just install and replace imports. | ๐ [Go to Quick Integration](#option-3-existing-project-integration) |
|
|
18
|
+
## ๐ Table of Contents
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
- [Installation](#-installation)
|
|
21
|
+
- [Three Ways to Use This Middleware](#-three-ways-to-use-this-middleware)
|
|
22
|
+
- [Option 1: New Project with npm Package](#option-1-new-project-with-npm-package-recommended)
|
|
23
|
+
- [Option 2: Clone and Use Locally](#option-2-clone-and-use-locally)
|
|
24
|
+
- [Option 3: Add to Existing Project](#option-3-add-to-existing-project)
|
|
25
|
+
- [Quick Start](#-quick-start)
|
|
26
|
+
- [API Reference](#-api-reference)
|
|
27
|
+
- [Examples](#-examples)
|
|
28
|
+
- [Environment Variables](#-environment-variables)
|
|
23
29
|
|
|
24
|
-
|
|
30
|
+
## ๐ฆ Installation
|
|
25
31
|
|
|
26
32
|
```bash
|
|
27
|
-
|
|
28
|
-
mkdir my-perplexity-ai-project
|
|
29
|
-
cd my-perplexity-ai-project
|
|
30
|
-
|
|
31
|
-
# Initialize Node.js project
|
|
32
|
-
npm init -y
|
|
33
|
+
npm install @revenium/perplexity
|
|
33
34
|
```
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
## ๐ฏ Three Ways to Use This Middleware
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
npm install @revenium/perplexity
|
|
39
|
-
```
|
|
38
|
+
### Option 1: New Project with npm Package (Recommended)
|
|
40
39
|
|
|
41
|
-
|
|
40
|
+
**Best for:** Starting a new project or adding Perplexity with Revenium to an existing project.
|
|
42
41
|
|
|
43
|
-
|
|
42
|
+
#### Step 1: Create a new project
|
|
44
43
|
|
|
45
44
|
```bash
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
# OR
|
|
50
|
-
#PowerShell
|
|
51
|
-
New-Item -Path .env -ItemType File
|
|
45
|
+
mkdir my-perplexity-project
|
|
46
|
+
cd my-perplexity-project
|
|
47
|
+
npm init -y
|
|
52
48
|
```
|
|
53
49
|
|
|
54
|
-
|
|
50
|
+
#### Step 2: Install the middleware
|
|
55
51
|
|
|
56
52
|
```bash
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
npm install @revenium/perplexity dotenv
|
|
54
|
+
```
|
|
59
55
|
|
|
60
|
-
|
|
61
|
-
REVENIUM_METERING_API_KEY="your_revenium_api_key_here"
|
|
62
|
-
REVENIUM_METERING_BASE_URL="https://api.revenium.io/meter"
|
|
56
|
+
#### Step 3: Create `.env` file
|
|
63
57
|
|
|
64
|
-
```
|
|
58
|
+
```env
|
|
59
|
+
# Perplexity API Configuration
|
|
60
|
+
PERPLEXITY_API_KEY=your_perplexity_api_key
|
|
65
61
|
|
|
66
|
-
|
|
62
|
+
# Revenium Metering Configuration
|
|
63
|
+
REVENIUM_METERING_API_KEY=your_revenium_api_key
|
|
64
|
+
REVENIUM_METERING_BASE_URL=https://api.revenium.io/meter
|
|
65
|
+
```
|
|
67
66
|
|
|
68
|
-
Create `
|
|
67
|
+
#### Step 4: Create `index.js`
|
|
69
68
|
|
|
70
69
|
```javascript
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
console.error("โ Perplexity basic example failed:", error);
|
|
93
|
-
process.exit(1);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
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
|
+
}
|
|
96
91
|
|
|
97
|
-
|
|
92
|
+
main().catch(console.error);
|
|
98
93
|
```
|
|
99
94
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
Add test scripts and module type to your `package.json`:
|
|
95
|
+
#### Step 5: Run your project
|
|
103
96
|
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
"name": "my-perplexity-ai-project",
|
|
107
|
-
"version": "1.0.0",
|
|
108
|
-
"type": "module",
|
|
109
|
-
"scripts": {
|
|
110
|
-
"test-perplexity": "node test-perplexity.js"
|
|
111
|
-
},
|
|
112
|
-
"dependencies": {
|
|
113
|
-
"@revenium/perplexity": "^1.0.0"
|
|
114
|
-
}
|
|
115
|
-
}
|
|
97
|
+
```bash
|
|
98
|
+
node index.js
|
|
116
99
|
```
|
|
117
100
|
|
|
118
|
-
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
### Option 2: Clone and Use Locally
|
|
119
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
|
|
120
112
|
```
|
|
121
|
-
|
|
113
|
+
|
|
114
|
+
#### Step 2: Install dependencies
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
npm install
|
|
122
118
|
```
|
|
123
119
|
|
|
124
|
-
|
|
120
|
+
#### Step 3: Create `.env` file
|
|
125
121
|
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
|
130
129
|
```
|
|
131
130
|
|
|
132
|
-
|
|
131
|
+
#### Step 4: Build the project
|
|
133
132
|
|
|
134
133
|
```bash
|
|
135
|
-
|
|
136
|
-
npm run test-perplexity
|
|
134
|
+
npm run build
|
|
137
135
|
```
|
|
138
136
|
|
|
139
|
-
|
|
137
|
+
#### Step 5: Run examples
|
|
138
|
+
|
|
139
|
+
**TypeScript Examples:**
|
|
140
140
|
|
|
141
|
-
|
|
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:**
|
|
142
149
|
|
|
143
150
|
```bash
|
|
144
|
-
|
|
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
|
|
145
155
|
```
|
|
146
156
|
|
|
147
|
-
####
|
|
157
|
+
#### Step 6: Use in your own code
|
|
148
158
|
|
|
149
|
-
|
|
159
|
+
After building, you can import from the local build:
|
|
150
160
|
|
|
151
161
|
```javascript
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const middleware = new PerplexityReveniumMiddleware();
|
|
158
|
-
const model = middleware.getGenerativeModel("sonar-pro");
|
|
159
|
-
const stream = await model.createChatCompletionStream({
|
|
160
|
-
messages: [
|
|
161
|
-
{
|
|
162
|
-
role: "user",
|
|
163
|
-
content: "What is artificial intelligence?",
|
|
164
|
-
},
|
|
165
|
-
],
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
console.log("*** STREAMING RESPONSE ***");
|
|
169
|
-
let fullText = "";
|
|
170
|
-
|
|
171
|
-
for await (const chunk of stream) {
|
|
172
|
-
const content = chunk.choices[0]?.delta?.content;
|
|
173
|
-
if (content) {
|
|
174
|
-
process.stdout.write(content);
|
|
175
|
-
fullText += content;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
console.log("\nโ
Streaming with metering successful!");
|
|
180
|
-
console.log(`๐ Total response length: ${fullText.length} characters`);
|
|
181
|
-
} catch (error) {
|
|
182
|
-
console.error("โ Perplexity streaming example failed:", error);
|
|
183
|
-
process.exit(1);
|
|
184
|
-
}
|
|
185
|
-
};
|
|
162
|
+
const {
|
|
163
|
+
initializeReveniumFromEnv,
|
|
164
|
+
initializePerplexityFromEnv,
|
|
165
|
+
createChatCompletion,
|
|
166
|
+
} = require("./dist/cjs");
|
|
186
167
|
|
|
187
|
-
|
|
168
|
+
// Your code here...
|
|
188
169
|
```
|
|
189
170
|
|
|
190
|
-
|
|
171
|
+
---
|
|
191
172
|
|
|
192
|
-
|
|
173
|
+
### Option 3: Add to Existing Project
|
|
193
174
|
|
|
194
|
-
|
|
195
|
-
// examples/metadata-perplexity.js
|
|
196
|
-
import { PerplexityReveniumMiddleware } from "@revenium/perplexity";
|
|
197
|
-
|
|
198
|
-
const metadataExample = async () => {
|
|
199
|
-
try {
|
|
200
|
-
const middleware = new PerplexityReveniumMiddleware();
|
|
201
|
-
const model = middleware.getGenerativeModel("sonar-pro");
|
|
202
|
-
const result = await model.createChatCompletion({
|
|
203
|
-
model: "sonar-pro",
|
|
204
|
-
messages: [{ role: "user", content: "What is the capital of France?" }],
|
|
205
|
-
usageMetadata: {
|
|
206
|
-
taskType: "test",
|
|
207
|
-
subscriberEmail: "test@revenium.ai",
|
|
208
|
-
subscriberId: "123456",
|
|
209
|
-
subscriberCredentialName: "apiKey",
|
|
210
|
-
subscriberCredential: "keyValue",
|
|
211
|
-
organizationId: "123456",
|
|
212
|
-
subscriptionId: "123456",
|
|
213
|
-
productId: "free-trial",
|
|
214
|
-
agent: "perplexity",
|
|
215
|
-
responseQualityScore: 100,
|
|
216
|
-
transactionId: "123456",
|
|
217
|
-
timeToFirstToken: 1000,
|
|
218
|
-
requestTime: new Date(),
|
|
219
|
-
completionStartTime: new Date(),
|
|
220
|
-
operationType: "CHAT",
|
|
221
|
-
inputTokenCount: 10,
|
|
222
|
-
outputTokenCount: 10,
|
|
223
|
-
reasoningTokenCount: 20,
|
|
224
|
-
cacheCreationTokenCount: 0,
|
|
225
|
-
cacheReadTokenCount: 0,
|
|
226
|
-
totalTokenCount: 40,
|
|
227
|
-
responseTime: new Date(),
|
|
228
|
-
requestDuration: 1000,
|
|
229
|
-
stopReason: "END",
|
|
230
|
-
},
|
|
231
|
-
});
|
|
232
|
-
console.log("[BASIC REQUEST]", result.choices[0].message);
|
|
233
|
-
} catch (error) {
|
|
234
|
-
console.error("โ Perplexity streaming example failed:", error);
|
|
235
|
-
process.exit(1);
|
|
236
|
-
}
|
|
237
|
-
};
|
|
175
|
+
**Best for:** Integrating Perplexity with Revenium into an existing Node.js project.
|
|
238
176
|
|
|
239
|
-
|
|
177
|
+
#### Step 1: Install the middleware
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
npm install @revenium/perplexity
|
|
240
181
|
```
|
|
241
182
|
|
|
242
|
-
|
|
183
|
+
#### Step 2: Add environment variables
|
|
243
184
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
},
|
|
254
|
-
"dependencies": {
|
|
255
|
-
"@revenium/perplexity": "^1.0.0"
|
|
256
|
-
}
|
|
257
|
-
}
|
|
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
|
|
258
194
|
```
|
|
259
195
|
|
|
260
|
-
|
|
196
|
+
#### Step 3: Initialize in your application
|
|
261
197
|
|
|
262
|
-
|
|
263
|
-
# Test streaming
|
|
264
|
-
npm run test-perplexity-stream
|
|
198
|
+
**For CommonJS projects:**
|
|
265
199
|
|
|
266
|
-
|
|
267
|
-
|
|
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
|
+
```
|
|
268
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
|
+
}
|
|
269
272
|
```
|
|
270
273
|
|
|
271
274
|
---
|
|
272
275
|
|
|
273
|
-
##
|
|
276
|
+
## ๐ง Quick Start
|
|
274
277
|
|
|
275
|
-
|
|
278
|
+
### 1. Set up environment variables
|
|
276
279
|
|
|
277
|
-
|
|
278
|
-
# Clone the repository
|
|
279
|
-
git clone git@github.com:revenium/revenium-middleware-perplexity-node.git
|
|
280
|
-
cd revenium-middleware-perplexity-node
|
|
280
|
+
Create a `.env` file in your project root:
|
|
281
281
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
282
|
+
```env
|
|
283
|
+
# Perplexity API Configuration
|
|
284
|
+
PERPLEXITY_API_KEY=your_perplexity_api_key
|
|
285
285
|
|
|
286
|
-
#
|
|
287
|
-
|
|
288
|
-
|
|
286
|
+
# Revenium Metering Configuration
|
|
287
|
+
REVENIUM_METERING_API_KEY=your_revenium_api_key
|
|
288
|
+
REVENIUM_METERING_BASE_URL=https://api.revenium.io/meter
|
|
289
289
|
```
|
|
290
290
|
|
|
291
|
-
###
|
|
291
|
+
### 2. Initialize and use
|
|
292
292
|
|
|
293
|
-
|
|
293
|
+
```typescript
|
|
294
|
+
import {
|
|
295
|
+
initializeReveniumFromEnv,
|
|
296
|
+
initializePerplexityFromEnv,
|
|
297
|
+
createChatCompletion,
|
|
298
|
+
PERPLEXITY_MODELS,
|
|
299
|
+
} from "@revenium/perplexity";
|
|
294
300
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
REVENIUM_METERING_API_KEY="your_revenium_api_key_here"
|
|
299
|
-
REVENIUM_METERING_BASE_URL="https://api.revenium.io/meter"
|
|
300
|
-
```
|
|
301
|
+
// Initialize configurations
|
|
302
|
+
initializeReveniumFromEnv();
|
|
303
|
+
initializePerplexityFromEnv();
|
|
301
304
|
|
|
302
|
-
|
|
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
|
+
});
|
|
303
310
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
## Change type to commonjs in package.json
|
|
307
|
-
"type": "commonjs",
|
|
308
|
-
# Then run any of the following
|
|
309
|
-
npm run e-basic # Basic chat completion
|
|
310
|
-
npm run e-streaming # Streaming response
|
|
311
|
-
npm run e-enhanced # Enhanced request
|
|
312
|
-
npm run e-chat-completions # Chat completions
|
|
313
|
-
npm run e-metadata # Metadata request
|
|
314
|
-
|
|
315
|
-
# Playground examples
|
|
316
|
-
# Required build first
|
|
317
|
-
npm run build
|
|
318
|
-
## Change type to module in package.json
|
|
319
|
-
"type": "module",
|
|
320
|
-
# Then run any of the following
|
|
321
|
-
npm run p-basic
|
|
322
|
-
npm run p-streaming
|
|
323
|
-
npm run p-enhanced
|
|
324
|
-
npm run p-metadata
|
|
311
|
+
console.log(result.content);
|
|
312
|
+
// Output: "The capital of France is Paris."
|
|
325
313
|
```
|
|
326
314
|
|
|
327
|
-
|
|
315
|
+
## ๐ API Reference
|
|
328
316
|
|
|
329
|
-
|
|
317
|
+
### Configuration
|
|
330
318
|
|
|
331
|
-
|
|
319
|
+
#### `initializeReveniumFromEnv()`
|
|
332
320
|
|
|
333
|
-
|
|
321
|
+
Initialize Revenium configuration from environment variables.
|
|
334
322
|
|
|
335
|
-
```
|
|
336
|
-
|
|
323
|
+
```typescript
|
|
324
|
+
const config = initializeReveniumFromEnv();
|
|
337
325
|
```
|
|
338
326
|
|
|
339
|
-
|
|
327
|
+
#### `initializePerplexityFromEnv()`
|
|
340
328
|
|
|
341
|
-
|
|
329
|
+
Initialize Perplexity configuration from environment variables.
|
|
342
330
|
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
REVENIUM_METERING_API_KEY="your_revenium_api_key_here"
|
|
346
|
-
REVENIUM_METERING_BASE_URL="https://api.revenium.io/meter"
|
|
331
|
+
```typescript
|
|
332
|
+
const config = initializePerplexityFromEnv();
|
|
347
333
|
```
|
|
348
334
|
|
|
349
|
-
|
|
335
|
+
#### `initializeRevenium(config)`
|
|
350
336
|
|
|
351
|
-
|
|
337
|
+
Initialize Revenium with custom configuration.
|
|
352
338
|
|
|
353
|
-
```
|
|
354
|
-
|
|
339
|
+
```typescript
|
|
340
|
+
initializeRevenium({
|
|
341
|
+
meteringApiKey: "your_api_key",
|
|
342
|
+
meteringBaseUrl: "https://api.revenium.io/meter",
|
|
343
|
+
teamId: "your_team_id", // Optional
|
|
344
|
+
});
|
|
355
345
|
```
|
|
356
346
|
|
|
357
|
-
|
|
347
|
+
#### `initializePerplexity(config)`
|
|
358
348
|
|
|
359
|
-
|
|
360
|
-
|
|
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
|
+
});
|
|
361
356
|
```
|
|
362
357
|
|
|
363
|
-
###
|
|
358
|
+
### Chat Completions
|
|
364
359
|
|
|
365
|
-
####
|
|
360
|
+
#### `createChatCompletion(params)`
|
|
366
361
|
|
|
367
|
-
|
|
368
|
-
import { PerplexityReveniumMiddleware } from "@revenium/perplexity";
|
|
362
|
+
Create a chat completion with automatic metering.
|
|
369
363
|
|
|
370
|
-
|
|
371
|
-
const
|
|
372
|
-
const model = middleware.getGenerativeModel("sonar-pro");
|
|
373
|
-
const result = await model.createChatCompletion({
|
|
364
|
+
```typescript
|
|
365
|
+
const result = await createChatCompletion({
|
|
374
366
|
messages: [
|
|
375
|
-
{
|
|
376
|
-
|
|
377
|
-
content: "Hello world",
|
|
378
|
-
},
|
|
367
|
+
{ role: "system", content: "You are a helpful assistant." },
|
|
368
|
+
{ role: "user", content: "Hello!" },
|
|
379
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
|
+
},
|
|
380
379
|
});
|
|
381
|
-
|
|
380
|
+
|
|
381
|
+
console.log(result.content);
|
|
382
|
+
console.log(result.usage);
|
|
383
|
+
console.log(result.transactionId);
|
|
382
384
|
```
|
|
383
385
|
|
|
384
|
-
|
|
386
|
+
**Parameters:**
|
|
387
|
+
|
|
388
|
+
- `messages` - Array of message objects with `role` and `content`
|
|
389
|
+
- `model` - Perplexity model to use (see [Available Models](#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:**
|
|
385
398
|
|
|
386
|
-
|
|
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
|
+
```
|
|
387
414
|
|
|
388
|
-
|
|
415
|
+
#### `createStreamingChatCompletion(params)`
|
|
389
416
|
|
|
390
|
-
|
|
417
|
+
Create a streaming chat completion.
|
|
391
418
|
|
|
392
|
-
```
|
|
393
|
-
const
|
|
394
|
-
messages: [
|
|
395
|
-
|
|
396
|
-
role: "user",
|
|
397
|
-
content: "Hello world",
|
|
398
|
-
},
|
|
399
|
-
],
|
|
419
|
+
```typescript
|
|
420
|
+
const result = await createStreamingChatCompletion({
|
|
421
|
+
messages: [{ role: "user", content: "Count from 1 to 5" }],
|
|
422
|
+
model: PERPLEXITY_MODELS.SONAR_PRO,
|
|
400
423
|
});
|
|
401
|
-
|
|
402
|
-
|
|
424
|
+
|
|
425
|
+
for await (const chunk of result.stream) {
|
|
426
|
+
const content = chunk.choices[0]?.delta?.content || "";
|
|
427
|
+
process.stdout.write(content);
|
|
403
428
|
}
|
|
404
429
|
```
|
|
405
430
|
|
|
406
|
-
|
|
431
|
+
**Returns:**
|
|
407
432
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
---
|
|
433
|
+
```typescript
|
|
434
|
+
{
|
|
435
|
+
stream: AsyncGenerator<PerplexityStreamChunk>;
|
|
436
|
+
transactionId: string;
|
|
437
|
+
model: string;
|
|
438
|
+
}
|
|
439
|
+
```
|
|
417
440
|
|
|
418
|
-
|
|
441
|
+
### Available Models
|
|
419
442
|
|
|
420
|
-
|
|
443
|
+
```typescript
|
|
444
|
+
import { PERPLEXITY_MODELS } from "@revenium/perplexity";
|
|
421
445
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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"
|
|
425
450
|
|
|
426
|
-
|
|
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
|
+
```
|
|
427
456
|
|
|
428
|
-
|
|
457
|
+
### Utility Functions
|
|
429
458
|
|
|
430
|
-
|
|
459
|
+
#### `disableRevenium()` / `enableRevenium()`
|
|
431
460
|
|
|
432
|
-
|
|
461
|
+
Temporarily disable or enable Revenium metering.
|
|
433
462
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
| `PERPLEXITY_API_KEY` | โ
| Your Perplexity API key |
|
|
437
|
-
| `REVENIUM_METERING_API_KEY` | โ
| Your Revenium API key |
|
|
438
|
-
| `REVENIUM_METERING_BASE_URL` | โ | Revenium base URL (default: https://api.revenium.io/meter) |
|
|
463
|
+
```typescript
|
|
464
|
+
import { disableRevenium, enableRevenium } from "@revenium/perplexity";
|
|
439
465
|
|
|
440
|
-
|
|
466
|
+
disableRevenium(); // Stop sending metering data
|
|
467
|
+
// ... make API calls ...
|
|
468
|
+
enableRevenium(); // Resume sending metering data
|
|
469
|
+
```
|
|
441
470
|
|
|
442
|
-
|
|
471
|
+
#### `generateTransactionId()`
|
|
443
472
|
|
|
444
|
-
|
|
473
|
+
Generate a unique transaction ID.
|
|
445
474
|
|
|
446
|
-
|
|
475
|
+
```typescript
|
|
476
|
+
import { generateTransactionId } from "@revenium/perplexity";
|
|
447
477
|
|
|
448
|
-
|
|
449
|
-
export PERPLEXITY_API_KEY="your-actual-api-key"
|
|
450
|
-
echo $PERPLEXITY_API_KEY # Verify it's set
|
|
478
|
+
const txnId = generateTransactionId();
|
|
451
479
|
```
|
|
452
480
|
|
|
453
|
-
|
|
481
|
+
## ๐ Examples
|
|
454
482
|
|
|
455
|
-
|
|
456
|
-
|
|
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);
|
|
457
502
|
```
|
|
458
503
|
|
|
459
|
-
|
|
504
|
+
### Streaming Response
|
|
460
505
|
|
|
461
|
-
```
|
|
462
|
-
{
|
|
463
|
-
"
|
|
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);
|
|
464
515
|
}
|
|
465
516
|
```
|
|
466
517
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
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
|
+
});
|
|
471
538
|
```
|
|
472
539
|
|
|
473
|
-
|
|
540
|
+
### Custom Metadata
|
|
474
541
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
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
|
+
```
|
|
480
557
|
|
|
481
|
-
|
|
558
|
+
## ๐๏ธ Project Structure
|
|
482
559
|
|
|
483
|
-
|
|
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
|
+
```
|
|
484
577
|
|
|
485
|
-
|
|
578
|
+
## ๐งช Running Examples
|
|
486
579
|
|
|
487
|
-
|
|
488
|
-
- **Streaming**: Real-time response streaming
|
|
489
|
-
- **Metadata**: Rich tracking examples
|
|
490
|
-
- **Error Handling**: Robust error management
|
|
491
|
-
- **Advanced Patterns**: Complex use cases
|
|
492
|
-
- **Configuration**: Different setup options
|
|
580
|
+
### TypeScript Examples
|
|
493
581
|
|
|
494
|
-
|
|
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
|
+
```
|
|
495
588
|
|
|
496
|
-
|
|
589
|
+
### JavaScript Playground
|
|
497
590
|
|
|
498
|
-
|
|
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
|
+
```
|
|
499
597
|
|
|
500
|
-
|
|
501
|
-
- Perplexity API key
|
|
502
|
-
- Revenium API key
|
|
598
|
+
## ๐ Environment Variables
|
|
503
599
|
|
|
504
|
-
|
|
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`) |
|
|
505
605
|
|
|
506
606
|
## ๐ License
|
|
507
607
|
|
|
508
|
-
|
|
608
|
+
ISC
|
|
509
609
|
|
|
510
|
-
|
|
610
|
+
## ๐ค Contributing
|
|
511
611
|
|
|
512
|
-
|
|
612
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
513
613
|
|
|
514
|
-
|
|
515
|
-
- ๐ฌ [Community Support](https://community.revenium.com)
|
|
516
|
-
- ๐ง [Email Support](mailto:support@revenium.com)
|
|
517
|
-
- ๐ [Report Issues](https://github.com/revenium/revenium-middleware-perplexity-node/issues)
|
|
614
|
+
## ๐ Support
|
|
518
615
|
|
|
519
|
-
|
|
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
|
|
520
622
|
|
|
521
|
-
|
|
623
|
+
- [Perplexity AI Documentation](https://docs.perplexity.ai)
|
|
624
|
+
- [Revenium Platform](https://revenium.io)
|
|
625
|
+
- [npm Package](https://www.npmjs.com/package/@revenium/perplexity)
|