@revenium/openai 1.0.11 → 1.0.13
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/.env.example +20 -0
- package/CHANGELOG.md +47 -47
- package/README.md +121 -964
- package/dist/cjs/core/config/loader.js +1 -1
- package/dist/cjs/core/config/loader.js.map +1 -1
- package/dist/cjs/core/config/manager.js +2 -1
- package/dist/cjs/core/config/manager.js.map +1 -1
- package/dist/cjs/core/providers/detector.js +3 -3
- package/dist/cjs/core/providers/detector.js.map +1 -1
- package/dist/cjs/core/tracking/api-client.js +1 -1
- package/dist/cjs/core/tracking/api-client.js.map +1 -1
- package/dist/cjs/core/tracking/payload-builder.js +17 -12
- package/dist/cjs/core/tracking/payload-builder.js.map +1 -1
- package/dist/cjs/index.js +23 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/utils/metadata-builder.js +12 -5
- package/dist/cjs/utils/metadata-builder.js.map +1 -1
- package/dist/cjs/utils/stop-reason-mapper.js +4 -0
- package/dist/cjs/utils/stop-reason-mapper.js.map +1 -1
- package/dist/cjs/utils/url-builder.js +32 -7
- package/dist/cjs/utils/url-builder.js.map +1 -1
- package/dist/esm/core/config/loader.js +1 -1
- package/dist/esm/core/config/loader.js.map +1 -1
- package/dist/esm/core/config/manager.js +2 -1
- package/dist/esm/core/config/manager.js.map +1 -1
- package/dist/esm/core/providers/detector.js +3 -3
- package/dist/esm/core/providers/detector.js.map +1 -1
- package/dist/esm/core/tracking/api-client.js +1 -1
- package/dist/esm/core/tracking/api-client.js.map +1 -1
- package/dist/esm/core/tracking/payload-builder.js +17 -12
- package/dist/esm/core/tracking/payload-builder.js.map +1 -1
- package/dist/esm/index.js +22 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/utils/metadata-builder.js +12 -5
- package/dist/esm/utils/metadata-builder.js.map +1 -1
- package/dist/esm/utils/stop-reason-mapper.js +4 -0
- package/dist/esm/utils/stop-reason-mapper.js.map +1 -1
- package/dist/esm/utils/url-builder.js +32 -7
- package/dist/esm/utils/url-builder.js.map +1 -1
- package/dist/types/core/config/manager.d.ts.map +1 -1
- package/dist/types/core/tracking/payload-builder.d.ts.map +1 -1
- package/dist/types/index.d.ts +23 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +9 -13
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/types/openai-augmentation.d.ts +1 -2
- package/dist/types/types/openai-augmentation.d.ts.map +1 -1
- package/dist/types/utils/metadata-builder.d.ts +2 -1
- package/dist/types/utils/metadata-builder.d.ts.map +1 -1
- package/dist/types/utils/stop-reason-mapper.d.ts.map +1 -1
- package/dist/types/utils/url-builder.d.ts +11 -3
- package/dist/types/utils/url-builder.d.ts.map +1 -1
- package/examples/README.md +213 -255
- package/examples/azure-basic.ts +26 -14
- package/examples/azure-responses-basic.ts +39 -10
- package/examples/azure-responses-streaming.ts +39 -10
- package/examples/azure-streaming.ts +41 -20
- package/examples/getting_started.ts +54 -0
- package/examples/openai-basic.ts +39 -17
- package/examples/openai-function-calling.ts +259 -0
- package/examples/openai-responses-basic.ts +38 -9
- package/examples/openai-responses-streaming.ts +38 -9
- package/examples/openai-streaming.ts +24 -13
- package/examples/openai-vision.ts +289 -0
- package/package.json +3 -9
- package/src/core/config/azure-config.ts +72 -0
- package/src/core/config/index.ts +23 -0
- package/src/core/config/loader.ts +66 -0
- package/src/core/config/manager.ts +95 -0
- package/src/core/config/validator.ts +89 -0
- package/src/core/providers/detector.ts +159 -0
- package/src/core/providers/index.ts +16 -0
- package/src/core/tracking/api-client.ts +78 -0
- package/src/core/tracking/index.ts +21 -0
- package/src/core/tracking/payload-builder.ts +137 -0
- package/src/core/tracking/usage-tracker.ts +189 -0
- package/src/core/wrapper/index.ts +9 -0
- package/src/core/wrapper/instance-patcher.ts +288 -0
- package/src/core/wrapper/request-handler.ts +423 -0
- package/src/core/wrapper/stream-wrapper.ts +100 -0
- package/src/index.ts +360 -0
- package/src/types/function-parameters.ts +251 -0
- package/src/types/index.ts +310 -0
- package/src/types/openai-augmentation.ts +232 -0
- package/src/types/responses-api.ts +308 -0
- package/src/utils/azure-model-resolver.ts +220 -0
- package/src/utils/constants.ts +21 -0
- package/src/utils/error-handler.ts +251 -0
- package/src/utils/metadata-builder.ts +228 -0
- package/src/utils/provider-detection.ts +257 -0
- package/src/utils/request-handler-factory.ts +285 -0
- package/src/utils/stop-reason-mapper.ts +78 -0
- package/src/utils/type-guards.ts +202 -0
- package/src/utils/url-builder.ts +68 -0
|
@@ -5,7 +5,16 @@
|
|
|
5
5
|
* The Responses API is a new stateful API that brings together capabilities from chat completions
|
|
6
6
|
* and assistants API in one unified experience.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* Metadata Options:
|
|
9
|
+
* - Start with basic usage (no metadata) - tracking works automatically
|
|
10
|
+
* - Add subscriber info for user tracking
|
|
11
|
+
* - Include organization/product IDs for business analytics
|
|
12
|
+
* - Use task type and trace ID for detailed analysis
|
|
13
|
+
*
|
|
14
|
+
* For complete metadata field reference, see:
|
|
15
|
+
* https://revenium.readme.io/reference/meter_ai_completion
|
|
16
|
+
*
|
|
17
|
+
* Responses API Reference: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/responses
|
|
9
18
|
*/
|
|
10
19
|
|
|
11
20
|
import 'dotenv/config';
|
|
@@ -35,7 +44,7 @@ async function main() {
|
|
|
35
44
|
const azure = new OpenAI({
|
|
36
45
|
apiKey: process.env.AZURE_OPENAI_API_KEY,
|
|
37
46
|
baseURL: `${process.env.AZURE_OPENAI_ENDPOINT}/openai/deployments/${process.env.AZURE_OPENAI_DEPLOYMENT_NAME}`,
|
|
38
|
-
defaultQuery: { 'api-version': '2024-
|
|
47
|
+
defaultQuery: { 'api-version': '2024-12-01-preview' },
|
|
39
48
|
defaultHeaders: {
|
|
40
49
|
'api-key': process.env.AZURE_OPENAI_API_KEY,
|
|
41
50
|
},
|
|
@@ -89,20 +98,30 @@ async function main() {
|
|
|
89
98
|
temperature: 0.6,
|
|
90
99
|
max_output_tokens: 200,
|
|
91
100
|
usageMetadata: {
|
|
101
|
+
// User identification
|
|
92
102
|
subscriber: {
|
|
93
103
|
id: 'azure-enterprise-user-123',
|
|
94
104
|
email: 'enterprise@azurecorp.com',
|
|
95
105
|
credential: {
|
|
96
|
-
name: '
|
|
97
|
-
value: '
|
|
106
|
+
name: 'api-key-prod',
|
|
107
|
+
value: 'key-stu-901',
|
|
98
108
|
},
|
|
99
109
|
},
|
|
110
|
+
|
|
111
|
+
// Organization & billing
|
|
100
112
|
organizationId: 'azure-enterprise-org-456',
|
|
113
|
+
subscriptionId: 'plan-azure-responses-2024',
|
|
114
|
+
|
|
115
|
+
// Product & task tracking
|
|
101
116
|
productId: 'azure-ai-integration-assistant',
|
|
102
117
|
taskType: 'enterprise-architecture-guidance',
|
|
103
|
-
traceId: 'azure-trace-789',
|
|
104
118
|
agent: 'azure-ai-architect',
|
|
105
|
-
|
|
119
|
+
|
|
120
|
+
// Session tracking
|
|
121
|
+
traceId: 'azure-trace-789',
|
|
122
|
+
|
|
123
|
+
// Quality metrics
|
|
124
|
+
responseQualityScore: 0.96, // 0.0-1.0 scale
|
|
106
125
|
},
|
|
107
126
|
} as ResponsesCreateParams);
|
|
108
127
|
|
|
@@ -167,20 +186,30 @@ async function main() {
|
|
|
167
186
|
instructions:
|
|
168
187
|
'You are an Azure AI solutions architect providing detailed technical guidance.',
|
|
169
188
|
usageMetadata: {
|
|
189
|
+
// User identification
|
|
170
190
|
subscriber: {
|
|
171
191
|
id: 'azure-saas-architect-789',
|
|
172
192
|
email: 'architect@azuresaas.com',
|
|
173
193
|
credential: {
|
|
174
|
-
name: '
|
|
175
|
-
value: '
|
|
194
|
+
name: 'api-key-prod',
|
|
195
|
+
value: 'key-vwx-234',
|
|
176
196
|
},
|
|
177
197
|
},
|
|
198
|
+
|
|
199
|
+
// Organization & billing
|
|
178
200
|
organizationId: 'azure-saas-enterprise-012',
|
|
201
|
+
subscriptionId: 'plan-azure-saas-2024',
|
|
202
|
+
|
|
203
|
+
// Product & task tracking
|
|
179
204
|
productId: 'azure-saas-ai-architect',
|
|
180
205
|
taskType: 'multi-tenant-architecture-design',
|
|
181
|
-
traceId: 'azure-saas-trace-345',
|
|
182
206
|
agent: 'azure-saas-solutions-architect',
|
|
183
|
-
|
|
207
|
+
|
|
208
|
+
// Session tracking
|
|
209
|
+
traceId: 'azure-saas-trace-345',
|
|
210
|
+
|
|
211
|
+
// Quality metrics
|
|
212
|
+
responseQualityScore: 0.99, // 0.0-1.0 scale
|
|
184
213
|
},
|
|
185
214
|
} as ResponsesCreateParams);
|
|
186
215
|
|
|
@@ -5,7 +5,16 @@
|
|
|
5
5
|
* using the Revenium middleware. The Responses API supports streaming for real-time
|
|
6
6
|
* response generation in Azure environments.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* Metadata Options:
|
|
9
|
+
* - Start with basic usage (no metadata) - tracking works automatically
|
|
10
|
+
* - Add subscriber info for user tracking
|
|
11
|
+
* - Include organization/product IDs for business analytics
|
|
12
|
+
* - Use task type and trace ID for detailed analysis
|
|
13
|
+
*
|
|
14
|
+
* For complete metadata field reference, see:
|
|
15
|
+
* https://revenium.readme.io/reference/meter_ai_completion
|
|
16
|
+
*
|
|
17
|
+
* Responses API Reference: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/responses
|
|
9
18
|
*/
|
|
10
19
|
|
|
11
20
|
import 'dotenv/config';
|
|
@@ -35,7 +44,7 @@ async function main() {
|
|
|
35
44
|
const azure = new OpenAI({
|
|
36
45
|
apiKey: process.env.AZURE_OPENAI_API_KEY,
|
|
37
46
|
baseURL: `${process.env.AZURE_OPENAI_ENDPOINT}/openai/deployments/${process.env.AZURE_OPENAI_DEPLOYMENT_NAME}`,
|
|
38
|
-
defaultQuery: { 'api-version': '2024-
|
|
47
|
+
defaultQuery: { 'api-version': '2024-12-01-preview' },
|
|
39
48
|
defaultHeaders: {
|
|
40
49
|
'api-key': process.env.AZURE_OPENAI_API_KEY,
|
|
41
50
|
},
|
|
@@ -94,20 +103,30 @@ async function main() {
|
|
|
94
103
|
temperature: 0.7,
|
|
95
104
|
max_output_tokens: 250,
|
|
96
105
|
usageMetadata: {
|
|
106
|
+
// User identification
|
|
97
107
|
subscriber: {
|
|
98
108
|
id: 'azure-security-expert-123',
|
|
99
109
|
email: 'security@azureenterprise.com',
|
|
100
110
|
credential: {
|
|
101
|
-
name: '
|
|
102
|
-
value: '
|
|
111
|
+
name: 'api-key-prod',
|
|
112
|
+
value: 'key-yza-567',
|
|
103
113
|
},
|
|
104
114
|
},
|
|
115
|
+
|
|
116
|
+
// Organization & billing
|
|
105
117
|
organizationId: 'azure-security-org-456',
|
|
118
|
+
subscriptionId: 'plan-azure-security-2024',
|
|
119
|
+
|
|
120
|
+
// Product & task tracking
|
|
106
121
|
productId: 'azure-ai-security-advisor',
|
|
107
122
|
taskType: 'enterprise-security-streaming',
|
|
108
|
-
traceId: 'azure-security-trace-789',
|
|
109
123
|
agent: 'azure-security-architect',
|
|
110
|
-
|
|
124
|
+
|
|
125
|
+
// Session tracking
|
|
126
|
+
traceId: 'azure-security-trace-789',
|
|
127
|
+
|
|
128
|
+
// Quality metrics
|
|
129
|
+
responseQualityScore: 0.94, // 0.0-1.0 scale
|
|
111
130
|
},
|
|
112
131
|
} as ResponsesCreateParams);
|
|
113
132
|
|
|
@@ -186,20 +205,30 @@ async function main() {
|
|
|
186
205
|
instructions:
|
|
187
206
|
'You are an Azure solutions architect specializing in scalable AI implementations with enterprise governance.',
|
|
188
207
|
usageMetadata: {
|
|
208
|
+
// User identification
|
|
189
209
|
subscriber: {
|
|
190
210
|
id: 'azure-enterprise-architect-789',
|
|
191
211
|
email: 'architect@azureenterprise.com',
|
|
192
212
|
credential: {
|
|
193
|
-
name: '
|
|
194
|
-
value: '
|
|
213
|
+
name: 'api-key-prod',
|
|
214
|
+
value: 'key-bcd-890',
|
|
195
215
|
},
|
|
196
216
|
},
|
|
217
|
+
|
|
218
|
+
// Organization & billing
|
|
197
219
|
organizationId: 'azure-enterprise-streaming-012',
|
|
220
|
+
subscriptionId: 'plan-azure-scalable-2024',
|
|
221
|
+
|
|
222
|
+
// Product & task tracking
|
|
198
223
|
productId: 'azure-scalable-ai-architect',
|
|
199
224
|
taskType: 'enterprise-scalable-ai-streaming',
|
|
200
|
-
traceId: 'azure-scalable-trace-345',
|
|
201
225
|
agent: 'azure-enterprise-solutions-architect',
|
|
202
|
-
|
|
226
|
+
|
|
227
|
+
// Session tracking
|
|
228
|
+
traceId: 'azure-scalable-trace-345',
|
|
229
|
+
|
|
230
|
+
// Quality metrics
|
|
231
|
+
responseQualityScore: 0.98, // 0.0-1.0 scale
|
|
203
232
|
},
|
|
204
233
|
} as ResponsesCreateParams);
|
|
205
234
|
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Azure OpenAI Streaming Example
|
|
3
3
|
*
|
|
4
4
|
* Shows how to use Revenium middleware with Azure OpenAI streaming responses.
|
|
5
5
|
* Demonstrates seamless metadata integration with Azure streaming - all metadata fields are optional!
|
|
6
|
+
*
|
|
7
|
+
* Metadata Options:
|
|
8
|
+
* - Start with basic usage (no metadata) - tracking works automatically
|
|
9
|
+
* - Add subscriber info for user tracking
|
|
10
|
+
* - Include organization/product IDs for business analytics
|
|
11
|
+
* - Use task type and trace ID for detailed analysis
|
|
12
|
+
*
|
|
13
|
+
* For complete metadata field reference, see:
|
|
14
|
+
* https://revenium.readme.io/reference/meter_ai_completion
|
|
6
15
|
*/
|
|
7
16
|
|
|
8
17
|
import 'dotenv/config';
|
|
@@ -83,30 +92,32 @@ async function azureStreamingExample() {
|
|
|
83
92
|
],
|
|
84
93
|
stream: true,
|
|
85
94
|
|
|
86
|
-
//
|
|
87
|
-
// Note: Nested subscriber structure matches Python middleware implementation
|
|
95
|
+
// Optional metadata for advanced reporting, lineage tracking, and cost allocation
|
|
88
96
|
usageMetadata: {
|
|
89
|
-
// User
|
|
97
|
+
// User identification
|
|
90
98
|
subscriber: {
|
|
91
99
|
id: 'azure-stream-user-789',
|
|
92
100
|
email: 'enterprise@company.com',
|
|
93
101
|
credential: {
|
|
94
|
-
name: '
|
|
95
|
-
value: '
|
|
102
|
+
name: 'api-key-prod',
|
|
103
|
+
value: 'key-mno-345',
|
|
96
104
|
},
|
|
97
105
|
},
|
|
98
106
|
|
|
99
|
-
//
|
|
107
|
+
// Organization & billing
|
|
100
108
|
organizationId: 'enterprise-corp',
|
|
101
|
-
|
|
109
|
+
subscriptionId: 'plan-azure-stream-2024',
|
|
102
110
|
|
|
103
|
-
//
|
|
111
|
+
// Product & task tracking
|
|
112
|
+
productId: 'azure-ai-consultant',
|
|
104
113
|
taskType: 'enterprise-consultation',
|
|
105
|
-
|
|
114
|
+
agent: 'azure-streaming-chat-node',
|
|
115
|
+
|
|
116
|
+
// Session tracking
|
|
117
|
+
traceId: 'azure-stream-' + Date.now(),
|
|
106
118
|
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
responseQualityScore: 0.95,
|
|
119
|
+
// Quality metrics
|
|
120
|
+
responseQualityScore: 0.95, // 0.0-1.0 scale
|
|
110
121
|
},
|
|
111
122
|
});
|
|
112
123
|
|
|
@@ -148,22 +159,32 @@ async function azureStreamingExample() {
|
|
|
148
159
|
'Enterprise document: Integration with Azure Active Directory',
|
|
149
160
|
],
|
|
150
161
|
|
|
151
|
-
//
|
|
152
|
-
// Note: Nested subscriber structure for consistency across language implementations
|
|
162
|
+
// Optional metadata for advanced reporting, lineage tracking, and cost allocation
|
|
153
163
|
usageMetadata: {
|
|
164
|
+
// User identification
|
|
154
165
|
subscriber: {
|
|
155
166
|
id: 'azure-enterprise-processor',
|
|
156
167
|
email: 'processor@enterprise-corp.com',
|
|
157
168
|
credential: {
|
|
158
|
-
name: '
|
|
159
|
-
value: '
|
|
169
|
+
name: 'api-key-prod',
|
|
170
|
+
value: 'key-pqr-678',
|
|
160
171
|
},
|
|
161
172
|
},
|
|
173
|
+
|
|
174
|
+
// Organization & billing
|
|
162
175
|
organizationId: 'enterprise-corp',
|
|
163
|
-
|
|
176
|
+
subscriptionId: 'plan-azure-enterprise-2024',
|
|
177
|
+
|
|
178
|
+
// Product & task tracking
|
|
164
179
|
productId: 'azure-document-intelligence',
|
|
165
|
-
|
|
166
|
-
agent: 'azure-batch-embeddings-
|
|
180
|
+
taskType: 'enterprise-document-processing',
|
|
181
|
+
agent: 'azure-batch-embeddings-node',
|
|
182
|
+
|
|
183
|
+
// Session tracking
|
|
184
|
+
traceId: 'azure-enterprise-' + Date.now(),
|
|
185
|
+
|
|
186
|
+
// Quality metrics
|
|
187
|
+
responseQualityScore: 0.96, // 0.0-1.0 scale
|
|
167
188
|
},
|
|
168
189
|
});
|
|
169
190
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import { initializeReveniumFromEnv, patchOpenAIInstance } from '@revenium/openai';
|
|
3
|
+
import OpenAI from 'openai';
|
|
4
|
+
|
|
5
|
+
async function main() {
|
|
6
|
+
const initResult = initializeReveniumFromEnv();
|
|
7
|
+
if (!initResult.success) {
|
|
8
|
+
console.error('Failed to initialize Revenium:', initResult.message);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const openai = patchOpenAIInstance(new OpenAI());
|
|
13
|
+
|
|
14
|
+
const response = await openai.chat.completions.create({
|
|
15
|
+
model: 'gpt-4o-mini',
|
|
16
|
+
messages: [
|
|
17
|
+
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
18
|
+
{ role: 'user', content: 'Please verify you are ready to assist me.' }
|
|
19
|
+
],
|
|
20
|
+
|
|
21
|
+
/* Optional metadata for advanced reporting, lineage tracking, and cost allocation
|
|
22
|
+
usageMetadata: {
|
|
23
|
+
// User identification
|
|
24
|
+
subscriber: {
|
|
25
|
+
id: 'user-123',
|
|
26
|
+
email: 'user@example.com',
|
|
27
|
+
credential: {
|
|
28
|
+
name: 'api-key-prod',
|
|
29
|
+
value: 'key-abc-123'
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
// Organization & billing
|
|
34
|
+
organizationId: 'my-customers-name',
|
|
35
|
+
subscriptionId: 'plan-enterprise-2024',
|
|
36
|
+
|
|
37
|
+
// Product & task tracking
|
|
38
|
+
productId: 'my-product',
|
|
39
|
+
taskType: 'doc-summary',
|
|
40
|
+
agent: 'customer-support',
|
|
41
|
+
|
|
42
|
+
// Session tracking
|
|
43
|
+
traceId: 'session-' + Date.now(),
|
|
44
|
+
|
|
45
|
+
// Quality metrics
|
|
46
|
+
responseQualityScore: 0.95 // 0.0-1.0 scale
|
|
47
|
+
}
|
|
48
|
+
*/
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
console.log('Response:', response.choices[0]?.message?.content);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
main().catch(console.error);
|
package/examples/openai-basic.ts
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Shows how to use Revenium middleware with OpenAI chat completions and embeddings.
|
|
5
5
|
* Demonstrates seamless metadata integration - all metadata fields are optional!
|
|
6
|
+
*
|
|
7
|
+
* Metadata Options:
|
|
8
|
+
* - Start with basic usage (no metadata) - tracking works automatically
|
|
9
|
+
* - Add subscriber info for user tracking
|
|
10
|
+
* - Include organization/product IDs for business analytics
|
|
11
|
+
* - Use task type and trace ID for detailed analysis
|
|
12
|
+
*
|
|
13
|
+
* For complete metadata field reference, see:
|
|
14
|
+
* https://revenium.readme.io/reference/meter_ai_completion
|
|
6
15
|
*/
|
|
7
16
|
|
|
8
17
|
import 'dotenv/config';
|
|
@@ -45,29 +54,32 @@ async function openaiBasicExample() {
|
|
|
45
54
|
{ role: 'user', content: 'Explain the benefits of using middleware in 2 sentences.' },
|
|
46
55
|
],
|
|
47
56
|
|
|
48
|
-
//
|
|
49
|
-
// Note: Nested subscriber structure matches Python middleware for consistency
|
|
57
|
+
// Optional metadata for advanced reporting, lineage tracking, and cost allocation
|
|
50
58
|
usageMetadata: {
|
|
51
|
-
// User
|
|
59
|
+
// User identification
|
|
52
60
|
subscriber: {
|
|
53
61
|
id: 'user-12345',
|
|
54
62
|
email: 'developer@company.com',
|
|
55
63
|
credential: {
|
|
56
|
-
name: 'api-key',
|
|
57
|
-
value: '
|
|
64
|
+
name: 'api-key-prod',
|
|
65
|
+
value: 'key-abc-123',
|
|
58
66
|
},
|
|
59
67
|
},
|
|
60
68
|
|
|
61
|
-
//
|
|
69
|
+
// Organization & billing
|
|
62
70
|
organizationId: 'my-customer',
|
|
63
|
-
|
|
71
|
+
subscriptionId: 'plan-premium-2024',
|
|
64
72
|
|
|
65
|
-
//
|
|
73
|
+
// Product & task tracking
|
|
74
|
+
productId: 'ai-assistant',
|
|
66
75
|
taskType: 'explanation-request',
|
|
67
|
-
traceId: `session-${Date.now()}`,
|
|
68
|
-
|
|
69
|
-
// Custom fields (optional)
|
|
70
76
|
agent: 'openai-basic-chat-node',
|
|
77
|
+
|
|
78
|
+
// Session tracking
|
|
79
|
+
traceId: 'session-' + Date.now(),
|
|
80
|
+
|
|
81
|
+
// Quality metrics
|
|
82
|
+
responseQualityScore: 0.95, // 0.0-1.0 scale
|
|
71
83
|
},
|
|
72
84
|
});
|
|
73
85
|
|
|
@@ -96,22 +108,32 @@ async function openaiBasicExample() {
|
|
|
96
108
|
model: 'text-embedding-3-small',
|
|
97
109
|
input: 'Advanced text embedding with comprehensive tracking metadata',
|
|
98
110
|
|
|
99
|
-
//
|
|
100
|
-
// Note: Nested subscriber structure for consistency across language implementations
|
|
111
|
+
// Optional metadata for advanced reporting, lineage tracking, and cost allocation
|
|
101
112
|
usageMetadata: {
|
|
113
|
+
// User identification
|
|
102
114
|
subscriber: {
|
|
103
115
|
id: 'embedding-user-789',
|
|
104
116
|
email: 'embeddings@company.com',
|
|
105
117
|
credential: {
|
|
106
|
-
name: '
|
|
107
|
-
value: '
|
|
118
|
+
name: 'api-key-prod',
|
|
119
|
+
value: 'key-def-456',
|
|
108
120
|
},
|
|
109
121
|
},
|
|
122
|
+
|
|
123
|
+
// Organization & billing
|
|
110
124
|
organizationId: 'my-company',
|
|
111
|
-
|
|
125
|
+
subscriptionId: 'plan-enterprise-2024',
|
|
126
|
+
|
|
127
|
+
// Product & task tracking
|
|
112
128
|
productId: 'search-engine',
|
|
113
|
-
|
|
129
|
+
taskType: 'document-embedding',
|
|
114
130
|
agent: 'openai-basic-embeddings-node',
|
|
131
|
+
|
|
132
|
+
// Session tracking
|
|
133
|
+
traceId: 'embed-' + Date.now(),
|
|
134
|
+
|
|
135
|
+
// Quality metrics
|
|
136
|
+
responseQualityScore: 0.98, // 0.0-1.0 scale
|
|
115
137
|
},
|
|
116
138
|
});
|
|
117
139
|
|