@mate-academy/llm-gateway 7.5.1 → 7.6.1

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 (29) hide show
  1. package/README.md +26 -0
  2. package/dist/LLMService.constants.d.ts +8930 -6066
  3. package/dist/LLMService.typedefs.d.ts +27 -0
  4. package/dist/LLMService.typedefs.js.map +1 -1
  5. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAICompletion.service.js +17 -10
  6. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAICompletion.service.js.map +1 -1
  7. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAISpeechToText.service.js +10 -6
  8. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAISpeechToText.service.js.map +1 -1
  9. package/dist/providers/LLMAPI/LLMAPI.constants.d.ts +13949 -9653
  10. package/dist/providers/LLMAPI/LLMAPI.constants.js +2778 -2073
  11. package/dist/providers/LLMAPI/LLMAPI.constants.js.map +1 -1
  12. package/dist/providers/LLMAPI/LLMAPI.typedefs.d.ts +96 -39
  13. package/dist/providers/LLMAPI/LLMAPI.typedefs.js +114 -37
  14. package/dist/providers/LLMAPI/LLMAPI.typedefs.js.map +1 -1
  15. package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.js +3 -1
  16. package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.js.map +1 -1
  17. package/dist/providers/LLMAPI/services/LLMAPICompletion.service.js +25 -13
  18. package/dist/providers/LLMAPI/services/LLMAPICompletion.service.js.map +1 -1
  19. package/dist/providers/LLMAPI/utilities/LLMAPIJsonFixer.d.ts +2 -0
  20. package/dist/providers/LLMAPI/utilities/LLMAPIJsonFixer.js +15 -7
  21. package/dist/providers/LLMAPI/utilities/LLMAPIJsonFixer.js.map +1 -1
  22. package/dist/providers/OpenAICompatible/OpenAICompatibleCompletion.service.js +5 -0
  23. package/dist/providers/OpenAICompatible/OpenAICompatibleCompletion.service.js.map +1 -1
  24. package/dist/providers/OpenAICompatible/OpenAICompatibleSpeechToText.service.js +2 -1
  25. package/dist/providers/OpenAICompatible/OpenAICompatibleSpeechToText.service.js.map +1 -1
  26. package/dist/utilities/calculateCosts.d.ts +3 -16
  27. package/dist/utilities/calculateCosts.js +20 -0
  28. package/dist/utilities/calculateCosts.js.map +1 -1
  29. package/package.json +1 -1
package/README.md CHANGED
@@ -547,6 +547,32 @@ if (result.data) {
547
547
  }
548
548
  ```
549
549
 
550
+ #### Token Usage and Cost
551
+
552
+ Successful completion and transcription results expose two optional fields: `usage`
553
+ (`LLMModelUsage`) with the provider-reported token counts, and `cost`
554
+ (`LLMCostsResult`) with the absolute USD cost for the call, derived from that usage
555
+ and the model's pricing. Both are present only on the success branch (absent when
556
+ `result.error` is set), so read them after narrowing:
557
+
558
+ ```typescript
559
+ const result = await completionService.sendMessage({
560
+ message: { /* ... */ },
561
+ model: preferredModel,
562
+ schema: mySchema,
563
+ });
564
+
565
+ if (!('error' in result) && result.usage) {
566
+ console.log('Input tokens:', result.usage.inputTextTokens);
567
+ console.log('Output tokens:', result.usage.outputTextTokens);
568
+ console.log('Total cost (USD):', result.cost?.total);
569
+ }
570
+ ```
571
+
572
+ For the LLMAPI provider, the structured-output result's `usage` (and the `cost`
573
+ derived from it) includes the JSON-fix call's tokens (summed into the primary
574
+ call's usage) when a fix was required.
575
+
550
576
  #### Provider Support
551
577
 
552
578
  - **OpenAI**: Uses native `response_format` with `json_schema` for optimal performance