@revenium/openai 1.0.13 → 1.0.15

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 (240) hide show
  1. package/.env.example +10 -15
  2. package/CHANGELOG.md +65 -11
  3. package/CODE_OF_CONDUCT.md +57 -0
  4. package/CONTRIBUTING.md +38 -0
  5. package/README.md +104 -216
  6. package/SECURITY.md +34 -0
  7. package/dist/cjs/core/client/index.js +14 -0
  8. package/dist/cjs/core/client/index.js.map +1 -0
  9. package/dist/cjs/core/client/manager.js +109 -0
  10. package/dist/cjs/core/client/manager.js.map +1 -0
  11. package/dist/cjs/core/config/azure-config.js +5 -17
  12. package/dist/cjs/core/config/azure-config.js.map +1 -1
  13. package/dist/cjs/core/config/index.js +2 -2
  14. package/dist/cjs/core/config/index.js.map +1 -1
  15. package/dist/cjs/core/config/loader.js +34 -14
  16. package/dist/cjs/core/config/loader.js.map +1 -1
  17. package/dist/cjs/core/config/manager.js +11 -5
  18. package/dist/cjs/core/config/manager.js.map +1 -1
  19. package/dist/cjs/core/config/validator.js +3 -45
  20. package/dist/cjs/core/config/validator.js.map +1 -1
  21. package/dist/cjs/core/middleware/index.js +21 -0
  22. package/dist/cjs/core/middleware/index.js.map +1 -0
  23. package/dist/cjs/core/middleware/interfaces.js +454 -0
  24. package/dist/cjs/core/middleware/interfaces.js.map +1 -0
  25. package/dist/cjs/core/middleware/revenium-client.js +152 -0
  26. package/dist/cjs/core/middleware/revenium-client.js.map +1 -0
  27. package/dist/cjs/core/providers/detector.js +45 -23
  28. package/dist/cjs/core/providers/detector.js.map +1 -1
  29. package/dist/cjs/core/providers/index.js +2 -1
  30. package/dist/cjs/core/providers/index.js.map +1 -1
  31. package/dist/cjs/core/tracking/api-client.js +21 -14
  32. package/dist/cjs/core/tracking/api-client.js.map +1 -1
  33. package/dist/cjs/core/tracking/index.js +5 -1
  34. package/dist/cjs/core/tracking/index.js.map +1 -1
  35. package/dist/cjs/core/tracking/payload-builder.js +143 -25
  36. package/dist/cjs/core/tracking/payload-builder.js.map +1 -1
  37. package/dist/cjs/core/tracking/usage-tracker.js +111 -18
  38. package/dist/cjs/core/tracking/usage-tracker.js.map +1 -1
  39. package/dist/cjs/index.js +39 -202
  40. package/dist/cjs/index.js.map +1 -1
  41. package/dist/cjs/types/index.js +0 -8
  42. package/dist/cjs/types/index.js.map +1 -1
  43. package/dist/cjs/types/openai-augmentation.js +0 -49
  44. package/dist/cjs/types/openai-augmentation.js.map +1 -1
  45. package/dist/cjs/utils/constants.js +17 -20
  46. package/dist/cjs/utils/constants.js.map +1 -1
  47. package/dist/cjs/utils/error-handler.js +18 -14
  48. package/dist/cjs/utils/error-handler.js.map +1 -1
  49. package/dist/cjs/utils/metadata-builder.js +17 -16
  50. package/dist/cjs/utils/metadata-builder.js.map +1 -1
  51. package/dist/cjs/utils/provider-detection.js +25 -28
  52. package/dist/cjs/utils/provider-detection.js.map +1 -1
  53. package/dist/cjs/utils/trace-fields.js +115 -0
  54. package/dist/cjs/utils/trace-fields.js.map +1 -0
  55. package/dist/esm/core/client/index.js +6 -0
  56. package/dist/esm/core/client/index.js.map +1 -0
  57. package/dist/esm/core/client/manager.js +102 -0
  58. package/dist/esm/core/client/manager.js.map +1 -0
  59. package/dist/esm/core/config/azure-config.js +6 -18
  60. package/dist/esm/core/config/azure-config.js.map +1 -1
  61. package/dist/esm/core/config/index.js +5 -4
  62. package/dist/esm/core/config/index.js.map +1 -1
  63. package/dist/esm/core/config/loader.js +33 -13
  64. package/dist/esm/core/config/loader.js.map +1 -1
  65. package/dist/esm/core/config/manager.js +13 -7
  66. package/dist/esm/core/config/manager.js.map +1 -1
  67. package/dist/esm/core/config/validator.js +3 -44
  68. package/dist/esm/core/config/validator.js.map +1 -1
  69. package/dist/esm/core/middleware/index.js +8 -0
  70. package/dist/esm/core/middleware/index.js.map +1 -0
  71. package/dist/esm/core/middleware/interfaces.js +442 -0
  72. package/dist/esm/core/middleware/interfaces.js.map +1 -0
  73. package/dist/esm/core/middleware/revenium-client.js +115 -0
  74. package/dist/esm/core/middleware/revenium-client.js.map +1 -0
  75. package/dist/esm/core/providers/detector.js +43 -22
  76. package/dist/esm/core/providers/detector.js.map +1 -1
  77. package/dist/esm/core/providers/index.js +2 -2
  78. package/dist/esm/core/providers/index.js.map +1 -1
  79. package/dist/esm/core/tracking/api-client.js +20 -13
  80. package/dist/esm/core/tracking/api-client.js.map +1 -1
  81. package/dist/esm/core/tracking/index.js +4 -4
  82. package/dist/esm/core/tracking/index.js.map +1 -1
  83. package/dist/esm/core/tracking/payload-builder.js +142 -26
  84. package/dist/esm/core/tracking/payload-builder.js.map +1 -1
  85. package/dist/esm/core/tracking/usage-tracker.js +78 -20
  86. package/dist/esm/core/tracking/usage-tracker.js.map +1 -1
  87. package/dist/esm/index.js +9 -177
  88. package/dist/esm/index.js.map +1 -1
  89. package/dist/esm/types/index.js +2 -10
  90. package/dist/esm/types/index.js.map +1 -1
  91. package/dist/esm/types/openai-augmentation.js +0 -49
  92. package/dist/esm/types/openai-augmentation.js.map +1 -1
  93. package/dist/esm/utils/constants.js +16 -19
  94. package/dist/esm/utils/constants.js.map +1 -1
  95. package/dist/esm/utils/error-handler.js +19 -15
  96. package/dist/esm/utils/error-handler.js.map +1 -1
  97. package/dist/esm/utils/metadata-builder.js +17 -16
  98. package/dist/esm/utils/metadata-builder.js.map +1 -1
  99. package/dist/esm/utils/provider-detection.js +26 -29
  100. package/dist/esm/utils/provider-detection.js.map +1 -1
  101. package/dist/esm/utils/trace-fields.js +100 -0
  102. package/dist/esm/utils/trace-fields.js.map +1 -0
  103. package/dist/types/core/client/index.d.ts +6 -0
  104. package/dist/types/core/client/index.d.ts.map +1 -0
  105. package/dist/types/core/client/manager.d.ts +32 -0
  106. package/dist/types/core/client/manager.d.ts.map +1 -0
  107. package/dist/types/core/config/azure-config.d.ts +2 -2
  108. package/dist/types/core/config/azure-config.d.ts.map +1 -1
  109. package/dist/types/core/config/index.d.ts +4 -4
  110. package/dist/types/core/config/index.d.ts.map +1 -1
  111. package/dist/types/core/config/loader.d.ts +3 -1
  112. package/dist/types/core/config/loader.d.ts.map +1 -1
  113. package/dist/types/core/config/manager.d.ts +1 -1
  114. package/dist/types/core/config/manager.d.ts.map +1 -1
  115. package/dist/types/core/config/validator.d.ts +1 -12
  116. package/dist/types/core/config/validator.d.ts.map +1 -1
  117. package/dist/types/core/middleware/index.d.ts +8 -0
  118. package/dist/types/core/middleware/index.d.ts.map +1 -0
  119. package/dist/types/core/middleware/interfaces.d.ts +104 -0
  120. package/dist/types/core/middleware/interfaces.d.ts.map +1 -0
  121. package/dist/types/core/middleware/revenium-client.d.ts +64 -0
  122. package/dist/types/core/middleware/revenium-client.d.ts.map +1 -0
  123. package/dist/types/core/providers/detector.d.ts +9 -2
  124. package/dist/types/core/providers/detector.d.ts.map +1 -1
  125. package/dist/types/core/providers/index.d.ts +2 -2
  126. package/dist/types/core/providers/index.d.ts.map +1 -1
  127. package/dist/types/core/tracking/api-client.d.ts +1 -1
  128. package/dist/types/core/tracking/api-client.d.ts.map +1 -1
  129. package/dist/types/core/tracking/index.d.ts +4 -4
  130. package/dist/types/core/tracking/index.d.ts.map +1 -1
  131. package/dist/types/core/tracking/payload-builder.d.ts +5 -3
  132. package/dist/types/core/tracking/payload-builder.d.ts.map +1 -1
  133. package/dist/types/core/tracking/usage-tracker.d.ts +4 -2
  134. package/dist/types/core/tracking/usage-tracker.d.ts.map +1 -1
  135. package/dist/types/index.d.ts +11 -135
  136. package/dist/types/index.d.ts.map +1 -1
  137. package/dist/types/types/function-parameters.d.ts +91 -23
  138. package/dist/types/types/function-parameters.d.ts.map +1 -1
  139. package/dist/types/types/index.d.ts +53 -108
  140. package/dist/types/types/index.d.ts.map +1 -1
  141. package/dist/types/types/openai-augmentation.d.ts +4 -138
  142. package/dist/types/types/openai-augmentation.d.ts.map +1 -1
  143. package/dist/types/utils/constants.d.ts +7 -1
  144. package/dist/types/utils/constants.d.ts.map +1 -1
  145. package/dist/types/utils/error-handler.d.ts +2 -2
  146. package/dist/types/utils/error-handler.d.ts.map +1 -1
  147. package/dist/types/utils/metadata-builder.d.ts +2 -2
  148. package/dist/types/utils/metadata-builder.d.ts.map +1 -1
  149. package/dist/types/utils/provider-detection.d.ts +3 -3
  150. package/dist/types/utils/provider-detection.d.ts.map +1 -1
  151. package/dist/types/utils/trace-fields.d.ts +11 -0
  152. package/dist/types/utils/trace-fields.d.ts.map +1 -0
  153. package/examples/README.md +282 -198
  154. package/examples/azure/basic.ts +62 -0
  155. package/examples/azure/responses-basic.ts +45 -0
  156. package/examples/azure/responses-stream.ts +61 -0
  157. package/examples/azure/stream.ts +56 -0
  158. package/examples/getting_started.ts +31 -43
  159. package/examples/openai/basic.ts +45 -0
  160. package/examples/openai/metadata.ts +67 -0
  161. package/examples/openai/responses-basic.ts +44 -0
  162. package/examples/openai/responses-embed.ts +34 -0
  163. package/examples/openai/responses-streaming.ts +63 -0
  164. package/examples/openai/streaming.ts +59 -0
  165. package/package.json +23 -13
  166. package/dist/cjs/core/wrapper/index.js +0 -15
  167. package/dist/cjs/core/wrapper/index.js.map +0 -1
  168. package/dist/cjs/core/wrapper/instance-patcher.js +0 -202
  169. package/dist/cjs/core/wrapper/instance-patcher.js.map +0 -1
  170. package/dist/cjs/core/wrapper/request-handler.js +0 -317
  171. package/dist/cjs/core/wrapper/request-handler.js.map +0 -1
  172. package/dist/cjs/core/wrapper/stream-wrapper.js +0 -82
  173. package/dist/cjs/core/wrapper/stream-wrapper.js.map +0 -1
  174. package/dist/cjs/utils/azure-model-resolver.js +0 -211
  175. package/dist/cjs/utils/azure-model-resolver.js.map +0 -1
  176. package/dist/cjs/utils/request-handler-factory.js +0 -185
  177. package/dist/cjs/utils/request-handler-factory.js.map +0 -1
  178. package/dist/esm/core/wrapper/index.js +0 -9
  179. package/dist/esm/core/wrapper/index.js.map +0 -1
  180. package/dist/esm/core/wrapper/instance-patcher.js +0 -199
  181. package/dist/esm/core/wrapper/instance-patcher.js.map +0 -1
  182. package/dist/esm/core/wrapper/request-handler.js +0 -310
  183. package/dist/esm/core/wrapper/request-handler.js.map +0 -1
  184. package/dist/esm/core/wrapper/stream-wrapper.js +0 -79
  185. package/dist/esm/core/wrapper/stream-wrapper.js.map +0 -1
  186. package/dist/esm/utils/azure-model-resolver.js +0 -204
  187. package/dist/esm/utils/azure-model-resolver.js.map +0 -1
  188. package/dist/esm/utils/request-handler-factory.js +0 -146
  189. package/dist/esm/utils/request-handler-factory.js.map +0 -1
  190. package/dist/types/core/wrapper/index.d.ts +0 -8
  191. package/dist/types/core/wrapper/index.d.ts.map +0 -1
  192. package/dist/types/core/wrapper/instance-patcher.d.ts +0 -33
  193. package/dist/types/core/wrapper/instance-patcher.d.ts.map +0 -1
  194. package/dist/types/core/wrapper/request-handler.d.ts +0 -29
  195. package/dist/types/core/wrapper/request-handler.d.ts.map +0 -1
  196. package/dist/types/core/wrapper/stream-wrapper.d.ts +0 -13
  197. package/dist/types/core/wrapper/stream-wrapper.d.ts.map +0 -1
  198. package/dist/types/utils/azure-model-resolver.d.ts +0 -41
  199. package/dist/types/utils/azure-model-resolver.d.ts.map +0 -1
  200. package/dist/types/utils/request-handler-factory.d.ts +0 -81
  201. package/dist/types/utils/request-handler-factory.d.ts.map +0 -1
  202. package/examples/azure-basic.ts +0 -206
  203. package/examples/azure-responses-basic.ts +0 -233
  204. package/examples/azure-responses-streaming.ts +0 -255
  205. package/examples/azure-streaming.ts +0 -209
  206. package/examples/openai-basic.ts +0 -147
  207. package/examples/openai-function-calling.ts +0 -259
  208. package/examples/openai-responses-basic.ts +0 -212
  209. package/examples/openai-responses-streaming.ts +0 -232
  210. package/examples/openai-streaming.ts +0 -172
  211. package/examples/openai-vision.ts +0 -289
  212. package/src/core/config/azure-config.ts +0 -72
  213. package/src/core/config/index.ts +0 -23
  214. package/src/core/config/loader.ts +0 -66
  215. package/src/core/config/manager.ts +0 -95
  216. package/src/core/config/validator.ts +0 -89
  217. package/src/core/providers/detector.ts +0 -159
  218. package/src/core/providers/index.ts +0 -16
  219. package/src/core/tracking/api-client.ts +0 -78
  220. package/src/core/tracking/index.ts +0 -21
  221. package/src/core/tracking/payload-builder.ts +0 -137
  222. package/src/core/tracking/usage-tracker.ts +0 -189
  223. package/src/core/wrapper/index.ts +0 -9
  224. package/src/core/wrapper/instance-patcher.ts +0 -288
  225. package/src/core/wrapper/request-handler.ts +0 -423
  226. package/src/core/wrapper/stream-wrapper.ts +0 -100
  227. package/src/index.ts +0 -360
  228. package/src/types/function-parameters.ts +0 -251
  229. package/src/types/index.ts +0 -310
  230. package/src/types/openai-augmentation.ts +0 -232
  231. package/src/types/responses-api.ts +0 -308
  232. package/src/utils/azure-model-resolver.ts +0 -220
  233. package/src/utils/constants.ts +0 -21
  234. package/src/utils/error-handler.ts +0 -251
  235. package/src/utils/metadata-builder.ts +0 -228
  236. package/src/utils/provider-detection.ts +0 -257
  237. package/src/utils/request-handler-factory.ts +0 -285
  238. package/src/utils/stop-reason-mapper.ts +0 -78
  239. package/src/utils/type-guards.ts +0 -202
  240. package/src/utils/url-builder.ts +0 -68
package/README.md CHANGED
@@ -8,18 +8,21 @@
8
8
 
9
9
  **Transparent TypeScript middleware for automatic Revenium usage tracking with OpenAI**
10
10
 
11
- A professional-grade Node.js middleware that seamlessly integrates with OpenAI and Azure OpenAI to provide automatic usage tracking, billing analytics, and comprehensive metadata collection. Features native TypeScript support with zero type casting required and supports both traditional Chat Completions API and the new Responses API.
11
+ A professional-grade Node.js middleware that seamlessly integrates with OpenAI and Azure OpenAI to provide automatic usage tracking, billing analytics, and comprehensive metadata collection. Features native TypeScript support with zero type casting required and supports both Chat Completions API, Embeddings API, and Responses API.
12
+
13
+ **Go-aligned API for consistent cross-language development!**
12
14
 
13
15
  ## Features
14
16
 
17
+ - **Go-Aligned API** - Same `Initialize()`/`GetClient()` pattern as Go implementation
15
18
  - **Seamless Integration** - Native TypeScript support, no type casting required
16
- - **Optional Metadata** - Track users, organizations, and business context (12 predefined fields, all optional)
17
- - **Dual API Support** - Chat Completions API + Responses API
19
+ - **Optional Metadata** - Track users, organizations, and business context (all fields optional)
20
+ - **Multiple API Support** - Chat Completions, Embeddings, and Responses API
18
21
  - **Azure OpenAI Support** - Full Azure OpenAI integration with automatic detection
19
22
  - **Type Safety** - Complete TypeScript support with IntelliSense
20
23
  - **Streaming Support** - Handles regular and streaming requests seamlessly
21
24
  - **Fire-and-Forget** - Never blocks your application flow
22
- - **Zero Configuration** - Auto-initialization from environment variables
25
+ - **Automatic .env Loading** - Loads environment variables automatically
23
26
 
24
27
  ## Getting Started
25
28
 
@@ -40,35 +43,21 @@ npm install --save-dev typescript @types/node
40
43
 
41
44
  ### 2. Configure Environment Variables
42
45
 
43
- Create a `.env` file:
46
+ Create a `.env` file in your project root. See [`.env.example`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/.env.example) for all available configuration options.
44
47
 
45
- **NOTE: YOU MUST REPLACE THE PLACEHOLDERS WITH YOUR OWN API KEYS**
48
+ **Minimum required configuration:**
46
49
 
47
50
  ```env
48
- REVENIUM_METERING_BASE_URL=https://api.revenium.ai
49
51
  REVENIUM_METERING_API_KEY=hak_your_revenium_api_key_here
52
+ REVENIUM_METERING_BASE_URL=https://api.revenium.ai
50
53
  OPENAI_API_KEY=sk_your_openai_api_key_here
51
54
  ```
52
55
 
53
- ### 3. Run Your First Example
54
-
55
- Run the [getting started example](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/getting_started.ts):
56
-
57
- ```bash
58
- npx tsx node_modules/@revenium/openai/examples/getting_started.ts
59
- ```
60
-
61
- Or with debug logging:
62
-
63
- ```bash
64
- # Linux/macOS
65
- REVENIUM_DEBUG=true npx tsx node_modules/@revenium/openai/examples/getting_started.ts
56
+ **NOTE: Replace the placeholder values with your actual API keys.**
66
57
 
67
- # Windows (PowerShell)
68
- $env:REVENIUM_DEBUG="true"; npx tsx node_modules/@revenium/openai/examples/getting_started.ts
69
- ```
58
+ ### 3. Run Your First Example
70
59
 
71
- **For more examples and usage patterns, see [examples/README.md](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/README.md).**
60
+ **For complete examples and usage patterns, see [`examples/README.md`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/README.md).**
72
61
 
73
62
  ---
74
63
 
@@ -105,250 +94,152 @@ The middleware automatically captures comprehensive usage data:
105
94
  - **Error Tracking** - Failed requests, error types, retry attempts
106
95
  - **Environment Info** - Development vs production usage
107
96
 
108
- ## Advanced Usage
109
-
110
- ### Initialization Options
111
-
112
- The middleware supports three initialization patterns:
113
-
114
- **Automatic (Recommended)** - Import and patch OpenAI instance:
115
-
116
- ```typescript
117
- import { patchOpenAIInstance } from '@revenium/openai';
118
- import OpenAI from 'openai';
119
-
120
- const openai = patchOpenAIInstance(new OpenAI());
121
- // Tracking works automatically if env vars are set
122
- ```
123
-
124
- **Explicit** - Call `initializeReveniumFromEnv()` for error handling control:
125
-
126
- ```typescript
127
- import { initializeReveniumFromEnv, patchOpenAIInstance } from '@revenium/openai';
128
- import OpenAI from 'openai';
129
-
130
- const result = initializeReveniumFromEnv();
131
- if (!result.success) {
132
- console.error('Failed to initialize:', result.message);
133
- process.exit(1);
134
- }
135
-
136
- const openai = patchOpenAIInstance(new OpenAI());
137
- ```
138
-
139
- **Manual** - Use `configure()` to set all options programmatically (see Manual Configuration below).
140
-
141
- For detailed examples of all initialization patterns, see [`examples/`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/README.md).
142
-
143
- ### Streaming Responses
144
-
145
- Streaming is fully supported with real-time token tracking. The middleware automatically tracks streaming responses without any additional configuration.
146
-
147
- See [`examples/openai-streaming.ts`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/openai-streaming.ts) and [`examples/azure-streaming.ts`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/azure-streaming.ts) for working streaming examples.
148
-
149
- ### Custom Metadata Tracking
150
-
151
- Add business context to track usage by organization, user, task type, or custom identifiers. Pass a `usageMetadata` object with any of these optional fields:
152
-
153
- | Field | Description | Use Case |
154
- |-------|-------------|----------|
155
- | `traceId` | Unique identifier for session or conversation tracking | Link multiple API calls together for debugging, user session analytics, or distributed tracing across services |
156
- | `taskType` | Type of AI task being performed | Categorize usage by workload (e.g., "chat", "code-generation", "doc-summary") for cost analysis and optimization |
157
- | `subscriber.id` | Unique user identifier | Track individual user consumption for billing, rate limiting, or user analytics |
158
- | `subscriber.email` | User email address | Identify users for support, compliance, or usage reports |
159
- | `subscriber.credential.name` | Authentication credential name | Track which API key or service account made the request |
160
- | `subscriber.credential.value` | Authentication credential value | Associate usage with specific credentials for security auditing |
161
- | `organizationId` | Organization or company identifier | Multi-tenant cost allocation, usage quotas per organization |
162
- | `subscriptionId` | Subscription plan identifier | Track usage against subscription limits, identify plan upgrade opportunities |
163
- | `productId` | Your product or feature identifier | Attribute AI costs to specific features in your application (e.g., "chatbot", "email-assistant") |
164
- | `agent` | AI agent or bot identifier | Distinguish between multiple AI agents or automation workflows in your system |
165
- | `responseQualityScore` | Custom quality rating (0.0-1.0) | Track user satisfaction or automated quality metrics for model performance analysis |
97
+ ## API Overview
166
98
 
167
- **Resources:**
168
- - [API Reference](https://revenium.readme.io/reference/meter_ai_completion) - Complete metadata field documentation
99
+ The middleware provides a Go-aligned API with the following main functions:
169
100
 
170
- ### OpenAI Responses API
171
- **Use case:** Using OpenAI's Responses API with string inputs and simplified interface.
101
+ - **`Initialize(config?)`** - Initialize the middleware (from environment or explicit config)
102
+ - **`GetClient()`** - Get the global Revenium client instance
103
+ - **`Configure(config)`** - Alias for `Initialize()` for programmatic configuration
104
+ - **`IsInitialized()`** - Check if the middleware is initialized
105
+ - **`Reset()`** - Reset the global client (useful for testing)
172
106
 
173
- See working examples:
174
- - `examples/openai-responses-basic.ts` - Basic Responses API usage
175
- - `examples/openai-responses-streaming.ts` - Streaming with Responses API
107
+ **For complete API documentation and usage examples, see [`examples/README.md`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/README.md).**
176
108
 
177
- ### Azure OpenAI Integration
178
- **Use case:** Automatic Azure OpenAI detection with deployment name resolution and accurate pricing.
109
+ ## Metadata Fields
179
110
 
180
- See working examples:
181
- - `examples/azure-basic.ts` - Azure chat completions and embeddings
182
- - `examples/azure-responses-basic.ts` - Azure Responses API integration
111
+ The middleware supports the following optional metadata fields for tracking:
183
112
 
184
- ### Embeddings with Metadata
185
- **Use case:** Track embeddings usage for search engines, RAG systems, and document processing.
113
+ | Field | Type | Description |
114
+ | ----------------------- | ------ | ----------------------------------------------------------- |
115
+ | `traceId` | string | Unique identifier for session or conversation tracking |
116
+ | `taskType` | string | Type of AI task being performed (e.g., "chat", "embedding") |
117
+ | `agent` | string | AI agent or bot identifier |
118
+ | `organizationId` | string | Organization or company identifier |
119
+ | `productId` | string | Your product or feature identifier |
120
+ | `subscriptionId` | string | Subscription plan identifier |
121
+ | `responseQualityScore` | number | Custom quality rating (0.0-1.0) |
122
+ | `subscriber.id` | string | Unique user identifier |
123
+ | `subscriber.email` | string | User email address |
124
+ | `subscriber.credential` | object | Authentication credential (`name` and `value` fields) |
186
125
 
187
- Embeddings examples are included in:
188
- - `examples/openai-basic.ts` - Text embeddings with metadata
189
- - `examples/openai-streaming.ts` - Batch embeddings processing
126
+ **All metadata fields are optional.** For complete metadata documentation and usage examples, see:
190
127
 
191
- ### Manual Configuration
192
-
193
- For advanced use cases, configure the middleware manually:
194
-
195
- ```typescript
196
- import { configure, patchOpenAIInstance } from '@revenium/openai';
197
- import OpenAI from 'openai';
198
-
199
- configure({
200
- reveniumApiKey: 'hak_your_api_key',
201
- reveniumBaseUrl: 'https://api.revenium.ai',
202
- debug: true,
203
- });
204
-
205
- const openai = patchOpenAIInstance(new OpenAI());
206
- ```
128
+ - [`examples/README.md`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/README.md) - All usage examples
129
+ - [Revenium API Reference](https://revenium.readme.io/reference/meter_ai_completion) - Complete API documentation
207
130
 
208
131
  ## Configuration Options
209
132
 
210
133
  ### Environment Variables
211
134
 
212
- | Variable | Required | Default | Description |
213
- | ------------------------------ | -------- | ------------------------------- | ---------------------------------------------- |
214
- | `REVENIUM_METERING_API_KEY` | true | - | Your Revenium API key (starts with `hak_`) |
215
- | `OPENAI_API_KEY` | true | - | Your OpenAI API key (starts with `sk-`) |
216
- | `REVENIUM_METERING_BASE_URL` | false | `https://api.revenium.ai` | Revenium metering API base URL |
217
- | `REVENIUM_DEBUG` | false | `false` | Enable debug logging (`true`/`false`) |
218
- | `AZURE_OPENAI_ENDPOINT` | false | - | Azure OpenAI endpoint URL (for Azure testing) |
219
- | `AZURE_OPENAI_API_KEY` | false | - | Azure OpenAI API key (for Azure testing) |
220
- | `AZURE_OPENAI_DEPLOYMENT` | false | - | Azure OpenAI deployment name (for Azure) |
221
- | `AZURE_OPENAI_API_VERSION` | false | `2024-12-01-preview` | Azure OpenAI API version (for Azure) |
135
+ For a complete list of all available environment variables with examples, see [`.env.example`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/.env.example).
222
136
 
223
- **Important Note about `REVENIUM_METERING_BASE_URL`:**
137
+ ## Examples
224
138
 
225
- - This variable is **optional** and defaults to the production URL (`https://api.revenium.ai`)
226
- - If you don't set it explicitly, the middleware will use the default production endpoint
227
- - However, you may see console warnings or errors if the middleware cannot determine the correct environment
228
- - **Best practice:** Always set this variable explicitly to match your environment:
139
+ The package includes comprehensive examples in the [`examples/`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/) directory.
229
140
 
230
- ```bash
231
- # Default production URL (recommended)
232
- REVENIUM_METERING_BASE_URL=https://api.revenium.ai
233
- ```
141
+ ### Getting Started
234
142
 
235
- - **Remember:** Your `REVENIUM_METERING_API_KEY` must match your base URL environment
143
+ ```bash
144
+ npm run example:getting-started
145
+ ```
236
146
 
237
- ## Included Examples
147
+ ### OpenAI Examples
238
148
 
239
- The package includes comprehensive example files covering:
149
+ | Example | Command | Description |
150
+ | ------------------------------- | ----------------------------------- | --------------------------------- |
151
+ | `openai/basic.ts` | `npm run example:openai-basic` | Chat completions and embeddings |
152
+ | `openai/metadata.ts` | `npm run example:openai-metadata` | All metadata fields demonstration |
153
+ | `openai/streaming.ts` | `npm run example:openai-stream` | Streaming chat completions |
154
+ | `openai/responses-basic.ts` | `npm run example:openai-res-basic` | Responses API usage |
155
+ | `openai/responses-embed.ts` | `npm run example:openai-res-embed` | Embeddings with Responses API |
156
+ | `openai/responses-streaming.ts` | `npm run example:openai-res-stream` | Streaming Responses API |
240
157
 
241
- - **Getting Started** - Simple entry point with all metadata fields documented
242
- - **Chat Completions** - Basic and streaming usage patterns
243
- - **Responses API** - OpenAI's new API with simplified interface
244
- - **Azure OpenAI** - Automatic Azure detection and integration
245
- - **Embeddings** - Text embedding generation with tracking
158
+ ### Azure OpenAI Examples
246
159
 
247
- Run the getting started example:
248
- ```bash
249
- npx tsx node_modules/@revenium/openai/examples/getting_started.ts
250
- ```
160
+ | Example | Command | Description |
161
+ | --------------------------- | ---------------------------------- | ----------------------------- |
162
+ | `azure/basic.ts` | `npm run example:azure-basic` | Azure chat completions |
163
+ | `azure/stream.ts` | `npm run example:azure-stream` | Azure streaming |
164
+ | `azure/responses-basic.ts` | `npm run example:azure-res-basic` | Azure Responses API |
165
+ | `azure/responses-stream.ts` | `npm run example:azure-res-stream` | Azure Responses API streaming |
251
166
 
252
- For complete example documentation, setup instructions, and all available examples, see [examples/README.md](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/README.md).
167
+ **For complete example documentation, setup instructions, and usage patterns, see [`examples/README.md`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/README.md).**
253
168
 
254
169
  ## How It Works
255
170
 
256
- 1. **Automatic Patching**: When imported, the middleware patches OpenAI's methods:
257
- - `chat.completions.create` (Chat Completions API)
258
- - `responses.create` (Responses API - when available)
259
- - `embeddings.create` (Embeddings API)
260
- 2. **Request Interception**: All OpenAI requests are intercepted to extract metadata
261
- 3. **Usage Extraction**: Token counts, model info, and timing data are captured
171
+ 1. **Initialize**: Call `Initialize()` to set up the middleware with your configuration
172
+ 2. **Get Client**: Call `GetClient()` to get a wrapped OpenAI client instance
173
+ 3. **Make Requests**: Use the client normally - all requests are automatically tracked
262
174
  4. **Async Tracking**: Usage data is sent to Revenium in the background (fire-and-forget)
263
175
  5. **Transparent Response**: Original OpenAI responses are returned unchanged
264
176
 
265
177
  The middleware never blocks your application - if Revenium tracking fails, your OpenAI requests continue normally.
266
178
 
267
- ## Troubleshooting
268
-
269
- ### Common Issues
270
-
271
- #### No tracking data appears
272
-
273
- Ensure environment variables are set and enable debug logging:
179
+ **Supported APIs:**
274
180
 
275
- ```bash
276
- export REVENIUM_METERING_API_KEY="hak_your_key"
277
- export OPENAI_API_KEY="sk_your_key"
278
- export REVENIUM_DEBUG=true
279
- ```
181
+ - Chat Completions API (`client.chat().completions().create()`)
182
+ - Embeddings API (`client.embeddings().create()`)
183
+ - Responses API (`client.responses().create()` and `client.responses().createStreaming()`)
280
184
 
281
- Look for these log messages:
282
- ```
283
- [Revenium Debug] OpenAI chat.completions.create intercepted
284
- [Revenium Debug] Revenium tracking successful
285
- ```
185
+ ## Troubleshooting
286
186
 
287
- #### TypeScript errors with usageMetadata
187
+ ### Common Issues
288
188
 
289
- Import the middleware before OpenAI to enable type augmentation:
189
+ **No tracking data appears:**
290
190
 
291
- ```typescript
292
- import { initializeReveniumFromEnv, patchOpenAIInstance } from '@revenium/openai';
293
- import OpenAI from 'openai';
294
- ```
191
+ 1. Verify environment variables are set correctly in `.env`
192
+ 2. Enable debug logging by setting `REVENIUM_DEBUG=true` in `.env`
193
+ 3. Check console for `[Revenium]` log messages
194
+ 4. Verify your `REVENIUM_METERING_API_KEY` is valid
295
195
 
296
- #### Azure OpenAI not tracking
196
+ **Client not initialized error:**
297
197
 
298
- Ensure you patch the Azure client:
198
+ - Make sure you call `Initialize()` before `GetClient()`
199
+ - Check that your `.env` file is in the project root
200
+ - Verify `REVENIUM_METERING_API_KEY` is set
299
201
 
300
- ```typescript
301
- import { AzureOpenAI } from 'openai';
302
- import { patchOpenAIInstance } from '@revenium/openai';
202
+ **Azure OpenAI not working:**
303
203
 
304
- const azure = patchOpenAIInstance(new AzureOpenAI({...}));
305
- ```
204
+ - Verify all Azure environment variables are set (see `.env.example`)
205
+ - Check that `AZURE_OPENAI_ENDPOINT` and `AZURE_OPENAI_API_KEY` are correct
206
+ - Ensure you're using a valid deployment name in the `model` parameter
306
207
 
307
208
  ### Debug Mode
308
209
 
309
- Enable detailed logging:
210
+ Enable detailed logging by adding to your `.env`:
310
211
 
311
- ```bash
312
- export REVENIUM_DEBUG=true
212
+ ```env
213
+ REVENIUM_DEBUG=true
313
214
  ```
314
215
 
315
216
  ### Getting Help
316
217
 
317
218
  If issues persist:
318
219
 
319
- 1. Check logs with `REVENIUM_DEBUG=true`
320
- 2. Verify environment variables are set
321
- 3. Test with `examples/getting_started.ts`
220
+ 1. Enable debug logging (`REVENIUM_DEBUG=true`)
221
+ 2. Check the [`examples/`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/) directory for working examples
222
+ 3. Review [`examples/README.md`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/README.md) for detailed setup instructions
322
223
  4. Contact support@revenium.io with debug logs
323
224
 
324
225
  ## Supported Models
325
226
 
326
- This middleware works with any OpenAI model. Examples in this package include:
227
+ This middleware works with any OpenAI model. For the complete model list, see the [OpenAI Models Documentation](https://platform.openai.com/docs/models).
327
228
 
328
- **Chat Completions:**
329
- - `gpt-4o-mini`, `gpt-4o` (GPT-4 family)
330
- - `gpt-5`, `gpt-5-mini`, `gpt-5-nano` (GPT-5 family)
331
-
332
- **Embeddings:**
333
- - `text-embedding-3-small`, `text-embedding-3-large`
334
-
335
- **Azure OpenAI:**
336
- - Works with any Azure deployment (deployment names automatically resolved)
229
+ ### API Support Matrix
337
230
 
338
- For the complete model list and latest specifications, see the [OpenAI Models Documentation](https://platform.openai.com/docs/models).
231
+ The following table shows what has been tested and verified with working examples:
339
232
 
340
- For cost tracking across providers, see the [Revenium Model Catalog](https://revenium.readme.io/v2.0.0/reference/get_ai_model).
233
+ | Feature | Chat Completions | Embeddings | Responses API |
234
+ | --------------------- | ---------------- | ---------- | ------------- |
235
+ | **OpenAI Basic** | Yes | Yes | Yes |
236
+ | **OpenAI Streaming** | Yes | No | Yes |
237
+ | **Azure Basic** | Yes | No | Yes |
238
+ | **Azure Streaming** | Yes | No | Yes |
239
+ | **Metadata Tracking** | Yes | Yes | Yes |
240
+ | **Token Counting** | Yes | Yes | Yes |
341
241
 
342
- ### API Support Matrix
343
-
344
- | Feature | Chat Completions API | Responses API | Embeddings API |
345
- | --------------------- | -------------------- | ------------- | -------------- |
346
- | **Basic Requests** | Yes | Yes | Yes |
347
- | **Streaming** | Yes | Yes | No |
348
- | **Metadata Tracking** | Yes | Yes | Yes |
349
- | **Azure OpenAI** | Yes | Yes | Yes |
350
- | **Cost Calculation** | Yes | Yes | Yes |
351
- | **Token Counting** | Yes | Yes | Yes |
242
+ **Note:** "Yes" = Tested with working examples in [`examples/`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/) directory
352
243
 
353
244
  ## Documentation
354
245
 
@@ -374,14 +265,11 @@ This project is licensed under the MIT License - see the [LICENSE](https://githu
374
265
 
375
266
  For issues, feature requests, or contributions:
376
267
 
268
+ - **Website**: [www.revenium.ai](https://www.revenium.ai)
377
269
  - **GitHub Repository**: [revenium/revenium-middleware-openai-node](https://github.com/revenium/revenium-middleware-openai-node)
378
270
  - **Issues**: [Report bugs or request features](https://github.com/revenium/revenium-middleware-openai-node/issues)
379
271
  - **Documentation**: [docs.revenium.io](https://docs.revenium.io)
380
- - **Contact**: Reach out to the Revenium team for additional support
381
-
382
- ## Development
383
-
384
- For development and testing instructions, see [DEVELOPMENT.md](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/DEVELOPMENT.md).
272
+ - **Email**: support@revenium.io
385
273
 
386
274
  ---
387
275
 
package/SECURITY.md ADDED
@@ -0,0 +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)
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ /**
3
+ * Client Module
4
+ * Exports client management functions.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.Configure = exports.Reset = exports.IsInitialized = exports.GetClient = exports.Initialize = void 0;
8
+ var manager_js_1 = require("./manager.js");
9
+ Object.defineProperty(exports, "Initialize", { enumerable: true, get: function () { return manager_js_1.Initialize; } });
10
+ Object.defineProperty(exports, "GetClient", { enumerable: true, get: function () { return manager_js_1.GetClient; } });
11
+ Object.defineProperty(exports, "IsInitialized", { enumerable: true, get: function () { return manager_js_1.IsInitialized; } });
12
+ Object.defineProperty(exports, "Reset", { enumerable: true, get: function () { return manager_js_1.Reset; } });
13
+ Object.defineProperty(exports, "Configure", { enumerable: true, get: function () { return manager_js_1.Configure; } });
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/client/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2CAMsB;AALpB,wGAAA,UAAU,OAAA;AACV,uGAAA,SAAS,OAAA;AACT,2GAAA,aAAa,OAAA;AACb,mGAAA,KAAK,OAAA;AACL,uGAAA,SAAS,OAAA"}
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ /**
3
+ * Client Manager
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Initialize = Initialize;
7
+ exports.GetClient = GetClient;
8
+ exports.IsInitialized = IsInitialized;
9
+ exports.Reset = Reset;
10
+ exports.Configure = Configure;
11
+ const revenium_client_js_1 = require("../middleware/revenium-client.js");
12
+ const config_1 = require("../config");
13
+ const providers_1 = require("../providers");
14
+ const config_2 = require("../config");
15
+ const constants_js_1 = require("../../utils/constants.js");
16
+ // Global client singleton
17
+ let globalClient = null;
18
+ // Global logger
19
+ const logger = (0, config_2.getLogger)();
20
+ /**
21
+ * Initialize - Initialize Revenium client
22
+ * Can be called with explicit config or will load from environment variables.
23
+ * @param config - Optional configuration. If not provided, loads from environment.
24
+ */
25
+ function Initialize(config) {
26
+ logger.debug("Initializing Revenium client");
27
+ let finalConfig;
28
+ if (config) {
29
+ // Merge provided config with defaults
30
+ const defaultConfig = {
31
+ reveniumBaseUrl: constants_js_1.DEFAULT_REVENIUM_BASE_URL,
32
+ debug: false,
33
+ };
34
+ finalConfig = {
35
+ ...defaultConfig,
36
+ ...config,
37
+ };
38
+ logger.debug("Using provided configuration");
39
+ }
40
+ else {
41
+ // Load from environment variables
42
+ const envLoaded = (0, config_1.initializeConfig)();
43
+ if (!envLoaded) {
44
+ throw new Error("Failed to load configuration from environment variables. " +
45
+ "Ensure REVENIUM_METERING_API_KEY and OPENAI_API_KEY are set, " +
46
+ "or provide configuration explicitly to Initialize().");
47
+ }
48
+ finalConfig = (0, config_1.getConfig)();
49
+ logger.debug("Loaded configuration from environment");
50
+ }
51
+ // Validate configuration
52
+ try {
53
+ (0, config_1.validateConfig)(finalConfig);
54
+ }
55
+ catch (error) {
56
+ logger.error("Configuration validation failed", {
57
+ error: error instanceof Error ? error.message : String(error),
58
+ });
59
+ throw error;
60
+ }
61
+ // Store config globally
62
+ (0, config_1.setConfig)(finalConfig);
63
+ // Detect provider from configuration
64
+ const providerInfo = (0, providers_1.detectProviderFromConfig)(finalConfig);
65
+ logger.info("Detected provider", {
66
+ provider: providerInfo.provider,
67
+ isAzure: providerInfo.isAzure,
68
+ });
69
+ // Create global client
70
+ globalClient = new revenium_client_js_1.ReveniumOpenAI(finalConfig, providerInfo.provider);
71
+ logger.info("Revenium client initialized successfully");
72
+ }
73
+ /**
74
+ * GetClient - Get the global Revenium client
75
+ * @returns The global ReveniumOpenAI client
76
+ * @throws Error if client is not initialized
77
+ */
78
+ function GetClient() {
79
+ if (!globalClient) {
80
+ throw new Error("Revenium client not initialized. Call Initialize() first.\n\n" +
81
+ "Example:\n" +
82
+ ' import { Initialize, GetClient } from "@revenium/openai";\n' +
83
+ " Initialize();\n" +
84
+ " const client = GetClient();");
85
+ }
86
+ return globalClient;
87
+ }
88
+ /**
89
+ * IsInitialized - Check if client is initialized
90
+ * @returns true if client is initialized, false otherwise
91
+ */
92
+ function IsInitialized() {
93
+ return globalClient !== null;
94
+ }
95
+ /**
96
+ * Reset - Reset the global client
97
+ */
98
+ function Reset() {
99
+ logger.debug("Resetting global client");
100
+ globalClient = null;
101
+ }
102
+ /**
103
+ * Configure - Alias for Initialize
104
+ * @param config - Configuration object
105
+ */
106
+ function Configure(config) {
107
+ Initialize(config);
108
+ }
109
+ //# sourceMappingURL=manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../../src/core/client/manager.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAyBH,gCA0DC;AAOD,8BAWC;AAMD,sCAEC;AAKD,sBAGC;AAMD,8BAEC;AA3HD,yEAAkE;AAElE,sCAKmB;AACnB,4CAAwD;AACxD,sCAAsC;AACtC,2DAAqE;AAErE,0BAA0B;AAC1B,IAAI,YAAY,GAA0B,IAAI,CAAC;AAE/C,gBAAgB;AAChB,MAAM,MAAM,GAAG,IAAA,kBAAS,GAAE,CAAC;AAE3B;;;;GAIG;AACH,SAAgB,UAAU,CAAC,MAAwB;IACjD,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAE7C,IAAI,WAAmB,CAAC;IAExB,IAAI,MAAM,EAAE,CAAC;QACX,sCAAsC;QACtC,MAAM,aAAa,GAAG;YACpB,eAAe,EAAE,wCAAyB;YAC1C,KAAK,EAAE,KAAK;SACb,CAAC;QAEF,WAAW,GAAG;YACZ,GAAG,aAAa;YAChB,GAAG,MAAM;SACA,CAAC;QAEZ,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC/C,CAAC;SAAM,CAAC;QACN,kCAAkC;QAClC,MAAM,SAAS,GAAG,IAAA,yBAAgB,GAAE,CAAC;QAErC,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACb,2DAA2D;gBACzD,+DAA+D;gBAC/D,sDAAsD,CACzD,CAAC;QACJ,CAAC;QAED,WAAW,GAAG,IAAA,kBAAS,GAAG,CAAC;QAC3B,MAAM,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;IACxD,CAAC;IAED,yBAAyB;IACzB,IAAI,CAAC;QACH,IAAA,uBAAc,EAAC,WAAW,CAAC,CAAC;IAC9B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,iCAAiC,EAAE;YAC9C,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAC9D,CAAC,CAAC;QACH,MAAM,KAAK,CAAC;IACd,CAAC;IAED,wBAAwB;IACxB,IAAA,kBAAS,EAAC,WAAW,CAAC,CAAC;IAEvB,qCAAqC;IACrC,MAAM,YAAY,GAAG,IAAA,oCAAwB,EAAC,WAAW,CAAC,CAAC;IAC3D,MAAM,CAAC,IAAI,CAAC,mBAAmB,EAAE;QAC/B,QAAQ,EAAE,YAAY,CAAC,QAAQ;QAC/B,OAAO,EAAE,YAAY,CAAC,OAAO;KAC9B,CAAC,CAAC;IAEH,uBAAuB;IACvB,YAAY,GAAG,IAAI,mCAAc,CAAC,WAAW,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;IAEtE,MAAM,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;AAC1D,CAAC;AAED;;;;GAIG;AACH,SAAgB,SAAS;IACvB,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CACb,+DAA+D;YAC7D,YAAY;YACZ,+DAA+D;YAC/D,mBAAmB;YACnB,+BAA+B,CAClC,CAAC;IACJ,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,SAAgB,aAAa;IAC3B,OAAO,YAAY,KAAK,IAAI,CAAC;AAC/B,CAAC;AAED;;GAEG;AACH,SAAgB,KAAK;IACnB,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACxC,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,SAAgB,SAAS,CAAC,MAAuB;IAC/C,UAAU,CAAC,MAAM,CAAC,CAAC;AACrB,CAAC"}
@@ -21,41 +21,29 @@ function gatherAzureConfig(client) {
21
21
  try {
22
22
  // Extract from client baseURL if available
23
23
  if (client?.baseURL) {
24
- const baseUrl = typeof client.baseURL === 'string' ? client.baseURL : client.baseURL?.toString();
24
+ const baseUrl = typeof client.baseURL === "string"
25
+ ? client.baseURL
26
+ : client.baseURL?.toString();
25
27
  config.endpoint = baseUrl;
26
28
  }
27
29
  // Extract from environment variables
28
30
  if (process.env.AZURE_OPENAI_ENDPOINT) {
29
31
  config.endpoint = process.env.AZURE_OPENAI_ENDPOINT;
30
32
  }
31
- if (process.env.AZURE_OPENAI_DEPLOYMENT) {
32
- config.deployment = process.env.AZURE_OPENAI_DEPLOYMENT;
33
- }
34
33
  if (process.env.AZURE_OPENAI_API_VERSION) {
35
34
  config.apiVersion = process.env.AZURE_OPENAI_API_VERSION;
36
35
  }
37
- else {
38
- // Default to preferred API version from Python learnings
39
- config.apiVersion = '2024-12-01-preview';
40
- }
41
36
  if (process.env.AZURE_OPENAI_API_KEY) {
42
37
  config.apiKey = process.env.AZURE_OPENAI_API_KEY;
43
38
  }
44
- if (process.env.AZURE_OPENAI_TENANT_ID) {
45
- config.tenantId = process.env.AZURE_OPENAI_TENANT_ID;
46
- }
47
- if (process.env.AZURE_OPENAI_RESOURCE_GROUP) {
48
- config.resourceGroup = process.env.AZURE_OPENAI_RESOURCE_GROUP;
49
- }
50
- logger.debug('Azure configuration gathered', {
39
+ logger.debug("Azure configuration gathered", {
51
40
  hasEndpoint: !!config.endpoint,
52
- hasDeployment: !!config.deployment,
53
41
  hasApiKey: !!config.apiKey,
54
42
  apiVersion: config.apiVersion,
55
43
  });
56
44
  }
57
45
  catch (error) {
58
- logger.warn('Error gathering Azure configuration', {
46
+ logger.warn("Error gathering Azure configuration", {
59
47
  error: error instanceof Error ? error.message : String(error),
60
48
  });
61
49
  }