Benji
Predicts the LLM and metered-API cost impact of a code diff, and comments it on the pull request.
Infracost prices the infrastructure you declare. This prices the code that actually spends.
Static analysis knows what a diff changed. Observability knows what you already paid. Neither knows what a change about to merge is going to cost.
## 💸 Benji — cost impact
**−$462 to +$8,186 / month** · expected **+$299**
| call site | change |
|---|---|
| `api/tickets.py:handle:0` | `gpt-4o-mini` → `gpt-4o` · $0.00212/call · ×1 · 5,000/day |
| `workers/digest.py:digest:0` | **new** · $0.00022/call · ×3–500 · 1/day |
> **The range is driven almost entirely by `len(orgs)`**, which is undeclared.
> Declare it under `[iterables]` or `[frequency]` in `benji.toml`.
⚠️ This 4-line change to `LLMClient.chat` affects **47 call sites across 12 files**.
<details><summary>Coverage: 34 of 51 candidate call sites analysed</summary>
17 unresolved — 12 dynamic dispatch, 5 depth limit.
</details>
How it thinks
Every number is one of three terms, and they are never collapsed into each other:
cost per call dollars for one execution tokenizer + price table
× multiplicity firings per invocation AST: loops, guards, retries
× frequency invocations per day your declaration, or telemetry
─────────────────
= dollars per day
They use different machinery, fail in different ways, and change on different timescales. Keeping them apart is what lets the bot say why a number moved — a price change and a traffic change need opposite responses.
Three rules follow from that, and they are the whole personality of the tool:
- Never a point estimate. A confident
+$127.40/mothat is wrong by ten times is worse than saying nothing. Everything is a range, and the bot names the factor driving its width. - Never a guess. An unresolvable model or an unbounded loop returns nothing, and the comment says which layer was missing. Unknown is a real answer.
- Always report coverage. "Analysed 34 of 51" turns a miss from silent into visible.
Deterministic code computes every figure. A language model may write prose or classify an ambiguous call; it never produces a number.
Install
# .github/workflows/benji.yml
name: benji
on: pull_request
permissions:
contents: read
jobs:
analyse:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- uses: 1Kyryll/Benji/action@v1
- uses: actions/upload-artifact@v4
with:
name: benji-report
path: benji-report.json
Posting the comment is a second workflow, and that is deliberate. On a pull request from a fork,
GITHUB_TOKEN is read-only: the analysis succeeds and the comment fails with a 403. The fix is to
analyse without privileges and post from a workflow_run job the fork cannot reach. Copy
benji-comment.yml as-is.
Never use pull_request_target with a checkout of the head ref. That is the well-known way to hand
a stranger write access to your repository.
Locally:
pip install benji-bot # `benji` on PyPI is an unrelated backup tool
benji diff HEAD~1 HEAD # or: python -m benji.cli diff HEAD~1 HEAD
Configure
Optional. Without it you still get cost per call and multiplicity; you do not get dollars per day, and the comment says so rather than guessing.
# benji.toml
[frequency]
"api.tickets:TicketService.handle" = { low = 2000, expected = 5000, high = 20000 }
"workers.digest:run" = 1
[iterables]
"handle:orgs" = { low = 3, expected = 40, high = 500 }
Declare entry points, not call sites. Nobody knows how often LLMClient.chat runs; everybody
knows roughly how many tickets arrive in a day. The bot carries the number down the call graph to
every metered call it reaches.
See benji.example.toml.
What it detects
Python, OpenAI and Anthropic, in four shapes:
| shape | example | confidence |
|---|---|---|
| SDK | client.chat.completions.create(model=...) |
exact |
| raw HTTP | session.post(f"{url}/v1/chat/completions", json={"model": ...}) |
exact |
| first-party wrapper | self.llm.chat(...) resolved to the SDK call underneath |
decays with depth |
| framework | llm.invoke(...), or self.llm(messages) — LangChain and friends |
reduced |
Wrapper resolution follows attribute types from annotations, constructor assignments, module
singletons and local assignments, stopping at a metered call, a cycle, depth 5, or the repository
boundary. It never parses site-packages.
Editing a wrapper is not a local change. A reverse call graph finds every site that reaches the function you touched, across files the diff never opened.
Measured on 11 real open-source Python applications: 78% of candidate call sites resolved.
Not in this version
Languages other than Python · own OTLP ingest · agent-loop analysis · merge gating · a dashboard.
Telemetry-backed frequency is the destination, not an alternative to the config file: the
FrequencySource interface exists so a Langfuse adapter is an addition rather than a rewrite.
Release
Publishing runs on a GitHub Release via Trusted Publishing — no API token is stored anywhere. The workflow runs the tests, checks the release tag matches the version in pyproject.toml, and only then uploads.
# bump version in pyproject.toml, commit, then
gh release create v0.1.0 --generate-notes
Develop
pip install -e ".[dev]"
pytest -q
ruff check . && ruff format .
python -m corpus.score --sample 20 # coverage against pinned real repositories
corpus/ is the fitness function, and it keeps its own copy of the call-detection logic on purpose:
a measuring instrument that shares code with the system it measures agrees with its own bugs.
Licence
MIT.
Metadata
Release files for benji-bot 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| benji_bot-0.1.0.tar.gz | 69.3 kB | With provenance | Details for benji_bot-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| benji_bot-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for benji_bot-0.1.0-py3-none-any.whl |
Total release size: 123.7 kB
Release files / benji_bot-0.1.0.tar.gz
| Download URL | benji_bot-0.1.0.tar.gz |
|---|---|
| Size | 69.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e1081669857d22ecf25d1d10e18c7e65053a960e59463881842142222c153905
|
|
BLAKE2b-256 checksum How to use checksums |
c5d4f273dc3818e4988582a0fc7d5fb21a90a06ecf915f4c57d20c727f9cbd41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.
Transparency logRelease files / benji_bot-0.1.0-py3-none-any.whl
| Download URL | benji_bot-0.1.0-py3-none-any.whl |
|---|---|
| Size | 54.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
98a70331e2ea12b0ef3fc2517fe0985ce866a76fd9ebb1a5e0d5527b90bc7369
|
|
BLAKE2b-256 checksum How to use checksums |
d9e3baddd6eeaffd5419b6efe2715bde4333b7dab1d89013c3782f0528474856
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.
Transparency logSecurity for benji-bot 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for benji_bot-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.