@revenium/openai 1.0.11 → 1.0.12

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 (66) hide show
  1. package/.env.example +20 -0
  2. package/CHANGELOG.md +21 -47
  3. package/README.md +141 -690
  4. package/dist/cjs/core/config/loader.js +1 -1
  5. package/dist/cjs/core/config/loader.js.map +1 -1
  6. package/dist/cjs/core/tracking/api-client.js +1 -1
  7. package/dist/cjs/core/tracking/api-client.js.map +1 -1
  8. package/dist/cjs/index.js +2 -2
  9. package/dist/cjs/index.js.map +1 -1
  10. package/dist/cjs/utils/url-builder.js +32 -7
  11. package/dist/cjs/utils/url-builder.js.map +1 -1
  12. package/dist/esm/core/config/loader.js +1 -1
  13. package/dist/esm/core/config/loader.js.map +1 -1
  14. package/dist/esm/core/tracking/api-client.js +1 -1
  15. package/dist/esm/core/tracking/api-client.js.map +1 -1
  16. package/dist/esm/index.js +2 -2
  17. package/dist/esm/index.js.map +1 -1
  18. package/dist/esm/utils/url-builder.js +32 -7
  19. package/dist/esm/utils/url-builder.js.map +1 -1
  20. package/dist/types/index.d.ts +2 -2
  21. package/dist/types/types/index.d.ts +2 -2
  22. package/dist/types/types/index.d.ts.map +1 -1
  23. package/dist/types/utils/url-builder.d.ts +11 -3
  24. package/dist/types/utils/url-builder.d.ts.map +1 -1
  25. package/examples/README.md +250 -254
  26. package/examples/azure-basic.ts +25 -13
  27. package/examples/azure-responses-basic.ts +36 -7
  28. package/examples/azure-responses-streaming.ts +36 -7
  29. package/examples/azure-streaming.ts +40 -19
  30. package/examples/getting_started.ts +54 -0
  31. package/examples/openai-basic.ts +39 -17
  32. package/examples/openai-function-calling.ts +259 -0
  33. package/examples/openai-responses-basic.ts +36 -7
  34. package/examples/openai-responses-streaming.ts +36 -7
  35. package/examples/openai-streaming.ts +24 -13
  36. package/examples/openai-vision.ts +289 -0
  37. package/package.json +3 -9
  38. package/src/core/config/azure-config.ts +72 -0
  39. package/src/core/config/index.ts +23 -0
  40. package/src/core/config/loader.ts +66 -0
  41. package/src/core/config/manager.ts +94 -0
  42. package/src/core/config/validator.ts +89 -0
  43. package/src/core/providers/detector.ts +159 -0
  44. package/src/core/providers/index.ts +16 -0
  45. package/src/core/tracking/api-client.ts +78 -0
  46. package/src/core/tracking/index.ts +21 -0
  47. package/src/core/tracking/payload-builder.ts +132 -0
  48. package/src/core/tracking/usage-tracker.ts +189 -0
  49. package/src/core/wrapper/index.ts +9 -0
  50. package/src/core/wrapper/instance-patcher.ts +288 -0
  51. package/src/core/wrapper/request-handler.ts +423 -0
  52. package/src/core/wrapper/stream-wrapper.ts +100 -0
  53. package/src/index.ts +336 -0
  54. package/src/types/function-parameters.ts +251 -0
  55. package/src/types/index.ts +313 -0
  56. package/src/types/openai-augmentation.ts +233 -0
  57. package/src/types/responses-api.ts +308 -0
  58. package/src/utils/azure-model-resolver.ts +220 -0
  59. package/src/utils/constants.ts +21 -0
  60. package/src/utils/error-handler.ts +251 -0
  61. package/src/utils/metadata-builder.ts +219 -0
  62. package/src/utils/provider-detection.ts +257 -0
  63. package/src/utils/request-handler-factory.ts +285 -0
  64. package/src/utils/stop-reason-mapper.ts +74 -0
  65. package/src/utils/type-guards.ts +202 -0
  66. package/src/utils/url-builder.ts +68 -0
package/.env.example ADDED
@@ -0,0 +1,20 @@
1
+ # Revenium OpenAI Middleware Configuration
2
+ # Copy this file to .env and fill in your actual values
3
+
4
+ # Required: Your Revenium API key (starts with hak_)
5
+ REVENIUM_METERING_API_KEY=hak_your_revenium_api_key_here
6
+
7
+ # Optional: Revenium API base URL (defaults to https://api.revenium.io)
8
+ #REVENIUM_METERING_BASE_URL=https://api.revenium.io
9
+
10
+ # Required: Your OpenAI API key (starts with sk-)
11
+ OPENAI_API_KEY=sk_your_openai_api_key_here
12
+
13
+ # Optional: Your Azure OpenAI configuration (for Azure testing)
14
+ AZURE_OPENAI_ENDPOINT=https://your-resource-name.openai.azure.com/
15
+ AZURE_OPENAI_API_KEY=your-azure-openai-api-key-here
16
+ AZURE_OPENAI_DEPLOYMENT=your-deployment-name-here
17
+ AZURE_OPENAI_API_VERSION=2024-12-01-preview
18
+
19
+ # Optional: Enable debug logging
20
+ REVENIUM_DEBUG=false
package/CHANGELOG.md CHANGED
@@ -5,73 +5,47 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.12] - 2025-10-30
9
+
10
+ ### Changed
11
+ - Improved documentation structure and Getting Started tutorial
12
+ - Enhanced package distribution to include TypeScript source files
13
+
14
+ ### Fixed
15
+ - Repository configuration updates
16
+
8
17
  ## [1.0.11] - 2025-10-21
9
18
 
10
19
  ### Added
11
- - Examples now included in npm package for offline access
12
- - New `examples/README.md` with comprehensive step-by-step guide
13
- - Step 4: Protect Your API Keys - Security best practices in main README
14
- - TypeScript and JavaScript examples for getting started
20
+ - Examples now included in npm package
21
+ - Comprehensive examples documentation
15
22
 
16
23
  ### Changed
17
- - Removed internal QA environment references from documentation
18
- - Documentation standardized for public repository
19
- - Improved README structure with enhanced security guidance
20
-
21
- ### Security
22
- - Added `.gitignore` best practices to protect API keys
23
- - Enhanced environment variable security documentation
24
+ - Updated API endpoint configuration
25
+ - Improved documentation structure
24
26
 
25
27
  ## [1.0.10] - 2025-10-17
26
28
 
27
29
  ### Added
28
- - Support for OpenAI Responses API (SDK 5.8+)
29
- - New example files for Responses API with Azure and standard OpenAI
30
- - Enhanced TypeScript type definitions for Responses API
30
+ - Support for OpenAI Responses API
31
31
 
32
32
  ### Changed
33
- - README documentation significantly expanded with step-by-step guides
34
- - Improved examples structure and organization
35
- - Package maintenance and stability improvements
33
+ - Enhanced documentation and examples
36
34
 
37
35
  ## [1.0.9] - 2025-10-16
38
36
 
39
37
  ### Changed
40
- - Internal improvements and bug fixes
41
- - Enhanced error handling and logging
38
+ - Bug fixes and stability improvements
42
39
 
43
40
  ## [1.0.8] - 2025-10-15
44
41
 
45
42
  ### Added
46
- - Initial release of @revenium/openai scoped package
47
- - Migration from revenium-middleware-openai-node to @revenium/openai
48
- - Transparent OpenAI API usage tracking middleware
49
- - Support for streaming responses
50
- - Support for function/tool calling
51
- - Automatic metadata collection and forwarding
52
- - Azure OpenAI support with automatic detection
53
- - Full TypeScript support with native type integration
54
- - Zero configuration setup from environment variables
55
-
56
- ### Changed
57
- - Package name migrated to scoped format (@revenium/openai)
58
-
59
- ---
60
-
61
- ## Package Migration Notice
62
-
63
- This package was previously published as `revenium-middleware-openai-node` up to v1.1.0.
64
-
65
- Starting with v1.0.8, the package has been migrated to the scoped format `@revenium/openai`.
66
-
67
- The old package has been deprecated with a notice directing users to the new scoped package.
68
-
69
- To upgrade:
70
- ```bash
71
- npm uninstall revenium-middleware-openai-node
72
- npm install @revenium/openai
73
- ```
43
+ - Initial release with OpenAI usage tracking
44
+ - Support for streaming responses and function calling
45
+ - Azure OpenAI support
46
+ - TypeScript support with native type integration
74
47
 
48
+ [1.0.12]: https://github.com/revenium/revenium-middleware-openai-node/releases/tag/v1.0.12
75
49
  [1.0.11]: https://github.com/revenium/revenium-middleware-openai-node/releases/tag/v1.0.11
76
50
  [1.0.10]: https://github.com/revenium/revenium-middleware-openai-node/releases/tag/v1.0.10
77
51
  [1.0.9]: https://github.com/revenium/revenium-middleware-openai-node/releases/tag/v1.0.9