Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions crates/goose-cli/src/session/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use console::{style, Color};
use goose::config::Config;
use goose::message::{Message, MessageContent, ToolRequest, ToolResponse};
use goose::providers::pricing::get_model_pricing;
use goose::providers::pricing::parse_model_id;
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use mcp_core::tool::ToolCall;
use regex::Regex;
Expand Down Expand Up @@ -732,9 +733,21 @@ async fn estimate_cost_usd(
input_tokens: usize,
output_tokens: usize,
) -> Option<f64> {
// For OpenRouter, parse the model name to extract real provider/model
let openrouter_data = if provider == "openrouter" {
parse_model_id(model)
} else {
None
};

let (provider_to_use, model_to_use) = match &openrouter_data {
Some((real_provider, real_model)) => (real_provider.as_str(), real_model.as_str()),
None => (provider, model),
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about:

    let (provider_to_use, model_to_use) = if provider == "openrouter" {
        parse_model_id(model)
            .map(|(real_provider, real_model)| (real_provider.as_str(), real_model.as_str()))
            .unwrap_or((provider, model))
    } else {
        (provider, model)
    };

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this lead to a dangling reference?


// Use the pricing module's get_model_pricing which handles model name mapping internally
let cleaned_model = normalize_model_name(model);
let pricing_info = get_model_pricing(provider, &cleaned_model).await;
let cleaned_model = normalize_model_name(model_to_use);
let pricing_info = get_model_pricing(provider_to_use, &cleaned_model).await;

match pricing_info {
Some(pricing) => {
Expand Down
Loading