Skip to main content

display_ai_usage

Function display_ai_usage 

Source
pub fn display_ai_usage(usage: &AiUsage)
Expand description

Display comprehensive AI API usage statistics and cost information.

Presents detailed information about AI API calls including token usage, model information, and cost implications. This helps users understand their AI service consumption and manage usage costs effectively.

§Information Displayed

  • Model Name: The specific AI model used for processing
  • Token Breakdown: Detailed token usage by category
    • Prompt tokens: Input text sent to the AI
    • Completion tokens: AI-generated response text
    • Total tokens: Sum of prompt and completion tokens
  • Cost Implications: Helps users understand billing impact

§Format Example

🤖 AI API Call Details:
   Model: gpt-4-turbo-preview
   Prompt tokens: 1,247
   Completion tokens: 892
   Total tokens: 2,139

§Arguments

  • usage - Core-owned usage payload containing token counts and model information (subx_core::core::report::AiUsage, reachable under its legacy alias subx_core::services::ai::AiUsageStats)

Core and service modules no longer call this helper. Its only caller is crate::cli::reporter::TerminalReporter’s ai_usage channel — the single place where core AI-usage reporting reaches the terminal.

§Examples

use subx_cli::cli::ui::display_ai_usage;
use subx_cli::services::ai::AiUsageStats;

let usage = AiUsageStats {
    model: "gpt-4-turbo-preview".to_string(),
    prompt_tokens: 1247,
    completion_tokens: 892,
    total_tokens: 2139,
};

display_ai_usage(&usage);

§Use Cases

  • Cost monitoring: Track API usage for billing awareness
  • Performance analysis: Understand token efficiency
  • Debugging: Verify expected model usage
  • Optimization: Identify opportunities to reduce token consumption