Skip to content

Add LLM cost change analysis to CI - #30

Open
Jwrede wants to merge 1 commit into
federicodeponte:masterfrom
Jwrede:add-tokentoll-cost-analysis
Open

Add LLM cost change analysis to CI#30
Jwrede wants to merge 1 commit into
federicodeponte:masterfrom
Jwrede:add-tokentoll-cost-analysis

Conversation

@Jwrede

@Jwrede Jwrede commented May 4, 2026

Copy link
Copy Markdown

Summary

Add tokentoll GitHub Action to analyze LLM API cost changes on pull requests.

When a PR modifies code that makes LLM API calls (model swaps, max_tokens changes, new call sites), tokentoll posts a comment showing the projected cost impact. It stays silent on PRs that don't touch LLM code.

What it detects

tokentoll uses Python AST analysis (zero runtime dependencies) to find calls to:

  • OpenAI (chat.completions.create, responses.create, embeddings.create)
  • Anthropic (messages.create)
  • Google GenAI (generate_content)
  • LiteLLM (completion, embedding)
  • LangChain (ChatOpenAI, ChatAnthropic, init_chat_model)
  • Zhipu AI / GLM (ZhipuAiClient, ZhipuAI)

Current scan of this project

tokentoll Scan Report

File Line SDK Model Est. Cost/Call Monthly
engine/utils/api_tier_detector.py 145 google_genai gemini-2.5-flash $0.000013 $0.01
engine/utils/gemini_client.py 122 google_genai gemini-2.0-flash (default) $0.000869 $0.87
engine/utils/revise.py 136 google_genai gemini-3-flash-preview $0.05 $49.40

Total estimated monthly cost: $50.28

Assumptions
  • 1000 calls/month per call site

Generated by tokentoll

How it works

  • Runs only on PRs, compares base vs head
  • Posts a sticky comment (updates in place, no duplicates)
  • Only comments when LLM calls are added, removed, or modified
  • First run posts an initial scan (this PR) so you can see the output
  • Zero runtime dependencies, ~1s scan time for most projects
  • PyPI | GitHub

Changes

  • Adds .github/workflows/llm-costs.yml (17 lines)
  • No code changes, no new dependencies

Adds a CI workflow that runs tokentoll on pull requests to detect
changes in LLM API calls (model swaps, new call sites, removed
endpoints) and posts the cost impact as a PR comment.

The action is pinned to SHA 753ca4d1150c74169b52a843439049b65e256d2b (v0.6.1) and installs
tokentoll==v0.6.1 from PyPI. Zero runtime dependencies.
@federicodeponte

Copy link
Copy Markdown
Owner

Maintainer triage after the Quality Gates fix and #43 packaging merge: leaving this unmerged.

This adds a new PR workflow with pull-requests: write permission and a third-party action that comments on PRs. Even though the action is SHA-pinned, it changes CI behavior for every PR and has no checks reported here. Needs maintainer approval for the bot/commenting behavior before merge.

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.

2 participants