@revenium/openai 1.0.12 → 1.0.14

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 (236) hide show
  1. package/.env.example +10 -15
  2. package/CHANGELOG.md +59 -0
  3. package/CODE_OF_CONDUCT.md +57 -0
  4. package/CONTRIBUTING.md +38 -0
  5. package/README.md +109 -515
  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 +12 -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 +17 -0
  22. package/dist/cjs/core/middleware/index.js.map +1 -0
  23. package/dist/cjs/core/middleware/interfaces.js +361 -0
  24. package/dist/cjs/core/middleware/interfaces.js.map +1 -0
  25. package/dist/cjs/core/middleware/revenium-client.js +142 -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 +14 -13
  32. package/dist/cjs/core/tracking/api-client.js.map +1 -1
  33. package/dist/cjs/core/tracking/payload-builder.js +30 -35
  34. package/dist/cjs/core/tracking/payload-builder.js.map +1 -1
  35. package/dist/cjs/core/tracking/usage-tracker.js +22 -18
  36. package/dist/cjs/core/tracking/usage-tracker.js.map +1 -1
  37. package/dist/cjs/index.js +26 -174
  38. package/dist/cjs/index.js.map +1 -1
  39. package/dist/cjs/types/index.js +0 -8
  40. package/dist/cjs/types/index.js.map +1 -1
  41. package/dist/cjs/types/openai-augmentation.js +0 -49
  42. package/dist/cjs/types/openai-augmentation.js.map +1 -1
  43. package/dist/cjs/utils/constants.js +17 -20
  44. package/dist/cjs/utils/constants.js.map +1 -1
  45. package/dist/cjs/utils/error-handler.js +18 -14
  46. package/dist/cjs/utils/error-handler.js.map +1 -1
  47. package/dist/cjs/utils/metadata-builder.js +27 -19
  48. package/dist/cjs/utils/metadata-builder.js.map +1 -1
  49. package/dist/cjs/utils/provider-detection.js +25 -28
  50. package/dist/cjs/utils/provider-detection.js.map +1 -1
  51. package/dist/cjs/utils/stop-reason-mapper.js +4 -0
  52. package/dist/cjs/utils/stop-reason-mapper.js.map +1 -1
  53. package/dist/cjs/utils/url-builder.js +3 -3
  54. package/dist/esm/core/client/index.js +6 -0
  55. package/dist/esm/core/client/index.js.map +1 -0
  56. package/dist/esm/core/client/manager.js +102 -0
  57. package/dist/esm/core/client/manager.js.map +1 -0
  58. package/dist/esm/core/config/azure-config.js +6 -18
  59. package/dist/esm/core/config/azure-config.js.map +1 -1
  60. package/dist/esm/core/config/index.js +5 -4
  61. package/dist/esm/core/config/index.js.map +1 -1
  62. package/dist/esm/core/config/loader.js +33 -13
  63. package/dist/esm/core/config/loader.js.map +1 -1
  64. package/dist/esm/core/config/manager.js +14 -7
  65. package/dist/esm/core/config/manager.js.map +1 -1
  66. package/dist/esm/core/config/validator.js +3 -44
  67. package/dist/esm/core/config/validator.js.map +1 -1
  68. package/dist/esm/core/middleware/index.js +8 -0
  69. package/dist/esm/core/middleware/index.js.map +1 -0
  70. package/dist/esm/core/middleware/interfaces.js +353 -0
  71. package/dist/esm/core/middleware/interfaces.js.map +1 -0
  72. package/dist/esm/core/middleware/revenium-client.js +105 -0
  73. package/dist/esm/core/middleware/revenium-client.js.map +1 -0
  74. package/dist/esm/core/providers/detector.js +43 -22
  75. package/dist/esm/core/providers/detector.js.map +1 -1
  76. package/dist/esm/core/providers/index.js +2 -2
  77. package/dist/esm/core/providers/index.js.map +1 -1
  78. package/dist/esm/core/tracking/api-client.js +13 -12
  79. package/dist/esm/core/tracking/api-client.js.map +1 -1
  80. package/dist/esm/core/tracking/payload-builder.js +31 -36
  81. package/dist/esm/core/tracking/payload-builder.js.map +1 -1
  82. package/dist/esm/core/tracking/usage-tracker.js +24 -20
  83. package/dist/esm/core/tracking/usage-tracker.js.map +1 -1
  84. package/dist/esm/index.js +9 -157
  85. package/dist/esm/index.js.map +1 -1
  86. package/dist/esm/types/index.js +2 -10
  87. package/dist/esm/types/index.js.map +1 -1
  88. package/dist/esm/types/openai-augmentation.js +0 -49
  89. package/dist/esm/types/openai-augmentation.js.map +1 -1
  90. package/dist/esm/utils/constants.js +16 -19
  91. package/dist/esm/utils/constants.js.map +1 -1
  92. package/dist/esm/utils/error-handler.js +19 -15
  93. package/dist/esm/utils/error-handler.js.map +1 -1
  94. package/dist/esm/utils/metadata-builder.js +27 -19
  95. package/dist/esm/utils/metadata-builder.js.map +1 -1
  96. package/dist/esm/utils/provider-detection.js +26 -29
  97. package/dist/esm/utils/provider-detection.js.map +1 -1
  98. package/dist/esm/utils/stop-reason-mapper.js +4 -0
  99. package/dist/esm/utils/stop-reason-mapper.js.map +1 -1
  100. package/dist/esm/utils/url-builder.js +3 -3
  101. package/dist/types/core/client/index.d.ts +6 -0
  102. package/dist/types/core/client/index.d.ts.map +1 -0
  103. package/dist/types/core/client/manager.d.ts +32 -0
  104. package/dist/types/core/client/manager.d.ts.map +1 -0
  105. package/dist/types/core/config/azure-config.d.ts +2 -2
  106. package/dist/types/core/config/azure-config.d.ts.map +1 -1
  107. package/dist/types/core/config/index.d.ts +4 -4
  108. package/dist/types/core/config/index.d.ts.map +1 -1
  109. package/dist/types/core/config/loader.d.ts +3 -1
  110. package/dist/types/core/config/loader.d.ts.map +1 -1
  111. package/dist/types/core/config/manager.d.ts +1 -1
  112. package/dist/types/core/config/manager.d.ts.map +1 -1
  113. package/dist/types/core/config/validator.d.ts +1 -12
  114. package/dist/types/core/config/validator.d.ts.map +1 -1
  115. package/dist/types/core/middleware/index.d.ts +8 -0
  116. package/dist/types/core/middleware/index.d.ts.map +1 -0
  117. package/dist/types/core/middleware/interfaces.d.ts +74 -0
  118. package/dist/types/core/middleware/interfaces.d.ts.map +1 -0
  119. package/dist/types/core/middleware/revenium-client.d.ts +58 -0
  120. package/dist/types/core/middleware/revenium-client.d.ts.map +1 -0
  121. package/dist/types/core/providers/detector.d.ts +9 -2
  122. package/dist/types/core/providers/detector.d.ts.map +1 -1
  123. package/dist/types/core/providers/index.d.ts +2 -2
  124. package/dist/types/core/providers/index.d.ts.map +1 -1
  125. package/dist/types/core/tracking/api-client.d.ts +1 -1
  126. package/dist/types/core/tracking/api-client.d.ts.map +1 -1
  127. package/dist/types/core/tracking/payload-builder.d.ts +3 -3
  128. package/dist/types/core/tracking/payload-builder.d.ts.map +1 -1
  129. package/dist/types/core/tracking/usage-tracker.d.ts +2 -2
  130. package/dist/types/core/tracking/usage-tracker.d.ts.map +1 -1
  131. package/dist/types/index.d.ts +11 -114
  132. package/dist/types/index.d.ts.map +1 -1
  133. package/dist/types/types/function-parameters.d.ts +2 -23
  134. package/dist/types/types/function-parameters.d.ts.map +1 -1
  135. package/dist/types/types/index.d.ts +17 -115
  136. package/dist/types/types/index.d.ts.map +1 -1
  137. package/dist/types/types/openai-augmentation.d.ts +4 -139
  138. package/dist/types/types/openai-augmentation.d.ts.map +1 -1
  139. package/dist/types/utils/constants.d.ts +7 -1
  140. package/dist/types/utils/constants.d.ts.map +1 -1
  141. package/dist/types/utils/error-handler.d.ts +2 -2
  142. package/dist/types/utils/error-handler.d.ts.map +1 -1
  143. package/dist/types/utils/metadata-builder.d.ts +4 -3
  144. package/dist/types/utils/metadata-builder.d.ts.map +1 -1
  145. package/dist/types/utils/provider-detection.d.ts +3 -3
  146. package/dist/types/utils/provider-detection.d.ts.map +1 -1
  147. package/dist/types/utils/stop-reason-mapper.d.ts.map +1 -1
  148. package/dist/types/utils/url-builder.d.ts +3 -3
  149. package/examples/README.md +270 -224
  150. package/examples/azure/basic.ts +62 -0
  151. package/examples/azure/responses-basic.ts +45 -0
  152. package/examples/azure/responses-stream.ts +61 -0
  153. package/examples/azure/stream.ts +56 -0
  154. package/examples/getting_started.ts +31 -43
  155. package/examples/openai/basic.ts +45 -0
  156. package/examples/openai/metadata.ts +67 -0
  157. package/examples/openai/responses-basic.ts +44 -0
  158. package/examples/openai/responses-embed.ts +34 -0
  159. package/examples/openai/responses-streaming.ts +63 -0
  160. package/examples/openai/streaming.ts +59 -0
  161. package/package.json +20 -13
  162. package/dist/cjs/core/wrapper/index.js +0 -15
  163. package/dist/cjs/core/wrapper/index.js.map +0 -1
  164. package/dist/cjs/core/wrapper/instance-patcher.js +0 -202
  165. package/dist/cjs/core/wrapper/instance-patcher.js.map +0 -1
  166. package/dist/cjs/core/wrapper/request-handler.js +0 -317
  167. package/dist/cjs/core/wrapper/request-handler.js.map +0 -1
  168. package/dist/cjs/core/wrapper/stream-wrapper.js +0 -82
  169. package/dist/cjs/core/wrapper/stream-wrapper.js.map +0 -1
  170. package/dist/cjs/utils/azure-model-resolver.js +0 -211
  171. package/dist/cjs/utils/azure-model-resolver.js.map +0 -1
  172. package/dist/cjs/utils/request-handler-factory.js +0 -185
  173. package/dist/cjs/utils/request-handler-factory.js.map +0 -1
  174. package/dist/esm/core/wrapper/index.js +0 -9
  175. package/dist/esm/core/wrapper/index.js.map +0 -1
  176. package/dist/esm/core/wrapper/instance-patcher.js +0 -199
  177. package/dist/esm/core/wrapper/instance-patcher.js.map +0 -1
  178. package/dist/esm/core/wrapper/request-handler.js +0 -310
  179. package/dist/esm/core/wrapper/request-handler.js.map +0 -1
  180. package/dist/esm/core/wrapper/stream-wrapper.js +0 -79
  181. package/dist/esm/core/wrapper/stream-wrapper.js.map +0 -1
  182. package/dist/esm/utils/azure-model-resolver.js +0 -204
  183. package/dist/esm/utils/azure-model-resolver.js.map +0 -1
  184. package/dist/esm/utils/request-handler-factory.js +0 -146
  185. package/dist/esm/utils/request-handler-factory.js.map +0 -1
  186. package/dist/types/core/wrapper/index.d.ts +0 -8
  187. package/dist/types/core/wrapper/index.d.ts.map +0 -1
  188. package/dist/types/core/wrapper/instance-patcher.d.ts +0 -33
  189. package/dist/types/core/wrapper/instance-patcher.d.ts.map +0 -1
  190. package/dist/types/core/wrapper/request-handler.d.ts +0 -29
  191. package/dist/types/core/wrapper/request-handler.d.ts.map +0 -1
  192. package/dist/types/core/wrapper/stream-wrapper.d.ts +0 -13
  193. package/dist/types/core/wrapper/stream-wrapper.d.ts.map +0 -1
  194. package/dist/types/utils/azure-model-resolver.d.ts +0 -41
  195. package/dist/types/utils/azure-model-resolver.d.ts.map +0 -1
  196. package/dist/types/utils/request-handler-factory.d.ts +0 -81
  197. package/dist/types/utils/request-handler-factory.d.ts.map +0 -1
  198. package/examples/azure-basic.ts +0 -206
  199. package/examples/azure-responses-basic.ts +0 -233
  200. package/examples/azure-responses-streaming.ts +0 -255
  201. package/examples/azure-streaming.ts +0 -209
  202. package/examples/openai-basic.ts +0 -147
  203. package/examples/openai-function-calling.ts +0 -259
  204. package/examples/openai-responses-basic.ts +0 -212
  205. package/examples/openai-responses-streaming.ts +0 -232
  206. package/examples/openai-streaming.ts +0 -172
  207. package/examples/openai-vision.ts +0 -289
  208. package/src/core/config/azure-config.ts +0 -72
  209. package/src/core/config/index.ts +0 -23
  210. package/src/core/config/loader.ts +0 -66
  211. package/src/core/config/manager.ts +0 -94
  212. package/src/core/config/validator.ts +0 -89
  213. package/src/core/providers/detector.ts +0 -159
  214. package/src/core/providers/index.ts +0 -16
  215. package/src/core/tracking/api-client.ts +0 -78
  216. package/src/core/tracking/index.ts +0 -21
  217. package/src/core/tracking/payload-builder.ts +0 -132
  218. package/src/core/tracking/usage-tracker.ts +0 -189
  219. package/src/core/wrapper/index.ts +0 -9
  220. package/src/core/wrapper/instance-patcher.ts +0 -288
  221. package/src/core/wrapper/request-handler.ts +0 -423
  222. package/src/core/wrapper/stream-wrapper.ts +0 -100
  223. package/src/index.ts +0 -336
  224. package/src/types/function-parameters.ts +0 -251
  225. package/src/types/index.ts +0 -313
  226. package/src/types/openai-augmentation.ts +0 -233
  227. package/src/types/responses-api.ts +0 -308
  228. package/src/utils/azure-model-resolver.ts +0 -220
  229. package/src/utils/constants.ts +0 -21
  230. package/src/utils/error-handler.ts +0 -251
  231. package/src/utils/metadata-builder.ts +0 -219
  232. package/src/utils/provider-detection.ts +0 -257
  233. package/src/utils/request-handler-factory.ts +0 -285
  234. package/src/utils/stop-reason-mapper.ts +0 -74
  235. package/src/utils/type-guards.ts +0 -202
  236. package/src/utils/url-builder.ts +0 -68
package/README.md CHANGED
@@ -3,22 +3,26 @@
3
3
  [![npm version](https://img.shields.io/npm/v/@revenium/openai.svg)](https://www.npmjs.com/package/@revenium/openai)
4
4
  [![Node.js](https://img.shields.io/badge/Node.js-16%2B-green)](https://nodejs.org/)
5
5
  [![Documentation](https://img.shields.io/badge/docs-revenium.io-blue)](https://docs.revenium.io)
6
+ [![Website](https://img.shields.io/badge/website-revenium.ai-blue)](https://www.revenium.ai)
6
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
8
 
8
9
  **Transparent TypeScript middleware for automatic Revenium usage tracking with OpenAI**
9
10
 
10
- 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!**
11
14
 
12
15
  ## Features
13
16
 
17
+ - **Go-Aligned API** - Same `Initialize()`/`GetClient()` pattern as Go implementation
14
18
  - **Seamless Integration** - Native TypeScript support, no type casting required
15
- - **Optional Metadata** - Track users, organizations, and custom metadata (all fields optional)
16
- - **Dual API Support** - Chat Completions API + new Responses API (OpenAI SDK 5.8+)
19
+ - **Optional Metadata** - Track users, organizations, and business context (all fields optional)
20
+ - **Multiple API Support** - Chat Completions, Embeddings, and Responses API
17
21
  - **Azure OpenAI Support** - Full Azure OpenAI integration with automatic detection
18
22
  - **Type Safety** - Complete TypeScript support with IntelliSense
19
23
  - **Streaming Support** - Handles regular and streaming requests seamlessly
20
24
  - **Fire-and-Forget** - Never blocks your application flow
21
- - **Zero Configuration** - Auto-initialization from environment variables
25
+ - **Automatic .env Loading** - Loads environment variables automatically
22
26
 
23
27
  ## Getting Started
24
28
 
@@ -39,42 +43,28 @@ npm install --save-dev typescript @types/node
39
43
 
40
44
  ### 2. Configure Environment Variables
41
45
 
42
- 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.
43
47
 
44
- **NOTE: YOU MUST REPLACE THE PLACEHOLDERS WITH YOUR OWN API KEYS**
48
+ **Minimum required configuration:**
45
49
 
46
50
  ```env
47
- REVENIUM_METERING_BASE_URL=https://api.revenium.io
48
51
  REVENIUM_METERING_API_KEY=hak_your_revenium_api_key_here
52
+ REVENIUM_METERING_BASE_URL=https://api.revenium.ai
49
53
  OPENAI_API_KEY=sk_your_openai_api_key_here
50
54
  ```
51
55
 
52
- ### 3. Run Your First Example
53
-
54
- Run the [getting started example](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/getting_started.ts):
55
-
56
- ```bash
57
- npx tsx node_modules/@revenium/openai/examples/getting_started.ts
58
- ```
59
-
60
- Or with debug logging:
56
+ **NOTE: Replace the placeholder values with your actual API keys.**
61
57
 
62
- ```bash
63
- # Linux/macOS
64
- REVENIUM_DEBUG=true npx tsx node_modules/@revenium/openai/examples/getting_started.ts
65
-
66
- # Windows (PowerShell)
67
- $env:REVENIUM_DEBUG="true"; npx tsx node_modules/@revenium/openai/examples/getting_started.ts
68
- ```
58
+ ### 3. Run Your First Example
69
59
 
70
- **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).**
71
61
 
72
62
  ---
73
63
 
74
64
  ## Requirements
75
65
 
76
66
  - Node.js 16+
77
- - OpenAI package v4.0+
67
+ - OpenAI package v5.0.0 or later
78
68
  - TypeScript 5.0+ (for TypeScript projects)
79
69
 
80
70
  ---
@@ -95,7 +85,7 @@ The middleware automatically captures comprehensive usage data:
95
85
  - **User Tracking** - Subscriber ID, email, credentials
96
86
  - **Organization Data** - Organization ID, subscription ID, product ID
97
87
  - **Task Classification** - Task type, agent identifier, trace ID
98
- - **Quality Metrics** - Response quality scores, custom metadata
88
+ - **Quality Metrics** - Response quality scores, task identifiers
99
89
 
100
90
  ### **Technical Details**
101
91
 
@@ -104,545 +94,152 @@ The middleware automatically captures comprehensive usage data:
104
94
  - **Error Tracking** - Failed requests, error types, retry attempts
105
95
  - **Environment Info** - Development vs production usage
106
96
 
107
- ## OpenAI Responses API Support
108
-
109
- This middleware includes **full support** for OpenAI's new Responses API, which is designed to replace the traditional Chat Completions API with enhanced capabilities for agent-like applications.
110
-
111
- ### What is the Responses API?
112
-
113
- The Responses API is OpenAI's new stateful API that:
114
-
115
- - Uses `input` instead of `messages` parameter for simplified interaction
116
- - Provides unified experience combining chat completions and assistants capabilities
117
- - Supports advanced features like background tasks, function calling, and code interpreter
118
- - Offers better streaming and real-time response generation
119
- - Works with GPT-5 and other advanced models
120
-
121
- ### API Comparison
122
-
123
- **Traditional Chat Completions:**
124
-
125
- ```javascript
126
- const response = await openai.chat.completions.create({
127
- model: 'gpt-4o',
128
- messages: [{ role: 'user', content: 'Hello' }],
129
- });
130
- ```
131
-
132
- **New Responses API:**
133
-
134
- ```javascript
135
- const response = await openai.responses.create({
136
- model: 'gpt-5',
137
- input: 'Hello', // Simplified input parameter
138
- });
139
- ```
140
-
141
- ### Key Differences
142
-
143
- | Feature | Chat Completions | Responses API |
144
- | ---------------------- | ---------------------------- | ----------------------------------- |
145
- | **Input Format** | `messages: [...]` | `input: "string"` or `input: [...]` |
146
- | **Models** | GPT-4, GPT-4o, etc. | GPT-5, GPT-4o, etc. |
147
- | **Response Structure** | `choices[0].message.content` | `output_text` |
148
- | **Stateful** | No | Yes (with `store: true`) |
149
- | **Advanced Features** | Limited | Built-in tools, reasoning, etc. |
150
- | **Temperature** | Supported | Not supported with GPT-5 |
151
-
152
- ### Requirements & Installation
153
-
154
- **OpenAI SDK Version:**
155
-
156
- - **Minimum:** `5.8.0` (when Responses API was officially released)
157
- - **Recommended:** `5.8.2` or later (tested and verified)
158
- - **Current:** `6.2.0` (latest available)
159
-
160
- **Installation:**
161
-
162
- ```bash
163
- # Install latest version with Responses API support
164
- npm install openai@^5.8.0
165
-
166
- # Or install specific tested version
167
- npm install openai@5.8.2
168
- ```
169
-
170
- ### Current Status
171
-
172
- **The Responses API is officially available in OpenAI SDK 5.8+**
173
-
174
- **Official Release:**
175
-
176
- - Released by OpenAI in SDK version 5.8.0
177
- - Fully documented in official OpenAI documentation
178
- - Production-ready with GPT-5 and other supported models
179
- - Complete middleware support with Revenium integration
180
-
181
- **Middleware Features:**
182
-
183
- - Full Responses API support (streaming & non-streaming)
184
- - Seamless metadata tracking identical to Chat Completions
185
- - Type-safe TypeScript integration
186
- - Complete token tracking including reasoning tokens
187
- - Azure OpenAI compatibility
97
+ ## API Overview
188
98
 
189
- **References:**
99
+ The middleware provides a Go-aligned API with the following main functions:
190
100
 
191
- - [OpenAI Responses API Documentation](https://platform.openai.com/docs/guides/migrate-to-responses)
192
- - [Azure OpenAI Responses API Documentation](https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/responses)
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)
193
106
 
194
- ### Working Examples
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).**
195
108
 
196
- Complete working examples are included with this package. Each example is fully documented and ready to run.
109
+ ## Metadata Fields
197
110
 
198
- #### Available Examples
111
+ The middleware supports the following optional metadata fields for tracking:
199
112
 
200
- **OpenAI Chat Completions API:**
201
- - `openai-basic.ts` - Basic chat + embeddings with optional metadata
202
- - `openai-streaming.ts` - Streaming responses + batch embeddings
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) |
203
125
 
204
- **OpenAI Responses API (SDK 5.8+):**
205
- - `openai-responses-basic.ts` - New Responses API with string input
206
- - `openai-responses-streaming.ts` - Streaming with Responses API
126
+ **All metadata fields are optional.** For complete metadata documentation and usage examples, see:
207
127
 
208
- **Azure OpenAI:**
209
- - `azure-basic.ts` - Azure chat completions + embeddings
210
- - `azure-streaming.ts` - Azure streaming responses
211
- - `azure-responses-basic.ts` - Azure Responses API
212
- - `azure-responses-streaming.ts` - Azure streaming Responses API
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
213
130
 
214
- **Detailed Guide:**
215
- - `examples/README.md` - Complete setup guide with TypeScript and JavaScript patterns
216
-
217
- #### Running Examples
218
-
219
- **Installed via npm?**
220
- ```bash
221
- # Try these in order:
222
- npx tsx node_modules/@revenium/openai/examples/openai-basic.ts
223
- npx tsx node_modules/@revenium/openai/examples/openai-streaming.ts
224
- npx tsx node_modules/@revenium/openai/examples/openai-responses-basic.ts
225
-
226
- # View all examples:
227
- ls node_modules/@revenium/openai/examples/
228
- ```
229
-
230
- **Cloned from GitHub?**
231
- ```bash
232
- npm install
233
- npm run example:openai-basic
234
- npm run example:openai-streaming
235
- npm run example:openai-responses-basic
236
-
237
- # See all example scripts:
238
- npm run
239
- ```
240
-
241
- **Browse online:** [`examples/` directory on GitHub](https://github.com/revenium/revenium-middleware-openai-node/tree/HEAD/examples)
242
-
243
- ### Temporarily Disabling Tracking
244
-
245
- If you need to disable Revenium tracking temporarily, you can unpatch the OpenAI client:
246
-
247
- ```javascript
248
- import { unpatchOpenAI, patchOpenAI } from '@revenium/openai-middleware';
249
-
250
- // Disable tracking
251
- unpatchOpenAI();
252
-
253
- // Your OpenAI calls now bypass Revenium tracking
254
- await openai.chat.completions.create({...});
255
-
256
- // Re-enable tracking
257
- patchOpenAI();
258
- ```
259
-
260
- **Common use cases:**
261
-
262
- - **Debugging**: Isolate whether issues are caused by the middleware
263
- - **Testing**: Compare behavior with/without tracking
264
- - **Conditional tracking**: Enable/disable based on environment
265
- - **Troubleshooting**: Temporary bypass during incident response
266
-
267
- **Note**: This affects all OpenAI instances globally since we patch the prototype methods.
131
+ ## Configuration Options
268
132
 
269
- ## Azure OpenAI Integration
133
+ ### Environment Variables
270
134
 
271
- **Azure OpenAI support** The middleware automatically detects Azure OpenAI clients and provides accurate usage tracking and cost calculation.
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).
272
136
 
273
- ### Quick Start with Azure OpenAI
137
+ ## Examples
274
138
 
275
- **Use case:** Automatic Azure OpenAI client detection with deployment name mapping and accurate usage tracking.
139
+ The package includes comprehensive examples in the [`examples/`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/) directory.
276
140
 
277
- See complete Azure examples:
278
- - `examples/azure-basic.ts` - Azure chat completions with environment variable setup
279
- - `examples/azure-streaming.ts` - Azure streaming responses
280
- - `examples/azure-responses-basic.ts` - Azure Responses API integration
141
+ ### Getting Started
281
142
 
282
- **Environment variables needed:**
283
143
  ```bash
284
- # Azure OpenAI configuration
285
- AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com/"
286
- AZURE_OPENAI_API_KEY="your-azure-api-key"
287
- AZURE_OPENAI_DEPLOYMENT="gpt-4o"
288
- AZURE_OPENAI_API_VERSION="2024-12-01-preview"
289
-
290
- # Revenium configuration
291
- REVENIUM_METERING_API_KEY="hak_your_revenium_api_key"
292
- REVENIUM_METERING_BASE_URL="https://api.revenium.io"
293
- ```
294
-
295
- ### Azure Features
296
-
297
- - **Automatic Detection**: Detects Azure OpenAI clients automatically
298
- - **Model Name Resolution**: Maps Azure deployment names to standard model names for accurate pricing
299
- - **Provider Metadata**: Correctly tags requests with `provider: "Azure"` and `modelSource: "OPENAI"`
300
- - **Deployment Support**: Works with any Azure deployment name (simple or complex)
301
- - **Endpoint Flexibility**: Supports all Azure OpenAI endpoint formats
302
- - **Zero Code Changes**: Existing Azure OpenAI code works without modification
303
-
304
- ### Azure Environment Variables
305
-
306
- | Variable | Required | Description | Example |
307
- | -------------------------- | -------- | ---------------------------------------------- | ------------------------------------ |
308
- | `AZURE_OPENAI_ENDPOINT` | Yes | Your Azure OpenAI endpoint URL | `https://acme.openai.azure.com/` |
309
- | `AZURE_OPENAI_API_KEY` | Yes | Your Azure OpenAI API key | `abc123...` |
310
- | `AZURE_OPENAI_DEPLOYMENT` | No | Default deployment name | `gpt-4o` or `text-embedding-3-large` |
311
- | `AZURE_OPENAI_API_VERSION` | No | API version (defaults to `2024-12-01-preview`) | `2024-12-01-preview` |
312
-
313
- ### Azure Model Name Resolution
314
-
315
- The middleware automatically maps Azure deployment names to standard model names for accurate pricing:
316
-
317
- ```typescript
318
- // Azure deployment names → Standard model names for pricing
319
- "gpt-4o-2024-11-20" → "gpt-4o"
320
- "gpt4o-prod" → "gpt-4o"
321
- "o4-mini" → "gpt-4o-mini"
322
- "gpt-35-turbo-dev" → "gpt-3.5-turbo"
323
- "text-embedding-3-large" → "text-embedding-3-large" // Direct match
324
- "embedding-3-large" → "text-embedding-3-large"
325
- ```
326
-
327
- ## Advanced Usage
328
-
329
- ### Initialization Options
330
-
331
- The middleware supports three initialization patterns:
332
-
333
- **Automatic (Recommended)** - Import and patch OpenAI instance:
334
-
335
- ```typescript
336
- import { patchOpenAIInstance } from '@revenium/openai';
337
- import OpenAI from 'openai';
338
-
339
- const openai = patchOpenAIInstance(new OpenAI());
340
- // Tracking works automatically if env vars are set
144
+ npm run example:getting-started
341
145
  ```
342
146
 
343
- **Explicit** - Call `initializeReveniumFromEnv()` for error handling control:
147
+ ### OpenAI Examples
344
148
 
345
- ```typescript
346
- import { initializeReveniumFromEnv, patchOpenAIInstance } from '@revenium/openai';
347
- import OpenAI from 'openai';
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 |
348
157
 
349
- const result = initializeReveniumFromEnv();
350
- if (!result.success) {
351
- console.error('Failed to initialize:', result.message);
352
- process.exit(1);
353
- }
158
+ ### Azure OpenAI Examples
354
159
 
355
- const openai = patchOpenAIInstance(new OpenAI());
356
- ```
357
-
358
- **Manual** - Use `configure()` to set all options programmatically (see Manual Configuration below).
359
-
360
- For detailed examples of all initialization patterns, see [`examples/`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/README.md).
361
-
362
- ### Streaming Responses
363
-
364
- Streaming is fully supported with real-time token tracking and time-to-first-token metrics. The middleware automatically tracks streaming responses without any additional configuration.
365
-
366
- 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.
367
-
368
- ### Custom Metadata Tracking
369
-
370
- Add business context to track usage by organization, user, task type, or custom fields. Pass a `usageMetadata` object with any of these optional fields:
371
-
372
- | Field | Description | Use Case |
373
- |-------|-------------|----------|
374
- | `traceId` | Unique identifier for session or conversation tracking | Link multiple API calls together for debugging, user session analytics, or distributed tracing across services |
375
- | `taskType` | Type of AI task being performed | Categorize usage by workload (e.g., "chat", "code-generation", "doc-summary") for cost analysis and optimization |
376
- | `subscriber.id` | Unique user identifier | Track individual user consumption for billing, rate limiting, or user analytics |
377
- | `subscriber.email` | User email address | Identify users for support, compliance, or usage reports |
378
- | `subscriber.credential.name` | Authentication credential name | Track which API key or service account made the request |
379
- | `subscriber.credential.value` | Authentication credential value | Associate usage with specific credentials for security auditing |
380
- | `organizationId` | Organization or company identifier | Multi-tenant cost allocation, usage quotas per organization |
381
- | `subscriptionId` | Subscription plan identifier | Track usage against subscription limits, identify plan upgrade opportunities |
382
- | `productId` | Your product or feature identifier | Attribute AI costs to specific features in your application (e.g., "chatbot", "email-assistant") |
383
- | `agent` | AI agent or bot identifier | Distinguish between multiple AI agents or automation workflows in your system |
384
- | `responseQualityScore` | Custom quality rating (0.0-1.0) | Track user satisfaction or automated quality metrics for model performance analysis |
385
-
386
- **Resources:**
387
- - [API Reference](https://revenium.readme.io/reference/meter_ai_completion) - Complete metadata field documentation
388
-
389
- ### OpenAI Responses API
390
- **Use case:** Using OpenAI's new Responses API with string inputs and simplified interface (SDK 5.8+).
391
-
392
- See working examples:
393
- - `examples/openai-responses-basic.ts` - Basic Responses API usage
394
- - `examples/openai-responses-streaming.ts` - Streaming with Responses API
395
-
396
- ### Azure OpenAI Integration
397
- **Use case:** Automatic Azure OpenAI detection with deployment name resolution and accurate pricing.
398
-
399
- See working examples:
400
- - `examples/azure-basic.ts` - Azure chat completions and embeddings
401
- - `examples/azure-responses-basic.ts` - Azure Responses API integration
402
-
403
- ### Embeddings with Metadata
404
- **Use case:** Track embeddings usage for search engines, RAG systems, and document processing.
405
-
406
- Embeddings examples are included in:
407
- - `examples/openai-basic.ts` - Text embeddings with metadata
408
- - `examples/openai-streaming.ts` - Batch embeddings processing
409
-
410
- ### Manual Configuration
411
-
412
- For advanced use cases, configure the middleware manually:
413
-
414
- ```typescript
415
- import { configure } from '@revenium/openai';
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 |
416
166
 
417
- configure({
418
- reveniumApiKey: 'hak_your_api_key',
419
- reveniumBaseUrl: 'https://api.revenium.io',
420
- apiTimeout: 5000,
421
- failSilent: true,
422
- maxRetries: 3,
423
- });
424
- ```
425
-
426
- ## Configuration Options
427
-
428
- ### Environment Variables
429
-
430
- | Variable | Required | Default | Description |
431
- | ------------------------------ | -------- | ------------------------------- | ---------------------------------------------- |
432
- | `REVENIUM_METERING_API_KEY` | true | - | Your Revenium API key (starts with `hak_`) |
433
- | `OPENAI_API_KEY` | true | - | Your OpenAI API key (starts with `sk-`) |
434
- | `REVENIUM_METERING_BASE_URL` | false | `https://api.revenium.io` | Revenium metering API base URL |
435
- | `REVENIUM_DEBUG` | false | `false` | Enable debug logging (`true`/`false`) |
436
- | `AZURE_OPENAI_ENDPOINT` | false | - | Azure OpenAI endpoint URL (for Azure testing) |
437
- | `AZURE_OPENAI_API_KEY` | false | - | Azure OpenAI API key (for Azure testing) |
438
- | `AZURE_OPENAI_DEPLOYMENT` | false | - | Azure OpenAI deployment name (for Azure) |
439
- | `AZURE_OPENAI_API_VERSION` | false | `2024-12-01-preview` | Azure OpenAI API version (for Azure) |
440
-
441
- **Important Note about `REVENIUM_METERING_BASE_URL`:**
442
-
443
- - This variable is **optional** and defaults to the production URL (`https://api.revenium.io`)
444
- - If you don't set it explicitly, the middleware will use the default production endpoint
445
- - However, you may see console warnings or errors if the middleware cannot determine the correct environment
446
- - **Best practice:** Always set this variable explicitly to match your environment:
447
-
448
- ```bash
449
- # Default production URL (recommended)
450
- REVENIUM_METERING_BASE_URL=https://api.revenium.io
451
- ```
452
-
453
- - **Remember:** Your `REVENIUM_METERING_API_KEY` must match your base URL environment
454
-
455
- ### Usage Metadata Options
456
-
457
- All metadata fields are optional and help provide better analytics:
458
-
459
- ```typescript
460
- interface UsageMetadata {
461
- traceId?: string; // Session or conversation ID
462
- taskType?: string; // Type of AI task (e.g., "chat", "summary")
463
- subscriber?: {
464
- // User information (nested structure)
465
- id?: string; // User ID from your system
466
- email?: string; // User's email address
467
- credential?: {
468
- // User credentials
469
- name?: string; // Credential name
470
- value?: string; // Credential value
471
- };
472
- };
473
- organizationId?: string; // Organization/company ID
474
- subscriptionId?: string; // Billing plan ID
475
- productId?: string; // Your product/feature ID
476
- agent?: string; // AI agent identifier
477
- responseQualityScore?: number; // Quality score (0-1)
478
- }
479
- ```
480
-
481
- ## Included Examples
482
-
483
- The package includes 8 comprehensive example files in your installation:
484
-
485
- **OpenAI Examples:**
486
- - **openai-basic.ts**: Basic chat completions with metadata tracking
487
- - **openai-streaming.ts**: Streaming responses with real-time output
488
- - **openai-responses-basic.ts**: New Responses API usage (OpenAI SDK 5.8+)
489
- - **openai-responses-streaming.ts**: Streaming with Responses API
490
-
491
- **Azure OpenAI Examples:**
492
- - **azure-basic.ts**: Azure OpenAI chat completions
493
- - **azure-streaming.ts**: Azure streaming responses
494
- - **azure-responses-basic.ts**: Azure Responses API
495
- - **azure-responses-streaming.ts**: Azure streaming Responses API
496
-
497
- **For npm users:** Examples are installed in `node_modules/@revenium/openai/examples/`
498
-
499
- **For GitHub users:** Examples are in the repository's `examples/` directory
500
-
501
- For detailed setup instructions and usage patterns, 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).**
502
168
 
503
169
  ## How It Works
504
170
 
505
- 1. **Automatic Patching**: When imported, the middleware patches OpenAI's methods:
506
- - `chat.completions.create` (Chat Completions API)
507
- - `responses.create` (Responses API - when available)
508
- - `embeddings.create` (Embeddings API)
509
- 2. **Request Interception**: All OpenAI requests are intercepted to extract metadata
510
- 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
511
174
  4. **Async Tracking**: Usage data is sent to Revenium in the background (fire-and-forget)
512
175
  5. **Transparent Response**: Original OpenAI responses are returned unchanged
513
176
 
514
177
  The middleware never blocks your application - if Revenium tracking fails, your OpenAI requests continue normally.
515
178
 
516
- ## Troubleshooting
517
-
518
- ### Common Issues
519
-
520
- #### 1. **No tracking data in dashboard**
521
-
522
- **Symptoms**: OpenAI calls work but no data appears in Revenium dashboard
179
+ **Supported APIs:**
523
180
 
524
- **Solution**: Enable debug logging to check middleware status:
181
+ - Chat Completions API (`client.chat().completions().create()`)
182
+ - Embeddings API (`client.embeddings().create()`)
183
+ - Responses API (`client.responses().create()` and `client.responses().createStreaming()`)
525
184
 
526
- ```bash
527
- export REVENIUM_DEBUG=true
528
- ```
529
-
530
- **Expected output for successful tracking**:
531
-
532
- ```bash
533
- [Revenium Debug] OpenAI chat.completions.create intercepted
534
- [Revenium Debug] Revenium tracking successful
535
-
536
- # For Responses API:
537
- [Revenium Debug] OpenAI responses.create intercepted
538
- [Revenium Debug] Revenium tracking successful
539
- ```
540
-
541
- #### 2. **Environment mismatch errors**
542
-
543
- **Symptoms**: Authentication errors or 401/403 responses
544
-
545
- **Solution**: Ensure your API key matches your base URL environment:
546
-
547
- ```bash
548
- # Correct - Key and URL from same environment
549
- REVENIUM_METERING_API_KEY=hak_your_api_key_here
550
- REVENIUM_METERING_BASE_URL=https://api.revenium.io
551
-
552
- # Wrong - Key and URL from different environments
553
- REVENIUM_METERING_API_KEY=hak_wrong_environment_key
554
- REVENIUM_METERING_BASE_URL=https://api.revenium.io
555
- ```
556
-
557
- #### 3. **TypeScript type errors**
558
-
559
- **Symptoms**: TypeScript errors about `usageMetadata` property
560
-
561
- **Solution**: Ensure you're importing the middleware before OpenAI:
562
-
563
- ```typescript
564
- // Correct order
565
- import { initializeReveniumFromEnv, patchOpenAIInstance } from '@revenium/openai';
566
- import OpenAI from 'openai';
567
-
568
- // Wrong order
569
- import OpenAI from 'openai';
570
- import { initializeReveniumFromEnv, patchOpenAIInstance } from '@revenium/openai';
571
- ```
572
-
573
- #### 4. **Azure OpenAI not working**
574
-
575
- **Symptoms**: Azure OpenAI calls not being tracked
576
-
577
- **Solution**: Ensure you're using `patchOpenAIInstance()` with your Azure client:
185
+ ## Troubleshooting
578
186
 
579
- ```typescript
580
- import { AzureOpenAI } from 'openai';
581
- import { patchOpenAIInstance } from '@revenium/openai';
187
+ ### Common Issues
582
188
 
583
- // Correct
584
- const azure = patchOpenAIInstance(new AzureOpenAI({...}));
189
+ **No tracking data appears:**
585
190
 
586
- // Wrong - not patched
587
- const azure = new AzureOpenAI({...});
588
- ```
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
589
195
 
590
- #### 5. **Responses API not available**
196
+ **Client not initialized error:**
591
197
 
592
- **Symptoms**: `openai.responses.create` is undefined
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
593
201
 
594
- **Solution**: Upgrade to OpenAI SDK 5.8+ for Responses API support:
202
+ **Azure OpenAI not working:**
595
203
 
596
- ```bash
597
- npm install openai@^5.8.0
598
- ```
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
599
207
 
600
208
  ### Debug Mode
601
209
 
602
- Enable comprehensive debug logging:
210
+ Enable detailed logging by adding to your `.env`:
603
211
 
604
- ```bash
605
- export REVENIUM_DEBUG=true
212
+ ```env
213
+ REVENIUM_DEBUG=true
606
214
  ```
607
215
 
608
- This will show:
609
-
610
- - Middleware initialization status
611
- - Request interception confirmations
612
- - Metadata extraction details
613
- - Tracking success/failure messages
614
- - Error details and stack traces
615
-
616
216
  ### Getting Help
617
217
 
618
- If you're still experiencing issues:
619
-
620
- 1. **Check the logs** with `REVENIUM_DEBUG=true`
621
- 2. **Verify environment variables** are set correctly
622
- 3. **Test with minimal example** from our documentation
623
- 4. **Contact support** with debug logs and error details
218
+ If issues persist:
624
219
 
625
- For detailed troubleshooting guides, visit [docs.revenium.io](https://docs.revenium.io)
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
223
+ 4. Contact support@revenium.io with debug logs
626
224
 
627
225
  ## Supported Models
628
226
 
629
- This middleware works with all OpenAI chat completion and embedding models, including those available through Azure OpenAI.
227
+ This middleware works with any OpenAI model. For the complete model list, see the [OpenAI Models Documentation](https://platform.openai.com/docs/models).
630
228
 
631
- **For the current list of supported models, pricing, and capabilities:**
632
- - [Revenium AI Models API](https://revenium.readme.io/v2.0.0/reference/get_ai_model)
229
+ ### API Support Matrix
633
230
 
634
- Models are continuously updated as new versions are released by OpenAI and Azure OpenAI. The middleware automatically handles model detection and pricing for accurate usage tracking.
231
+ The following table shows what has been tested and verified with working examples:
635
232
 
636
- ### API Support Matrix
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 |
637
241
 
638
- | Feature | Chat Completions API | Responses API | Embeddings API |
639
- | --------------------- | -------------------- | ------------- | -------------- |
640
- | **Basic Requests** | Yes | Yes | Yes |
641
- | **Streaming** | Yes | Yes | No |
642
- | **Metadata Tracking** | Yes | Yes | Yes |
643
- | **Azure OpenAI** | Yes | Yes | Yes |
644
- | **Cost Calculation** | Yes | Yes | Yes |
645
- | **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
646
243
 
647
244
  ## Documentation
648
245
 
@@ -668,14 +265,11 @@ This project is licensed under the MIT License - see the [LICENSE](https://githu
668
265
 
669
266
  For issues, feature requests, or contributions:
670
267
 
268
+ - **Website**: [www.revenium.ai](https://www.revenium.ai)
671
269
  - **GitHub Repository**: [revenium/revenium-middleware-openai-node](https://github.com/revenium/revenium-middleware-openai-node)
672
270
  - **Issues**: [Report bugs or request features](https://github.com/revenium/revenium-middleware-openai-node/issues)
673
271
  - **Documentation**: [docs.revenium.io](https://docs.revenium.io)
674
- - **Contact**: Reach out to the Revenium team for additional support
675
-
676
- ## Development
677
-
678
- 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
679
273
 
680
274
  ---
681
275