@revenium/openai 1.0.8 → 1.0.9
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 +106 -49
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,10 +31,10 @@ Choose your preferred approach to get started quickly:
|
|
|
31
31
|
Perfect for new projects. We'll guide you step-by-step from `mkdir` to running tests.
|
|
32
32
|
[👉 Go to Step-by-Step Guide](#option-1-create-project-from-scratch)
|
|
33
33
|
|
|
34
|
-
### Option 2:
|
|
34
|
+
### Option 2: Clone Our Repository
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
[👉 Go to
|
|
36
|
+
Clone and run the repository with working examples.
|
|
37
|
+
[👉 Go to Repository Guide](#option-2-clone-our-repository)
|
|
38
38
|
|
|
39
39
|
### Option 3: Add to Existing Project
|
|
40
40
|
|
|
@@ -81,15 +81,24 @@ New-Item -Path .env -ItemType File
|
|
|
81
81
|
Copy and paste the following into `.env`:
|
|
82
82
|
|
|
83
83
|
```env
|
|
84
|
-
# OpenAI Configuration
|
|
85
|
-
|
|
84
|
+
# Revenium OpenAI Middleware Configuration
|
|
85
|
+
# Copy this file to .env and fill in your actual values
|
|
86
86
|
|
|
87
|
-
# Revenium
|
|
87
|
+
# Required: Your Revenium API key (starts with hak_)
|
|
88
88
|
REVENIUM_METERING_API_KEY=hak_your_revenium_api_key_here
|
|
89
89
|
REVENIUM_METERING_BASE_URL=https://api.revenium.io/meter
|
|
90
90
|
|
|
91
|
+
# Required: Your OpenAI API key (starts with sk-)
|
|
92
|
+
OPENAI_API_KEY=sk_your_openai_api_key_here
|
|
93
|
+
|
|
94
|
+
# Optional: Your Azure OpenAI configuration (for Azure testing)
|
|
95
|
+
AZURE_OPENAI_ENDPOINT=https://your-resource-name.openai.azure.com/
|
|
96
|
+
AZURE_OPENAI_API_KEY=your-azure-openai-api-key-here
|
|
97
|
+
AZURE_OPENAI_DEPLOYMENT=your-deployment-name-here
|
|
98
|
+
AZURE_OPENAI_API_VERSION=2024-12-01-preview
|
|
99
|
+
|
|
91
100
|
# Optional: Enable debug logging
|
|
92
|
-
REVENIUM_DEBUG=
|
|
101
|
+
REVENIUM_DEBUG=false
|
|
93
102
|
```
|
|
94
103
|
|
|
95
104
|
**💡 NOTE**: Replace each `your_..._here` with your actual values.
|
|
@@ -246,26 +255,53 @@ my-openai-project/
|
|
|
246
255
|
└── test-openai.js # JavaScript test
|
|
247
256
|
```
|
|
248
257
|
|
|
249
|
-
## Option 2:
|
|
258
|
+
## Option 2: Clone Our Repository
|
|
250
259
|
|
|
251
|
-
### Step 1:
|
|
260
|
+
### Step 1: Clone the Repository
|
|
252
261
|
|
|
253
262
|
```bash
|
|
254
|
-
|
|
263
|
+
# Clone the repository
|
|
264
|
+
git clone git@github.com:revenium/revenium-middleware-openai-node.git
|
|
265
|
+
cd revenium-middleware-openai-node
|
|
255
266
|
```
|
|
256
267
|
|
|
257
|
-
### Step 2:
|
|
268
|
+
### Step 2: Install Dependencies
|
|
258
269
|
|
|
259
270
|
```bash
|
|
260
|
-
#
|
|
261
|
-
|
|
271
|
+
# Install all dependencies
|
|
272
|
+
npm install
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Step 3: Setup Environment Variables
|
|
276
|
+
|
|
277
|
+
Create a `.env` file in the project root:
|
|
262
278
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
279
|
+
```bash
|
|
280
|
+
# Create .env file
|
|
281
|
+
cp .env.example .env # If available, or create manually
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Copy and paste the following into `.env`:
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
# Revenium OpenAI Middleware Configuration
|
|
288
|
+
# Copy this file to .env and fill in your actual values
|
|
289
|
+
|
|
290
|
+
# Required: Your Revenium API key (starts with hak_)
|
|
291
|
+
REVENIUM_METERING_API_KEY=hak_your_revenium_api_key_here
|
|
292
|
+
REVENIUM_METERING_BASE_URL=https://api.revenium.io/meter
|
|
293
|
+
|
|
294
|
+
# Required: Your OpenAI API key (starts with sk-)
|
|
295
|
+
OPENAI_API_KEY=sk_your_openai_api_key_here
|
|
296
|
+
|
|
297
|
+
# Optional: Your Azure OpenAI configuration (for Azure testing)
|
|
298
|
+
AZURE_OPENAI_ENDPOINT=https://your-resource-name.openai.azure.com/
|
|
299
|
+
AZURE_OPENAI_API_KEY=your-azure-openai-api-key-here
|
|
300
|
+
AZURE_OPENAI_DEPLOYMENT=your-deployment-name-here
|
|
301
|
+
AZURE_OPENAI_API_VERSION=2024-12-01-preview
|
|
266
302
|
|
|
267
303
|
# Optional: Enable debug logging
|
|
268
|
-
|
|
304
|
+
REVENIUM_DEBUG=false
|
|
269
305
|
```
|
|
270
306
|
|
|
271
307
|
**⚠️ IMPORTANT - Environment Matching**:
|
|
@@ -274,36 +310,39 @@ export REVENIUM_DEBUG="true"
|
|
|
274
310
|
- If using Production environment URL `"https://api.revenium.io/meter"`, ensure your `REVENIUM_METERING_API_KEY` is from the **Production environment**
|
|
275
311
|
- **Mismatched environments will cause authentication failures**
|
|
276
312
|
|
|
277
|
-
### Step
|
|
278
|
-
|
|
279
|
-
The package includes working example files:
|
|
280
|
-
|
|
281
|
-
### Chat Completions API (Current)
|
|
313
|
+
### Step 4: Build the Project
|
|
282
314
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
315
|
+
```bash
|
|
316
|
+
# Build the middleware
|
|
317
|
+
npm run build
|
|
318
|
+
```
|
|
287
319
|
|
|
288
|
-
###
|
|
320
|
+
### Step 5: Run the Examples
|
|
289
321
|
|
|
290
|
-
|
|
291
|
-
- **[OpenAI Responses Streaming](examples/openai-responses-streaming.ts)** - Streaming Responses API with optional metadata
|
|
292
|
-
- **[Azure Responses Basic](examples/azure-responses-basic.ts)** - Azure Responses API with optional metadata
|
|
293
|
-
- **[Azure Responses Streaming](examples/azure-responses-streaming.ts)** - Azure streaming Responses API with optional metadata
|
|
322
|
+
The repository includes working example files:
|
|
294
323
|
|
|
295
324
|
```bash
|
|
296
|
-
# Chat Completions API examples
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
# Responses API examples (available with OpenAI SDK 5.8+)
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
325
|
+
# Run Chat Completions API examples (using npm scripts)
|
|
326
|
+
npm run example:openai-basic
|
|
327
|
+
npm run example:openai-streaming
|
|
328
|
+
npm run example:azure-basic
|
|
329
|
+
npm run example:azure-streaming
|
|
330
|
+
|
|
331
|
+
# Run Responses API examples (available with OpenAI SDK 5.8+)
|
|
332
|
+
npm run example:openai-responses-basic
|
|
333
|
+
npm run example:openai-responses-streaming
|
|
334
|
+
npm run example:azure-responses-basic
|
|
335
|
+
npm run example:azure-responses-streaming
|
|
336
|
+
|
|
337
|
+
# Or run examples directly with tsx
|
|
338
|
+
npx tsx examples/openai-basic.ts
|
|
339
|
+
npx tsx examples/openai-streaming.ts
|
|
340
|
+
npx tsx examples/azure-basic.ts
|
|
341
|
+
npx tsx examples/azure-streaming.ts
|
|
342
|
+
npx tsx examples/openai-responses-basic.ts
|
|
343
|
+
npx tsx examples/openai-responses-streaming.ts
|
|
344
|
+
npx tsx examples/azure-responses-basic.ts
|
|
345
|
+
npx tsx examples/azure-responses-streaming.ts
|
|
307
346
|
```
|
|
308
347
|
|
|
309
348
|
These examples demonstrate:
|
|
@@ -353,9 +392,23 @@ const openai = patchOpenAIInstance(new OpenAI());
|
|
|
353
392
|
Add to your `.env` file:
|
|
354
393
|
|
|
355
394
|
```env
|
|
395
|
+
# Revenium OpenAI Middleware Configuration
|
|
396
|
+
|
|
397
|
+
# Required: Your Revenium API key (starts with hak_)
|
|
356
398
|
REVENIUM_METERING_API_KEY=hak_your_revenium_api_key_here
|
|
357
399
|
REVENIUM_METERING_BASE_URL=https://api.revenium.io/meter
|
|
358
|
-
|
|
400
|
+
|
|
401
|
+
# Required: Your OpenAI API key (starts with sk-)
|
|
402
|
+
OPENAI_API_KEY=sk_your_openai_api_key_here
|
|
403
|
+
|
|
404
|
+
# Optional: Your Azure OpenAI configuration (for Azure testing)
|
|
405
|
+
AZURE_OPENAI_ENDPOINT=https://your-resource-name.openai.azure.com/
|
|
406
|
+
AZURE_OPENAI_API_KEY=your-azure-openai-api-key-here
|
|
407
|
+
AZURE_OPENAI_DEPLOYMENT=your-deployment-name-here
|
|
408
|
+
AZURE_OPENAI_API_VERSION=2024-12-01-preview
|
|
409
|
+
|
|
410
|
+
# Optional: Enable debug logging
|
|
411
|
+
REVENIUM_DEBUG=false
|
|
359
412
|
```
|
|
360
413
|
|
|
361
414
|
### Step 4: Optional - Add Metadata
|
|
@@ -846,12 +899,16 @@ configure({
|
|
|
846
899
|
|
|
847
900
|
### Environment Variables
|
|
848
901
|
|
|
849
|
-
| Variable
|
|
850
|
-
|
|
|
851
|
-
| `REVENIUM_METERING_API_KEY`
|
|
852
|
-
| `OPENAI_API_KEY`
|
|
853
|
-
| `REVENIUM_METERING_BASE_URL`
|
|
854
|
-
| `REVENIUM_DEBUG`
|
|
902
|
+
| Variable | Required | Default | Description |
|
|
903
|
+
| ------------------------------ | -------- | ------------------------------- | ---------------------------------------------- |
|
|
904
|
+
| `REVENIUM_METERING_API_KEY` | ✅ | - | Your Revenium API key (starts with `hak_`) |
|
|
905
|
+
| `OPENAI_API_KEY` | ✅ | - | Your OpenAI API key (starts with `sk-`) |
|
|
906
|
+
| `REVENIUM_METERING_BASE_URL` | ❌ | `https://api.revenium.io/meter` | Revenium metering API base URL |
|
|
907
|
+
| `REVENIUM_DEBUG` | ❌ | `false` | Enable debug logging (`true`/`false`) |
|
|
908
|
+
| `AZURE_OPENAI_ENDPOINT` | ❌ | - | Azure OpenAI endpoint URL (for Azure testing) |
|
|
909
|
+
| `AZURE_OPENAI_API_KEY` | ❌ | - | Azure OpenAI API key (for Azure testing) |
|
|
910
|
+
| `AZURE_OPENAI_DEPLOYMENT` | ❌ | - | Azure OpenAI deployment name (for Azure) |
|
|
911
|
+
| `AZURE_OPENAI_API_VERSION` | ❌ | `2024-12-01-preview` | Azure OpenAI API version (for Azure) |
|
|
855
912
|
|
|
856
913
|
**⚠️ Important Note about `REVENIUM_METERING_BASE_URL`:**
|
|
857
914
|
|
package/package.json
CHANGED