feat: add CLI cost preview (openfusion ask --estimate) - #109
Open
shrdgn wants to merge 1 commit into
Open
Conversation
Wires the existing /v1/estimate logic (openfusion.estimate.build_estimate + openfusion.pricing.get_prices) into a new `--estimate` flag on `openfusion ask`, so the roadmap's planned CLI cost preview works without running the prompt or requiring an upstream API key.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--estimateflag toopenfusion askthat prints the calls/tokens/$a prompt would cost — reusing the existingopenfusion.estimate.build_estimate+openfusion.pricing.get_priceslogic that already backsPOST /v1/estimate— without running the prompt or requiring an upstream API key.Why it matters
POST /v1/estimateand the playground's live cost preview already existed, but there was no way to preview cost from the terminal before runningopenfusion ask— you had to just run it and see what it cost. This closes that gap with a small, self-contained change that reuses existing, well-tested estimate/pricing code paths.Test plan
pytest -q— 454 passed (4 new tests covering_print_estimatecost/no-pricing output and thatrun_ask(..., estimate=True)skips execution and the API-key check)ruff check .mypy openfusion/ --ignore-missing-imports --disable-error-code import-untyped --exclude openfusion/cli.pypython -c "from openfusion.cli import _ask_cli; _ask_cli(['--help'])"shows the new--estimateflagGenerated by Claude Code