Purpose\ntokentoll is positioned as "Infracost for the LLM cost domain," with the goal of detecting changes in LLM call costs during code review and preventing cost regressions from reaching production. It runs as a CI gate, statically analyzes Pull Requests, and provides a cost conclusion.\n\nKey capabilities\n- Statically analyzes LLM API calls in Python, JavaScript, and TypeScript; JS/TS is parsed via tree-sitter, supporting .js, .jsx, .ts, and .tsx.\n- Scores each PR according to custom policies in .tokentoll.yml and posts a PASS/WARN/FAIL conclusion comment on the PR; when a policy is violated, it exits with a non-zero status, causing the workflow to fail.\n- Policy rules are independent of one another; a field that is not set disables that rule.\n- A multi-round constant propagation engine can resolve model names in variable assignments, os.getenv()/process.env.X fallbacks, function defaults, class attributes, constructor arguments, dictionary and object literals, **kwargs unpacking, and Vercel AI SDK provider wrappers (such as openai("gpt-4o")).\n- Dynamic model defaults are resolved in the following order: default_models (by SDK) > default_model (generic) > built-in SDK defaults.\n- Pricing data ships with the package and can be used offline; it covers 300+ models from OpenAI, Anthropic, Google, AWS Bedrock, Azure, and others, as well as 2200+ entries in the merged LiteLLM catalog, and can be refreshed from LiteLLM as needed.\n- Includes an MCP (Model Context Protocol) server that exposes two tools, scan (estimate the cost of a given path) and diff (compare two refs), both returning JSON, for MCP hosts such as Claude Code to check the cost impact of LLM code changes during agent conversations.\n- Requires no API keys, sends no telemetry, and runs entirely in the CI environment.\n\nUsage\nAdd .github/workflows/tokentoll.yml to the repository, and add .tokentoll.y at the repository rootml (auto-discovery). Subsequent PRs will receive a conclusion comment, and PRs that exceed the threshold will cause the workflow to fail. For SHA-pinned installation and least-privilege configuration, see docs/github-action.md; for the full policy schema, see docs/policy.md; for the security posture, see docs/security.md. To refresh pricing, run the corresponding command to update from LiteLLM.\n\nUse cases\nSuitable for teams that want to establish a cost gate for LLM applications in CI, especially scenarios where LLM calls are written in Python or JS/TS and the team wants to block cost increases caused by model swaps or newly added call sites at the PR stage; it is also suitable for evaluating the cost of changes within coding conversations in MCP hosts such as Claude Code.\n\nLimitations\n- Static analysis only: models loaded from a database or remote configuration cannot be resolved, will fall back to the configured per-SDK defaults, and the call site will be marked as (default).\n- Token estimation uses the characters/4 heuristic by default unless tiktoken is installed (pip install tokentoll[tiktoken]).\n- Monthly estimates assume uniform call volume for each call site, which can be overridden per project with calls_per_month or per path with overrides.\n- JS/TS parsing is limited to the same file; model names imported from other modules produce dynamic call sites rather than resolved values.\n- Future plans include context-aware call frequency inference (FastAPI routes, scripts, loops) and cross-file import resolution for JS/TS.
tokentoll
tokentoll is a CI-oriented LLM cost gate tool that statically analyzes LLM API calls in Python, JavaScript, and TypeScript code, scores each Pull Request according to custom policies, and posts a PASS/WARN/FAIL conclusion on the PR; when a policy is violated, it can fail the workflow, thereby preventing cost regressions from being merged. It requires no API keys, sends no telemetry, ships pricing data with the package and can be used offline, and also includes an MCP server for hosts such as Claude Code to check the cost impact of code changes during conversations.