Skip to content

Conversation

@GaryZhous
Copy link
Contributor

@GaryZhous GaryZhous commented Jul 9, 2025

Built on top of #2941, this pull request enhances the goose-cli session module by introducing functionality to estimate and display cost information for token usage based on provider pricing data. It includes new methods for normalizing model names, fetching pricing data, and calculating costs, as well as configuration updates to enable cost display. Instead of hard-coding the cost calculation, I make use of Jack's Pricing_Cache which he created in #2992.

Pricing Integration:

  • Added initialize_pricing_cache to session startup: Ensures pricing cache is initialized, with error handling to log warnings if initialization fails.
  • Introduced estimate_cost_usd function: Calculates token usage cost in USD using provider pricing data and normalized model names.
  • Added display_cost_usage function: Displays cost information in USD if pricing data is available, including token breakdown.

Model Name Normalization:

  • Implemented normalize_model_name function: Cleans up model names by removing suffixes (e.g., "-latest", date-like patterns) and converting version numbers for compatibility with pricing data. Otherwise we are not able to access the pricing info from the cache since Openrouter does the model naming differently. (e.g. claude-3-5-haiku-latest is claude-3.5-haiku on Openrouter)

Configuration Updates:

  • Added configuration parameters: Introduced GOOSE_CLI_SHOW_COST to toggle cost display and GOOSE_PROVIDER to specify the provider name.

These changes collectively improve the goose-cli tool by providing users with detailed cost insights based on their session's token usage. For models whose pricing is unknown, nothing will show up.

How to enable

# one-off
GOOSE_CLI_SHOW_COST=true goose chat

# persistent
# ~/.config/goose/config.yaml
GOOSE_CLI_SHOW_COST: true

After

image
image

GaryZhous and others added 27 commits July 9, 2025 19:40
@GaryZhous GaryZhous closed this Jul 9, 2025
@GaryZhous GaryZhous deleted the GaryZ/Refine-CLI branch July 9, 2025 23:46
@GaryZhous GaryZhous changed the title feat(cli): add cost estimation per provider for Goose CLI (draft)feat: add cost estimation per provider for Goose CLI Jul 10, 2025
@GaryZhous
Copy link
Contributor Author

this is just a draft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.