Add cost estimation and context budget forecasting#1
Merged
Conversation
Introduce per-request and per-session cost estimates based on model pricing. Adds pricing.py with a lookup table for Claude and GPT models, integrates cost into the token_counter analyzer summary, CLI reporter output, and diagnosis JSON under a top-level "cost" key. Unknown models are silently skipped (no errors, no cost field).
Predict when a session will hit the context window limit based on turn-over-turn token growth rate. Adds CONTEXT_OVERFLOW_RISK diagnostic issue when overflow is projected within 2x the current turn count. New fields in session_insights.budget_forecast: - growth_rate_per_turn - current_utilization - estimated_overflow_turn - context_window_tokens - model (matched family)
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
Two new features that make context-profiler reports immediately actionable:
1. Cost Estimation (
pricing.py)Adds $/request cost estimates based on model pricing tables.
2. Budget Forecasting (
session_insights.py)Predicts when a session will overflow the context window.
budget_forecastfield in session_insights:growth_rate_per_turncurrent_utilizationestimated_overflow_turncontext_window_tokensCONTEXT_OVERFLOW_RISKTesting
tests/test_budget_forecast.py(20 test cases)Example output
{ "budget_forecast": { "growth_rate_per_turn": 10000.0, "current_utilization": 0.3906, "estimated_overflow_turn": 12, "context_window_tokens": 128000, "model": "gpt-4o" }, "cost": { "estimated_input_cost_usd": 0.001978, "estimated_model": "GPT-4o" } }