Add per-review cost estimate based on model + tokens used #28
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Idea
Every review the bot posts should include a cost estimate — model used per stage × input/output tokens × current per-token price — so the operator can see where the spend is going on a per-PR basis.
Why
Right now the gateway emits Prometheus counters (
auto_review_llm_tokens_total{tier=\"reasoning|cheap|embedding\",dir=\"input|output\"}) but there is no per-review attribution. A misconfigured tier (e.g. accidentally pointing the cheap tier at an expensive reasoning model), an oversized prompt, or a runaway agentic-verify loop is invisible until the monthly invoice. Surfacing the cost in the review body itself (and inreview history) closes that loop:Sketch
ar-llm: provider responses already surfaceusage.prompt_tokensandusage.completion_tokensfor OpenAI-compatible APIs — extend theRouterso eachcomplete()/embed()call returns aUsage { input, output, model }alongside the response. (Embedding endpoints only reportprompt_tokens.)ar-llm: introduce aPriceTablekeyed by(provider_base_url, model_name)→{ input_per_1m_usd, output_per_1m_usd, embedding_per_1m_usd }. Default it to current OpenAI public pricing for the models we ship inQUICKSTART.md. Operators override viaAR_PRICE_TABLE_PATH(TOML/JSON) so on-prem and OpenRouter / Together / Groq deployments can plug in their own rates.ar-orchestrator::dispatcher: aggregateUsageacross every LLM call in the per-PR pipeline (triage, embedding, reasoning, self-heal, verify, agentic-verify, pre-merge custom). Persist the aggregate in the review-history record alongside the existing finding count + diff size.ar-review::pipeline: append a one-line cost summary to the review markdown body — e.g. Hidden behind a default-onAR_REVIEW_COST_FOOTERenv so operators can disable it for repos where the visibility is unwanted.ar-cli status/ar-cli history: show cost per review in the existing tables; add a--since/--repofilter so an operator can answer "what did this bot cost me last week?" in one command.Out of scope
Acceptance
review-historyrecords carry the per-review aggregate so historical queries don't re-scan logs.PriceTabletest harness pins the default OpenAI rates so a price drift is visible ingit diff.AR_PRICE_TABLE_PATHallows an operator to override the table without rebuilding.