< Summary

Information
Class: OpenAiIntegration.CostBreakdown
Assembly: OpenAiIntegration
File(s): /home/runner/work/KicktippAi/KicktippAi/src/OpenAiIntegration/ICostCalculationService.cs
Line coverage
100%
Covered lines: 1
Uncovered lines: 0
Coverable lines: 1
Total lines: 67
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%

File(s)

/home/runner/work/KicktippAi/KicktippAi/src/OpenAiIntegration/ICostCalculationService.cs

#LineLine coverage
 1using OpenAI.Chat;
 2
 3namespace OpenAiIntegration;
 4
 5/// <summary>
 6/// Service for calculating and logging OpenAI API costs
 7/// </summary>
 8public interface ICostCalculationService
 9{
 10    /// <summary>
 11    /// Calculates and logs the cost breakdown for an OpenAI chat completion
 12    /// </summary>
 13    /// <param name="model">The model used for the completion</param>
 14    /// <param name="usage">The token usage information from the response</param>
 15    void LogCostBreakdown(string model, ChatTokenUsage usage);
 16
 17    /// <summary>
 18    /// Calculates and logs the cost breakdown for an OpenAI chat completion under an optional service tier.
 19    /// </summary>
 20    /// <param name="model">The model used for the completion</param>
 21    /// <param name="usage">The token usage information from the response</param>
 22    /// <param name="serviceTier">The final OpenAI service tier used for billing, if known</param>
 23    void LogCostBreakdown(string model, ChatTokenUsage usage, string? serviceTier);
 24
 25    /// <summary>
 26    /// Calculates the cost for a specific model and usage
 27    /// </summary>
 28    /// <param name="model">The model to calculate costs for</param>
 29    /// <param name="usage">The token usage information</param>
 30    /// <returns>The calculated cost, or null if pricing is not available for the model</returns>
 31    decimal? CalculateCost(string model, ChatTokenUsage usage);
 32
 33    /// <summary>
 34    /// Calculates the cost for a specific model, usage, and optional service tier.
 35    /// </summary>
 36    /// <param name="model">The model to calculate costs for</param>
 37    /// <param name="usage">The token usage information</param>
 38    /// <param name="serviceTier">The final OpenAI service tier used for billing, if known</param>
 39    /// <returns>The calculated cost, or null if pricing is not available for the model</returns>
 40    decimal? CalculateCost(string model, ChatTokenUsage usage, string? serviceTier);
 41
 42    /// <summary>
 43    /// Calculates a detailed cost breakdown for a specific model and usage.
 44    /// </summary>
 45    /// <param name="model">The model to calculate costs for</param>
 46    /// <param name="usage">The token usage information</param>
 47    /// <returns>A <see cref="CostBreakdown"/> with per-component costs, or null if pricing is not available for the mod
 48    CostBreakdown? CalculateCostBreakdown(string model, ChatTokenUsage usage);
 49
 50    /// <summary>
 51    /// Calculates a detailed cost breakdown for a specific model, usage, and optional service tier.
 52    /// </summary>
 53    /// <param name="model">The model to calculate costs for</param>
 54    /// <param name="usage">The token usage information</param>
 55    /// <param name="serviceTier">The final OpenAI service tier used for billing, if known</param>
 56    /// <returns>A <see cref="CostBreakdown"/> with per-component costs, or null if pricing is not available for the mod
 57    CostBreakdown? CalculateCostBreakdown(string model, ChatTokenUsage usage, string? serviceTier);
 58}
 59
 60/// <summary>
 61/// Detailed cost breakdown for an OpenAI API call, with per-component costs in USD.
 62/// </summary>
 63/// <param name="Input">Cost for uncached input tokens</param>
 64/// <param name="CachedInput">Cost for cached input tokens</param>
 65/// <param name="Output">Cost for output tokens</param>
 66/// <param name="Total">Total cost (input + cached input + output)</param>
 167public record CostBreakdown(decimal Input, decimal CachedInput, decimal Output, decimal Total);