plutus-agent 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. plutus_agent-0.2.0/BILLING.md +63 -0
  2. plutus_agent-0.2.0/CHANGELOG.md +39 -0
  3. plutus_agent-0.2.0/LICENSE +21 -0
  4. plutus_agent-0.2.0/MANIFEST.in +6 -0
  5. plutus_agent-0.2.0/PKG-INFO +253 -0
  6. plutus_agent-0.2.0/README.md +214 -0
  7. plutus_agent-0.2.0/ROADMAP.md +183 -0
  8. plutus_agent-0.2.0/docs/claude-code.md +53 -0
  9. plutus_agent-0.2.0/examples/claude_code_hook.py +66 -0
  10. plutus_agent-0.2.0/examples/hermes_integration.py +59 -0
  11. plutus_agent-0.2.0/examples/quickstart.py +38 -0
  12. plutus_agent-0.2.0/plutus_agent/__init__.py +39 -0
  13. plutus_agent-0.2.0/plutus_agent/__main__.py +7 -0
  14. plutus_agent-0.2.0/plutus_agent/alerts.py +116 -0
  15. plutus_agent-0.2.0/plutus_agent/billing/__init__.py +8 -0
  16. plutus_agent-0.2.0/plutus_agent/billing/stripe_client.py +262 -0
  17. plutus_agent-0.2.0/plutus_agent/bridge.py +32 -0
  18. plutus_agent-0.2.0/plutus_agent/cli.py +449 -0
  19. plutus_agent-0.2.0/plutus_agent/client.py +83 -0
  20. plutus_agent-0.2.0/plutus_agent/config.py +171 -0
  21. plutus_agent-0.2.0/plutus_agent/db.py +294 -0
  22. plutus_agent-0.2.0/plutus_agent/demo.py +114 -0
  23. plutus_agent-0.2.0/plutus_agent/integrations/__init__.py +14 -0
  24. plutus_agent-0.2.0/plutus_agent/integrations/adapters.py +74 -0
  25. plutus_agent-0.2.0/plutus_agent/integrations/claude_code_hook.py +80 -0
  26. plutus_agent-0.2.0/plutus_agent/metering.py +312 -0
  27. plutus_agent-0.2.0/plutus_agent/pricing.py +177 -0
  28. plutus_agent-0.2.0/plutus_agent/reports.py +277 -0
  29. plutus_agent-0.2.0/plutus_agent/server/__init__.py +4 -0
  30. plutus_agent-0.2.0/plutus_agent/server/api.py +36 -0
  31. plutus_agent-0.2.0/plutus_agent/server/app.py +242 -0
  32. plutus_agent-0.2.0/plutus_agent/server/views.py +342 -0
  33. plutus_agent-0.2.0/plutus_agent.egg-info/PKG-INFO +253 -0
  34. plutus_agent-0.2.0/plutus_agent.egg-info/SOURCES.txt +40 -0
  35. plutus_agent-0.2.0/plutus_agent.egg-info/dependency_links.txt +1 -0
  36. plutus_agent-0.2.0/plutus_agent.egg-info/entry_points.txt +2 -0
  37. plutus_agent-0.2.0/plutus_agent.egg-info/requires.txt +16 -0
  38. plutus_agent-0.2.0/plutus_agent.egg-info/top_level.txt +1 -0
  39. plutus_agent-0.2.0/pyproject.toml +60 -0
  40. plutus_agent-0.2.0/setup.cfg +4 -0
  41. plutus_agent-0.2.0/tests/test_engine.py +272 -0
  42. plutus_agent-0.2.0/tests/test_server.py +83 -0
@@ -0,0 +1,63 @@
1
+ # Billing setup — get Plutus accepting money in ~10 minutes
2
+
3
+ Plutus runs fully offline until you add a Stripe key. This is the end-to-end
4
+ flow to take a real (test-mode) payment and watch prepaid credit top up.
5
+
6
+ ## 0. Prerequisites
7
+ ```bash
8
+ pip install "plutus-agent[stripe]"
9
+ plutus init --org "Your Co" --tier pro
10
+ ```
11
+ Grab your **test-mode** keys from the Stripe dashboard (Developers → API keys).
12
+ Always start in test mode (`sk_test_…`).
13
+
14
+ ## 1. Point Plutus at Stripe
15
+ ```bash
16
+ export STRIPE_SECRET_KEY=sk_test_xxx
17
+ export STRIPE_PUBLISHABLE_KEY=pk_test_xxx
18
+ export STRIPE_WEBHOOK_SECRET=whsec_xxx # from step 3
19
+ ```
20
+ Or put them in `~/.plutus/config.yaml` under `billing:` (env wins).
21
+
22
+ ## 2. Create the Pro plan
23
+ ```bash
24
+ plutus stripe-setup
25
+ ```
26
+ This creates a **Plutus Pro** product + a `$20/mo` recurring price (idempotent
27
+ via the `plutus_pro_monthly` lookup key) and writes the price id into your
28
+ config. Credit top-ups are priced dynamically per checkout, so nothing else to
29
+ create.
30
+
31
+ ## 3. Run the server + forward webhooks
32
+ ```bash
33
+ plutus serve # dashboard at http://localhost:8420
34
+ # in another terminal (Stripe CLI):
35
+ stripe listen --forward-to localhost:8420/webhook/stripe
36
+ ```
37
+ `stripe listen` prints a `whsec_…` — that's your `STRIPE_WEBHOOK_SECRET` for
38
+ step 1. Restart `plutus serve` after setting it.
39
+
40
+ ## 4. Take a payment
41
+ On the dashboard's **Billing** panel: enter an amount → **Top up →** → pay with
42
+ Stripe's test card `4242 4242 4242 4242` (any future expiry / CVC). Or fire a
43
+ synthetic event:
44
+ ```bash
45
+ stripe trigger checkout.session.completed
46
+ ```
47
+ On `checkout.session.completed`, Plutus credits the org's ledger and the
48
+ **Credit balance** card updates on the next 5-second refresh. "Upgrade to Pro"
49
+ moves the org to the `pro` tier; the Customer Portal button manages the
50
+ subscription.
51
+
52
+ ## 5. Go live
53
+ Swap `sk_test_…`/`pk_test_…`/`whsec_…` for live keys, register a production
54
+ webhook endpoint in the Stripe dashboard pointing at
55
+ `https://your-host/webhook/stripe`, and re-run `plutus stripe-setup` once
56
+ against the live key to create the live price.
57
+
58
+ ## How it's safe
59
+ - Webhooks are **signature-verified** and recorded by event id — a replay never
60
+ double-credits (`stripe_events` table).
61
+ - The credit balance is the **sum of an append-only ledger**, so it's auditable
62
+ and can't silently drift.
63
+ - No Stripe key → Checkout is simply disabled and everything else runs offline.
@@ -0,0 +1,39 @@
1
+ # Changelog
2
+
3
+ All notable changes to Plutus are documented here.
4
+
5
+ ## [0.2.0] — 2026-06-21
6
+
7
+ The **monetization engine** — Plutus becomes the billing layer for AI agents.
8
+
9
+ ### Added
10
+ - **`plutus_agent` package** (PyPI `plutus-agent`, console command `plutus`).
11
+ - **Multi-tenant model** — organizations → workspaces → users, in SQLite.
12
+ - **Usage metering** per provider / model / task-type, with token→cost
13
+ estimation and exact-cost passthrough.
14
+ - **Prepaid credit** — append-only ledger that depletes as calls route through;
15
+ balance is the sum of deltas (robust to out-of-order / back-filled inserts).
16
+ - **Dark dashboard** at `:8420` (`plutus serve`) — brand `#0c0814`, real-time
17
+ cards, per-workspace budget bars, provider health, cost-per-task, live feed.
18
+ Framework-free (stdlib `http.server`).
19
+ - **`plutus serve --demo` / `plutus demo`** — realistic month of sample data.
20
+ - **Stripe billing** — Checkout for prepaid credits + the $20/mo Pro plan,
21
+ Customer Portal, and an idempotent webhook handler. Optional + offline-safe.
22
+ - **`plutus stripe-setup`** — creates the Pro price in your Stripe account.
23
+ - **`plutus install-claude-hook`** — wires Plutus into Claude Code / Codex as a
24
+ Stop hook so every turn meters automatically.
25
+ - **Monthly reports** — PDF (reportlab) or print-ready HTML.
26
+ - **Alerts** — SMTP low-balance and budget-cap email, de-duped, offline-safe.
27
+ - **Pricing tiers** — Free / Pro / Enterprise.
28
+ - **Embeddable client** — `from plutus_agent import Meter`.
29
+ - **Integrations** — Anthropic / OpenAI / Hermes adapters; runnable examples.
30
+ - **Packaging** — `pyproject.toml`, Dockerfile, docker-compose, GHCR + PyPI
31
+ release workflow, expanded CI.
32
+
33
+ ### Unchanged
34
+ - The live credit monitor (`plutus.py`) and runway router (`plutus_route.py`)
35
+ are left byte-for-byte intact. The engine bridges to them via subprocess.
36
+
37
+ ## [0.1.0]
38
+ - Provider credit & spend monitor (`plutus.py`) and runway-based model router
39
+ (`plutus_route.py`) for Hermes Agent.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Perseus Computing LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ include README.md LICENSE ROADMAP.md CHANGELOG.md BILLING.md
2
+ recursive-include docs *.md
3
+ recursive-include plutus_agent/assets *
4
+ recursive-include examples *.py
5
+ graft tests
6
+ global-exclude *.pyc __pycache__ *.db *.db-wal *.db-shm
@@ -0,0 +1,253 @@
1
+ Metadata-Version: 2.4
2
+ Name: plutus-agent
3
+ Version: 0.2.0
4
+ Summary: The billing layer for AI agents — self-hosted, Stripe-integrated usage metering and prepaid-credit billing for LLM/agent spend.
5
+ Author-email: Thomas Connally <tcconnally@gmail.com>
6
+ Maintainer: Perseus Computing LLC
7
+ License: MIT
8
+ Project-URL: Homepage, https://perseus.observer/plutus/
9
+ Project-URL: Repository, https://github.com/Perseus-Computing-LLC/plutus
10
+ Project-URL: Issues, https://github.com/Perseus-Computing-LLC/plutus/issues
11
+ Keywords: llm,billing,metering,finops,ai-agents,stripe,usage-based-billing,cost-tracking,openai,anthropic
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Web Environment
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Office/Business :: Financial
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.9
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: PyYAML>=5.4
27
+ Provides-Extra: stripe
28
+ Requires-Dist: stripe>=7.0; extra == "stripe"
29
+ Provides-Extra: pdf
30
+ Requires-Dist: reportlab>=4.0; extra == "pdf"
31
+ Provides-Extra: all
32
+ Requires-Dist: stripe>=7.0; extra == "all"
33
+ Requires-Dist: reportlab>=4.0; extra == "all"
34
+ Provides-Extra: dev
35
+ Requires-Dist: stripe>=7.0; extra == "dev"
36
+ Requires-Dist: reportlab>=4.0; extra == "dev"
37
+ Requires-Dist: pytest>=7.0; extra == "dev"
38
+ Dynamic: license-file
39
+
40
+ # Plutus — the billing layer for AI agents
41
+
42
+ [![Test](https://github.com/Perseus-Computing-LLC/plutus/actions/workflows/test.yml/badge.svg)](https://github.com/Perseus-Computing-LLC/plutus/actions/workflows/test.yml)
43
+ [![PyPI](https://img.shields.io/pypi/v/plutus-agent.svg)](https://pypi.org/project/plutus-agent/)
44
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
45
+
46
+ > **You wouldn't run a SaaS without billing. Don't run AI agents without Plutus.**
47
+
48
+ Plutus is **self-hosted, Stripe-integrated usage metering and prepaid-credit billing for LLM / AI-agent spend.** Point your agents at it and you get a real-time dark dashboard of where the money goes — per organization, per workspace, per provider, per task type — with prepaid credits that deplete as calls route through, low-balance and budget-cap alerts, and monthly PDF spend reports.
49
+
50
+ Everything except Stripe works **fully offline**. State is a single SQLite file. No Plutus cloud. No lock-in.
51
+
52
+ ```bash
53
+ pip install plutus-agent
54
+ plutus demo # → dark dashboard with realistic data at http://localhost:8420
55
+ ```
56
+
57
+ <p align="center"><em>◆ <a href="https://perseus.observer/plutus/">perseus.observer/plutus</a> · Perseus Computing LLC</em></p>
58
+
59
+ ---
60
+
61
+ ## Start in 30 seconds
62
+
63
+ ```bash
64
+ pip install plutus-agent # PyPI; stdlib + PyYAML, Stripe optional
65
+ plutus demo # zero-setup tour with a month of sample data
66
+ # → open http://localhost:8420
67
+ ```
68
+
69
+ **Running Claude Code or Codex?** See exactly where your spend goes, per project, in one command:
70
+
71
+ ```bash
72
+ plutus install-claude-hook # meters every Claude Code turn automatically
73
+ plutus serve # → http://localhost:8420
74
+ ```
75
+
76
+ → [docs/claude-code.md](docs/claude-code.md)
77
+
78
+ Real setup is three commands:
79
+
80
+ ```bash
81
+ plutus init --org "Acme Agents" --tier pro --workspace ci --budget 100
82
+ plutus topup --amount 50 # add prepaid credit (Stripe does this in prod)
83
+ plutus meter --provider anthropic --model claude-opus-4-8 \
84
+ --task code_review --workspace ci --input 8200 --output 2400
85
+ plutus serve # your live dashboard at :8420
86
+ ```
87
+
88
+ Or in your agent code:
89
+
90
+ ```python
91
+ from plutus_agent import Meter
92
+
93
+ plutus = Meter(org="Acme Agents")
94
+ resp = client.messages.create(model="claude-opus-4-8", ...)
95
+ plutus.track(provider="anthropic", model="claude-opus-4-8",
96
+ task_type="code_review", workspace="ci",
97
+ input_tokens=resp.usage.input_tokens,
98
+ output_tokens=resp.usage.output_tokens)
99
+ print(plutus.balance()) # remaining prepaid credit
100
+ ```
101
+
102
+ ## What you get
103
+
104
+ | | |
105
+ |---|---|
106
+ | **Real-time dashboard** | Dark-themed (`#0c0814`), spend today/7d/30d/MTD, per-workspace budget bars, provider health, cost-per-task ROI, live activity feed. Numbers refresh every 5s. `plutus serve` at `:8420`. |
107
+ | **Multi-tenant** | Organizations → workspaces → users. Meter per workspace, per provider, per model, per task type. |
108
+ | **Prepaid credits** | An append-only ledger that depletes as calls route through. Balance is always the sum of deltas — auditable, never drifts. |
109
+ | **Stripe billing** | Checkout Sessions for credit top-ups + the $20/mo Pro plan, the Customer Portal for self-serve management, and an **idempotent** webhook handler. Test-mode friendly. |
110
+ | **Alerts** | Email on low balance or when a workspace nears/exceeds its monthly budget cap. De-duped, offline-safe (dry-run without SMTP). |
111
+ | **Monthly reports** | Print-ready spend reports — PDF when `reportlab` is installed, clean HTML otherwise. |
112
+ | **Pricing tiers** | Free (10K tracked tokens/mo, 1 workspace), Pro ($20/mo, unlimited tracking, 10 workspaces, credits + alerts + reports), Enterprise (custom, SSO, SLA). |
113
+
114
+ ## Why Plutus — vs. the alternatives
115
+
116
+ | | Manual console-checking | Spreadsheet | **Nothing** | **Plutus** |
117
+ |---|:---:|:---:|:---:|:---:|
118
+ | One view across all providers | ❌ (one console each) | 🟡 (you paste it) | ❌ | ✅ |
119
+ | Real-time | ❌ | ❌ | ❌ | ✅ (5s refresh) |
120
+ | Per-workspace / per-task attribution | ❌ | 🟡 | ❌ | ✅ |
121
+ | Prepaid credit that auto-depletes | ❌ | ❌ | ❌ | ✅ |
122
+ | Low-balance / budget alerts | ❌ | ❌ | ❌ | ✅ |
123
+ | Charge *your* customers (Stripe) | ❌ | ❌ | ❌ | ✅ |
124
+ | Cost to run | your time | your time | a surprise invoice | one SQLite file |
125
+
126
+ If you run agents and you're tracking spend by logging into three billing consoles — or not at all — you already need this.
127
+
128
+ ## The dashboard
129
+
130
+ `plutus serve` (or `plutus demo`) serves a single dark pane at **`:8420`**:
131
+
132
+ - **Headline cards** — credit balance (turns coral when low), spend today, month-to-date, tracked-tokens-vs-plan meter.
133
+ - **Spend by workspace** — with budget-cap progress bars that go coral past 80%.
134
+ - **Providers** — health dot (live/idle/stale), trailing `$/day` burn, last-seen.
135
+ - **Cost per task type** — the ROI lens: `$/task` for code review vs chat vs research.
136
+ - **Live activity** — the most recent metered calls, estimated vs exact.
137
+ - **Billing** — buy prepaid credit, upgrade to Pro, or open the Stripe Customer Portal.
138
+
139
+ It's framework-free (stdlib `http.server`), CSP-safe, and serves the same on a laptop or a `$5` VPS.
140
+
141
+ ## Stripe (test mode)
142
+
143
+ Plutus runs fully offline until you give it a key. Then:
144
+
145
+ ```bash
146
+ export STRIPE_SECRET_KEY=sk_test_... # start in test mode
147
+ plutus stripe-setup # creates the $20/mo Pro price for you
148
+ plutus serve
149
+ stripe listen --forward-to localhost:8420/webhook/stripe # local dev
150
+ ```
151
+
152
+ Full walkthrough — take a test payment and watch credit top up — in **[BILLING.md](BILLING.md)**.
153
+
154
+ - **Buy credit** → one-time Checkout Session → `checkout.session.completed` tops up the ledger.
155
+ - **Upgrade to Pro** → subscription Checkout → subscription webhooks move the org between `pro`/`free`.
156
+ - **Manage billing** → Stripe Customer Portal.
157
+ - Every webhook is verified and recorded by event id, so a replay never double-credits.
158
+
159
+ ## Deploy with Docker
160
+
161
+ ```bash
162
+ docker compose up # dashboard at http://localhost:8420 (demo data)
163
+ # real use:
164
+ docker run -p 8420:8420 -v plutus:/data \
165
+ -e STRIPE_SECRET_KEY=sk_test_... \
166
+ ghcr.io/perseus-computing-llc/plutus serve --host 0.0.0.0
167
+ ```
168
+
169
+ State persists in the `/data` volume (`config.yaml` + `plutus.db`).
170
+
171
+ ## Integrations
172
+
173
+ Thin, dependency-free adapters in [`plutus_agent/integrations`](plutus_agent/integrations) and runnable [`examples/`](examples):
174
+
175
+ - **Anthropic / OpenAI SDKs** — `track_anthropic(meter, response)` / `track_openai(meter, response)` read `response.usage` for you.
176
+ - **Hermes Agent** — push each session as it completes, or back-fill an existing `state.db` ([`examples/hermes_integration.py`](examples/hermes_integration.py)).
177
+ - **Claude Code / Codex CLI** — `plutus install-claude-hook` wires a `Stop` hook that meters every turn, attributed per project ([docs/claude-code.md](docs/claude-code.md)).
178
+
179
+ ## CLI
180
+
181
+ ```text
182
+ plutus init create ~/.plutus/{config.yaml,plutus.db}
183
+ plutus serve run the dashboard + API at :8420 (--demo for sample data)
184
+ plutus demo serve with realistic sample data (zero setup)
185
+ plutus status orgs, balances, Stripe mode
186
+ plutus org create | list organizations
187
+ plutus workspace create | list workspaces (--budget for a monthly cap)
188
+ plutus meter record a usage event (depletes credit)
189
+ plutus topup add prepaid credit
190
+ plutus report monthly PDF/HTML spend report (--month YYYY-MM)
191
+ plutus alerts deliver pending low-balance / budget alerts
192
+ plutus stripe-setup create the $20/mo Pro price in your Stripe account
193
+ plutus install-claude-hook meter Claude Code / Codex turns automatically
194
+ plutus monitor print live provider runway (bridges to plutus.py)
195
+ plutus pricing show plan tiers
196
+ ```
197
+
198
+ ## Configuration
199
+
200
+ `~/.plutus/config.yaml` (created by `plutus init`). Secrets prefer environment variables:
201
+
202
+ | Env var | Purpose |
203
+ |---|---|
204
+ | `PLUTUS_HOME` | Plutus home dir (default `~/.plutus`) |
205
+ | `PLUTUS_DB` / `PLUTUS_PORT` | Override DB path / dashboard port |
206
+ | `STRIPE_SECRET_KEY` / `STRIPE_PUBLISHABLE_KEY` | Stripe API keys |
207
+ | `STRIPE_WEBHOOK_SECRET` / `STRIPE_PRICE_PRO` | Webhook signing secret / Pro Price ID |
208
+ | `PLUTUS_SMTP_PASSWORD` | SMTP password for alert email |
209
+
210
+ Provider price tables (used to *estimate* cost from tokens when an exact cost isn't supplied) are overridable under `pricing.overrides`.
211
+
212
+ ---
213
+
214
+ ## The credit monitor (`plutus.py`)
215
+
216
+ Plutus started as — and still ships — a **provider credit & spend monitor + runway-based model router** for [Hermes Agent](https://github.com/NousResearch/hermes-agent). These run independently of the billing engine and remain the live FinOps tooling:
217
+
218
+ - **`plutus.py`** — live DeepSeek balance API + Hermes `state.db` ledger fused per provider; CLI / `--json` / `--html` dashboard; `--calibrate` back-solves budgets for providers without a balance API.
219
+ - **`plutus_route.py`** — ranks providers by projected days-left and rewrites Hermes routing (primary / delegation / fallbacks), with backup + round-trip verification + a no-op guard so a config write can never lose a key.
220
+
221
+ ```bash
222
+ python3 plutus.py # pretty CLI table
223
+ python3 plutus.py --calibrate anthropic=74.46
224
+ python3 plutus_route.py --dry-run # preview runway-based routing
225
+ ```
226
+
227
+ The billing engine can fold this live runway into its dashboard — set `monitor.enabled` + `monitor.command` in `config.yaml`, or run `plutus monitor`. See the original monitor docs in [`ROADMAP.md`](ROADMAP.md) and [`HANDOFF.md`](HANDOFF.md).
228
+
229
+ ## Layout
230
+
231
+ ```
232
+ plutus.py, plutus_route.py the live credit monitor + router (unchanged)
233
+ plutus_agent/ the monetization engine (this package)
234
+ cli.py config.py db.py pricing.py metering.py client.py bridge.py
235
+ reports.py alerts.py demo.py
236
+ billing/stripe_client.py Checkout, Portal, idempotent webhooks
237
+ server/{app,views,api}.py stdlib dashboard + JSON API at :8420
238
+ integrations/ Anthropic / OpenAI / Hermes adapters
239
+ examples/ quickstart, Hermes, Claude Code hook
240
+ tests/ engine + server test suites
241
+ ```
242
+
243
+ ## Development
244
+
245
+ ```bash
246
+ pip install -e ".[dev]" # stripe + reportlab + pytest
247
+ python -m unittest discover -s tests -v
248
+ python -m unittest test_plutus # the original monitor's suite
249
+ ```
250
+
251
+ ## License
252
+
253
+ MIT — see [LICENSE](LICENSE). © Perseus Computing LLC.
@@ -0,0 +1,214 @@
1
+ # Plutus — the billing layer for AI agents
2
+
3
+ [![Test](https://github.com/Perseus-Computing-LLC/plutus/actions/workflows/test.yml/badge.svg)](https://github.com/Perseus-Computing-LLC/plutus/actions/workflows/test.yml)
4
+ [![PyPI](https://img.shields.io/pypi/v/plutus-agent.svg)](https://pypi.org/project/plutus-agent/)
5
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
+
7
+ > **You wouldn't run a SaaS without billing. Don't run AI agents without Plutus.**
8
+
9
+ Plutus is **self-hosted, Stripe-integrated usage metering and prepaid-credit billing for LLM / AI-agent spend.** Point your agents at it and you get a real-time dark dashboard of where the money goes — per organization, per workspace, per provider, per task type — with prepaid credits that deplete as calls route through, low-balance and budget-cap alerts, and monthly PDF spend reports.
10
+
11
+ Everything except Stripe works **fully offline**. State is a single SQLite file. No Plutus cloud. No lock-in.
12
+
13
+ ```bash
14
+ pip install plutus-agent
15
+ plutus demo # → dark dashboard with realistic data at http://localhost:8420
16
+ ```
17
+
18
+ <p align="center"><em>◆ <a href="https://perseus.observer/plutus/">perseus.observer/plutus</a> · Perseus Computing LLC</em></p>
19
+
20
+ ---
21
+
22
+ ## Start in 30 seconds
23
+
24
+ ```bash
25
+ pip install plutus-agent # PyPI; stdlib + PyYAML, Stripe optional
26
+ plutus demo # zero-setup tour with a month of sample data
27
+ # → open http://localhost:8420
28
+ ```
29
+
30
+ **Running Claude Code or Codex?** See exactly where your spend goes, per project, in one command:
31
+
32
+ ```bash
33
+ plutus install-claude-hook # meters every Claude Code turn automatically
34
+ plutus serve # → http://localhost:8420
35
+ ```
36
+
37
+ → [docs/claude-code.md](docs/claude-code.md)
38
+
39
+ Real setup is three commands:
40
+
41
+ ```bash
42
+ plutus init --org "Acme Agents" --tier pro --workspace ci --budget 100
43
+ plutus topup --amount 50 # add prepaid credit (Stripe does this in prod)
44
+ plutus meter --provider anthropic --model claude-opus-4-8 \
45
+ --task code_review --workspace ci --input 8200 --output 2400
46
+ plutus serve # your live dashboard at :8420
47
+ ```
48
+
49
+ Or in your agent code:
50
+
51
+ ```python
52
+ from plutus_agent import Meter
53
+
54
+ plutus = Meter(org="Acme Agents")
55
+ resp = client.messages.create(model="claude-opus-4-8", ...)
56
+ plutus.track(provider="anthropic", model="claude-opus-4-8",
57
+ task_type="code_review", workspace="ci",
58
+ input_tokens=resp.usage.input_tokens,
59
+ output_tokens=resp.usage.output_tokens)
60
+ print(plutus.balance()) # remaining prepaid credit
61
+ ```
62
+
63
+ ## What you get
64
+
65
+ | | |
66
+ |---|---|
67
+ | **Real-time dashboard** | Dark-themed (`#0c0814`), spend today/7d/30d/MTD, per-workspace budget bars, provider health, cost-per-task ROI, live activity feed. Numbers refresh every 5s. `plutus serve` at `:8420`. |
68
+ | **Multi-tenant** | Organizations → workspaces → users. Meter per workspace, per provider, per model, per task type. |
69
+ | **Prepaid credits** | An append-only ledger that depletes as calls route through. Balance is always the sum of deltas — auditable, never drifts. |
70
+ | **Stripe billing** | Checkout Sessions for credit top-ups + the $20/mo Pro plan, the Customer Portal for self-serve management, and an **idempotent** webhook handler. Test-mode friendly. |
71
+ | **Alerts** | Email on low balance or when a workspace nears/exceeds its monthly budget cap. De-duped, offline-safe (dry-run without SMTP). |
72
+ | **Monthly reports** | Print-ready spend reports — PDF when `reportlab` is installed, clean HTML otherwise. |
73
+ | **Pricing tiers** | Free (10K tracked tokens/mo, 1 workspace), Pro ($20/mo, unlimited tracking, 10 workspaces, credits + alerts + reports), Enterprise (custom, SSO, SLA). |
74
+
75
+ ## Why Plutus — vs. the alternatives
76
+
77
+ | | Manual console-checking | Spreadsheet | **Nothing** | **Plutus** |
78
+ |---|:---:|:---:|:---:|:---:|
79
+ | One view across all providers | ❌ (one console each) | 🟡 (you paste it) | ❌ | ✅ |
80
+ | Real-time | ❌ | ❌ | ❌ | ✅ (5s refresh) |
81
+ | Per-workspace / per-task attribution | ❌ | 🟡 | ❌ | ✅ |
82
+ | Prepaid credit that auto-depletes | ❌ | ❌ | ❌ | ✅ |
83
+ | Low-balance / budget alerts | ❌ | ❌ | ❌ | ✅ |
84
+ | Charge *your* customers (Stripe) | ❌ | ❌ | ❌ | ✅ |
85
+ | Cost to run | your time | your time | a surprise invoice | one SQLite file |
86
+
87
+ If you run agents and you're tracking spend by logging into three billing consoles — or not at all — you already need this.
88
+
89
+ ## The dashboard
90
+
91
+ `plutus serve` (or `plutus demo`) serves a single dark pane at **`:8420`**:
92
+
93
+ - **Headline cards** — credit balance (turns coral when low), spend today, month-to-date, tracked-tokens-vs-plan meter.
94
+ - **Spend by workspace** — with budget-cap progress bars that go coral past 80%.
95
+ - **Providers** — health dot (live/idle/stale), trailing `$/day` burn, last-seen.
96
+ - **Cost per task type** — the ROI lens: `$/task` for code review vs chat vs research.
97
+ - **Live activity** — the most recent metered calls, estimated vs exact.
98
+ - **Billing** — buy prepaid credit, upgrade to Pro, or open the Stripe Customer Portal.
99
+
100
+ It's framework-free (stdlib `http.server`), CSP-safe, and serves the same on a laptop or a `$5` VPS.
101
+
102
+ ## Stripe (test mode)
103
+
104
+ Plutus runs fully offline until you give it a key. Then:
105
+
106
+ ```bash
107
+ export STRIPE_SECRET_KEY=sk_test_... # start in test mode
108
+ plutus stripe-setup # creates the $20/mo Pro price for you
109
+ plutus serve
110
+ stripe listen --forward-to localhost:8420/webhook/stripe # local dev
111
+ ```
112
+
113
+ Full walkthrough — take a test payment and watch credit top up — in **[BILLING.md](BILLING.md)**.
114
+
115
+ - **Buy credit** → one-time Checkout Session → `checkout.session.completed` tops up the ledger.
116
+ - **Upgrade to Pro** → subscription Checkout → subscription webhooks move the org between `pro`/`free`.
117
+ - **Manage billing** → Stripe Customer Portal.
118
+ - Every webhook is verified and recorded by event id, so a replay never double-credits.
119
+
120
+ ## Deploy with Docker
121
+
122
+ ```bash
123
+ docker compose up # dashboard at http://localhost:8420 (demo data)
124
+ # real use:
125
+ docker run -p 8420:8420 -v plutus:/data \
126
+ -e STRIPE_SECRET_KEY=sk_test_... \
127
+ ghcr.io/perseus-computing-llc/plutus serve --host 0.0.0.0
128
+ ```
129
+
130
+ State persists in the `/data` volume (`config.yaml` + `plutus.db`).
131
+
132
+ ## Integrations
133
+
134
+ Thin, dependency-free adapters in [`plutus_agent/integrations`](plutus_agent/integrations) and runnable [`examples/`](examples):
135
+
136
+ - **Anthropic / OpenAI SDKs** — `track_anthropic(meter, response)` / `track_openai(meter, response)` read `response.usage` for you.
137
+ - **Hermes Agent** — push each session as it completes, or back-fill an existing `state.db` ([`examples/hermes_integration.py`](examples/hermes_integration.py)).
138
+ - **Claude Code / Codex CLI** — `plutus install-claude-hook` wires a `Stop` hook that meters every turn, attributed per project ([docs/claude-code.md](docs/claude-code.md)).
139
+
140
+ ## CLI
141
+
142
+ ```text
143
+ plutus init create ~/.plutus/{config.yaml,plutus.db}
144
+ plutus serve run the dashboard + API at :8420 (--demo for sample data)
145
+ plutus demo serve with realistic sample data (zero setup)
146
+ plutus status orgs, balances, Stripe mode
147
+ plutus org create | list organizations
148
+ plutus workspace create | list workspaces (--budget for a monthly cap)
149
+ plutus meter record a usage event (depletes credit)
150
+ plutus topup add prepaid credit
151
+ plutus report monthly PDF/HTML spend report (--month YYYY-MM)
152
+ plutus alerts deliver pending low-balance / budget alerts
153
+ plutus stripe-setup create the $20/mo Pro price in your Stripe account
154
+ plutus install-claude-hook meter Claude Code / Codex turns automatically
155
+ plutus monitor print live provider runway (bridges to plutus.py)
156
+ plutus pricing show plan tiers
157
+ ```
158
+
159
+ ## Configuration
160
+
161
+ `~/.plutus/config.yaml` (created by `plutus init`). Secrets prefer environment variables:
162
+
163
+ | Env var | Purpose |
164
+ |---|---|
165
+ | `PLUTUS_HOME` | Plutus home dir (default `~/.plutus`) |
166
+ | `PLUTUS_DB` / `PLUTUS_PORT` | Override DB path / dashboard port |
167
+ | `STRIPE_SECRET_KEY` / `STRIPE_PUBLISHABLE_KEY` | Stripe API keys |
168
+ | `STRIPE_WEBHOOK_SECRET` / `STRIPE_PRICE_PRO` | Webhook signing secret / Pro Price ID |
169
+ | `PLUTUS_SMTP_PASSWORD` | SMTP password for alert email |
170
+
171
+ Provider price tables (used to *estimate* cost from tokens when an exact cost isn't supplied) are overridable under `pricing.overrides`.
172
+
173
+ ---
174
+
175
+ ## The credit monitor (`plutus.py`)
176
+
177
+ Plutus started as — and still ships — a **provider credit & spend monitor + runway-based model router** for [Hermes Agent](https://github.com/NousResearch/hermes-agent). These run independently of the billing engine and remain the live FinOps tooling:
178
+
179
+ - **`plutus.py`** — live DeepSeek balance API + Hermes `state.db` ledger fused per provider; CLI / `--json` / `--html` dashboard; `--calibrate` back-solves budgets for providers without a balance API.
180
+ - **`plutus_route.py`** — ranks providers by projected days-left and rewrites Hermes routing (primary / delegation / fallbacks), with backup + round-trip verification + a no-op guard so a config write can never lose a key.
181
+
182
+ ```bash
183
+ python3 plutus.py # pretty CLI table
184
+ python3 plutus.py --calibrate anthropic=74.46
185
+ python3 plutus_route.py --dry-run # preview runway-based routing
186
+ ```
187
+
188
+ The billing engine can fold this live runway into its dashboard — set `monitor.enabled` + `monitor.command` in `config.yaml`, or run `plutus monitor`. See the original monitor docs in [`ROADMAP.md`](ROADMAP.md) and [`HANDOFF.md`](HANDOFF.md).
189
+
190
+ ## Layout
191
+
192
+ ```
193
+ plutus.py, plutus_route.py the live credit monitor + router (unchanged)
194
+ plutus_agent/ the monetization engine (this package)
195
+ cli.py config.py db.py pricing.py metering.py client.py bridge.py
196
+ reports.py alerts.py demo.py
197
+ billing/stripe_client.py Checkout, Portal, idempotent webhooks
198
+ server/{app,views,api}.py stdlib dashboard + JSON API at :8420
199
+ integrations/ Anthropic / OpenAI / Hermes adapters
200
+ examples/ quickstart, Hermes, Claude Code hook
201
+ tests/ engine + server test suites
202
+ ```
203
+
204
+ ## Development
205
+
206
+ ```bash
207
+ pip install -e ".[dev]" # stripe + reportlab + pytest
208
+ python -m unittest discover -s tests -v
209
+ python -m unittest test_plutus # the original monitor's suite
210
+ ```
211
+
212
+ ## License
213
+
214
+ MIT — see [LICENSE](LICENSE). © Perseus Computing LLC.