unalloc 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.
@@ -0,0 +1,18 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ venv/
5
+ dist/
6
+ build/
7
+ *.egg-info/
8
+ .pytest_cache/
9
+ .ruff_cache/
10
+ .mypy_cache/
11
+ .env
12
+ .DS_Store
13
+ .idea/
14
+ .vscode/*
15
+ !.vscode/settings.json
16
+ .claude/settings.local.json
17
+ .ipynb_checkpoints/
18
+ .cache/
@@ -0,0 +1,24 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 — 2026-09-13
4
+
5
+ Validated against five inference case studies; see `paper/unalloc-case-studies.pdf`.
6
+
7
+ ### Fixed
8
+ - OpenAI and Anthropic adapters lost their default API URLs whenever the CLI passed an unset environment variable, so every live fetch failed.
9
+ - The Anthropic Admin API is now called with `x-api-key` and `anthropic-version` instead of a Bearer token.
10
+ - Provider cost APIs are paged with `has_more` / `next_page`; previously only the first page was read.
11
+ - OpenCost component costs are summed as `Decimal` when `totalCost` is absent, never through `float`.
12
+ - Stacked label prefixes are all stripped (`label_app_kubernetes_io_name` → `name`).
13
+ - Canonical-key collisions resolve by a fixed precedence instead of arrival order (explicit key, alias, rewritten key, path-derived key).
14
+ - OpenCost annotations no longer override labels with the same key.
15
+ - `unalloc labels` honours `--fallback`, and exits 1 when no rows load instead of printing "Nothing unallocated".
16
+
17
+ ### Added
18
+ - `report --budget PCT` exits 2 when the unallocated share exceeds `PCT`, for CI gates.
19
+ - Reports show the spend attributed only through a fallback key (`fallback_usd` in `--json`).
20
+ - Case studies (`case_studies/`), a Typst paper (`paper/`), a ledger explorer, a companion notebook and a dev container with Postgres.
21
+
22
+ ## 0.1.0
23
+
24
+ Initial release: OpenCost, LiteLLM, OpenAI and Anthropic adapters; `report`, `labels` and `reconcile`.
unalloc-0.2.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Timothy Urista
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
unalloc-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,254 @@
1
+ Metadata-Version: 2.5
2
+ Name: unalloc
3
+ Version: 0.2.0
4
+ Summary: Find the AI spend nobody owns. Joins OpenCost allocation data with LLM provider bills and reports what's unattributed.
5
+ Project-URL: Homepage, https://github.com/timurista/unalloc
6
+ Project-URL: Issues, https://github.com/timurista/unalloc/issues
7
+ Project-URL: Changelog, https://github.com/timurista/unalloc/blob/main/CHANGELOG.md
8
+ Project-URL: Paper, https://github.com/timurista/unalloc/blob/main/paper/unalloc-case-studies.pdf
9
+ Project-URL: Explorer, https://timurista.github.io/unalloc/
10
+ Author: Timothy Urista
11
+ License: Apache-2.0
12
+ License-File: LICENSE
13
+ Keywords: cost-attribution,finops,kubernetes,llm,llmops,opencost,showback
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Environment :: Console
16
+ Classifier: Intended Audience :: System Administrators
17
+ Classifier: License :: OSI Approved :: Apache Software License
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: System :: Monitoring
22
+ Requires-Python: >=3.11
23
+ Requires-Dist: httpx>=0.27
24
+ Requires-Dist: rich>=13.7
25
+ Requires-Dist: typer>=0.12
26
+ Provides-Extra: dev
27
+ Requires-Dist: mypy>=1.11; extra == 'dev'
28
+ Requires-Dist: pytest>=8.0; extra == 'dev'
29
+ Requires-Dist: ruff>=0.6; extra == 'dev'
30
+ Provides-Extra: research
31
+ Requires-Dist: ipykernel>=6.29; extra == 'research'
32
+ Requires-Dist: jupyterlab>=4.2; extra == 'research'
33
+ Requires-Dist: matplotlib>=3.8; extra == 'research'
34
+ Requires-Dist: nbclient>=0.10; extra == 'research'
35
+ Requires-Dist: nbformat>=5.10; extra == 'research'
36
+ Requires-Dist: numpy>=1.26; extra == 'research'
37
+ Requires-Dist: psycopg[binary]>=3.2; extra == 'research'
38
+ Requires-Dist: torch>=2.3; extra == 'research'
39
+ Requires-Dist: typst>=0.13; extra == 'research'
40
+ Description-Content-Type: text/markdown
41
+
42
+ # unalloc
43
+
44
+ **Find the AI spend nobody owns.** Joins OpenCost allocation data with LLM provider bills and reports what's unattributed.
45
+
46
+ [![ci](https://github.com/timurista/unalloc/actions/workflows/ci.yml/badge.svg)](https://github.com/timurista/unalloc/actions/workflows/ci.yml)
47
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/timurista/unalloc/blob/main/LICENSE)
48
+ [![Python](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://github.com/timurista/unalloc/blob/main/pyproject.toml)
49
+ [![Paper](https://img.shields.io/badge/paper-PDF-1f5b45.svg)](https://github.com/timurista/unalloc/blob/main/paper/unalloc-case-studies.pdf)
50
+ [![Explorer](https://img.shields.io/badge/explorer-live-1f5b45.svg)](https://timurista.github.io/unalloc/)
51
+
52
+ OpenCost tells you what your Kubernetes workloads cost. Your provider dashboard tells you what your OpenAI and Anthropic calls cost. Neither tells you what a single AI feature costs, because the two live in different systems with different keys. `unalloc` pulls both into one normalized ledger, joins them on a label dimension you choose, and reports the number your finance team keeps asking for: how much of this month's AI spend can't be attributed to any team.
53
+
54
+ ## The output
55
+
56
+ ```
57
+ $ unalloc report --fixtures --dimension team
58
+
59
+ ╭──────────────────────────── unalloc ─────────────────────────────╮
60
+ │ 73.5% of $66,630.38 AI spend is unattributed │
61
+ │ $48,983.14 has no 'team' label │
62
+ ╰──────────────────────────────────────────────────────────────────╯
63
+
64
+ Spend by team
65
+ ┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━┓
66
+ ┃ team ┃ Cost ┃ Share ┃ Sources ┃ Rows ┃
67
+ ┡━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━┩
68
+ │ platform │ $13,166.02 │ 19.8% │ litellm, opencost │ 2 │
69
+ │ search │ $4,481.22 │ 6.7% │ litellm, opencost │ 2 │
70
+ │ <unallocated> │ $48,983.14 │ 73.5% │ anthropic, litellm, opencost, openai │ 11 │
71
+ └─────────────────┴─────────────┴───────┴───────────────────────────────────────┴──────┘
72
+ ```
73
+
74
+ Then the actionable half: a labeling backlog sorted by dollars.
75
+
76
+ ```
77
+ $ unalloc labels --fixtures --dimension team
78
+
79
+ Labeling backlog — rows missing 'team', by cost
80
+ ┏━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
81
+ ┃ # ┃ Source ┃ Cost object ┃ Cost ┃ Labels it does have ┃
82
+ ┡━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
83
+ │ 1 │ opencost │ inference/vllm-llama-70b │ $19,147.10 │ cluster, controller, ... │
84
+ │ 2 │ opencost │ __idle__ │ $6,070.00 │ cluster │
85
+ │ 3 │ litellm │ claude-opus-5 │ $5,412.75 │ environment, model │
86
+ └────┴──────────┴───────────────────────────┴────────────┴────────────────────────────┘
87
+ ```
88
+
89
+ `inference/vllm-llama-70b` is the whole pitch: $19K of GPU spend carrying a `costCenter` label but no `team`, sitting next to $5K of Claude API spend on an unlabeled legacy key. Two systems, one gap, no existing tool that shows them in the same table.
90
+
91
+ Add a fallback and unalloc says how much of the "allocated" spend only got there through it, so a fallback onto something that is not an owner can't hide inside the headline:
92
+
93
+ ```
94
+ $ unalloc report --fixtures -D team --fallback namespace
95
+ │ 37.9% of $66,630.38 AI spend is unattributed │
96
+ │ $25,237.54 has no 'team' label │
97
+ │ $23,745.60 attributed only via fallback (namespace) │
98
+ ```
99
+
100
+ ## Install
101
+
102
+ ```bash
103
+ pip install unalloc # or: uv tool install unalloc
104
+ unalloc report --fixtures # works immediately, no infrastructure needed
105
+ ```
106
+
107
+ From a clone:
108
+
109
+ ```bash
110
+ make dev # editable install with test + lint tooling
111
+ make demo # all three commands against bundled fixtures
112
+ make check # ruff + pytest, same as CI
113
+ ```
114
+
115
+ Or as a container, which needs no Python on the host:
116
+
117
+ ```bash
118
+ docker build -t unalloc:0.2.0 .
119
+ docker run --rm unalloc:0.2.0 report --fixtures -D team
120
+
121
+ # against real systems, reachable from the container
122
+ docker run --rm --network host --env-file .env unalloc:0.2.0 report -D team
123
+ ```
124
+
125
+ Copy `.env.example` to `.env` for the source configuration. unalloc stores
126
+ nothing: no database, no state directory, no cached credentials.
127
+
128
+ ## Usage
129
+
130
+ ```bash
131
+ # What percentage of spend has no owner?
132
+ unalloc report --dimension team --days 30
133
+
134
+ # Accept a second-best key before declaring a row unallocated
135
+ unalloc report -D team --fallback namespace --fallback cost_center
136
+
137
+ # Fail a CI job when more than 10% of spend is unowned
138
+ unalloc report -D team --budget 10
139
+
140
+ # Which label keys does my data actually have?
141
+ unalloc labels --available
142
+
143
+ # The backlog honours the same fallbacks as the report
144
+ unalloc labels -D team --fallback namespace
145
+
146
+ # Does the ledger tie out to the invoice?
147
+ unalloc reconcile --invoice openai=4031.36 --invoice anthropic=8737.03
148
+
149
+ # Pipe it into something else
150
+ unalloc report --json | jq '.unallocated_pct, .fallback_usd'
151
+ ```
152
+
153
+ Configure sources by environment variable:
154
+
155
+ | Variable | Purpose |
156
+ | --- | --- |
157
+ | `UNALLOC_OPENCOST_URL` | OpenCost API root, e.g. `http://opencost.opencost:9003` |
158
+ | `UNALLOC_LITELLM_URL` | LiteLLM proxy root |
159
+ | `UNALLOC_LITELLM_KEY` | LiteLLM master or admin key |
160
+ | `OPENAI_ADMIN_KEY` | OpenAI org admin key (costs endpoint) |
161
+ | `ANTHROPIC_ADMIN_KEY` | Anthropic org admin key (cost report endpoint, sent as `x-api-key`) |
162
+ | `UNALLOC_OPENAI_URL`, `UNALLOC_ANTHROPIC_URL` | Optional overrides for the public API roots, e.g. a proxy |
163
+
164
+ Restrict the run with `--source` to avoid double counting: if your traffic goes through LiteLLM, prefer `--source opencost --source litellm` and skip the direct provider adapters, since the same tokens appear in both. The [end-to-end case study](#case-studies-and-paper) measures exactly how much that costs you if you forget.
165
+
166
+ ## How it works
167
+
168
+ ```
169
+ OpenCost /allocation ─┐
170
+ LiteLLM /spend/logs ─┤
171
+ OpenAI org costs ─┼──▶ normalize (label canonicalization + aliases)
172
+ Anthropic cost report ┘ │
173
+ ▼
174
+ CostRow[]
175
+ │
176
+ ┌────────────────┼────────────────┐
177
+ ▼ ▼ ▼
178
+ attribute reconcile labels
179
+ (unallocated %) (vs invoice) (backlog by $)
180
+ ```
181
+
182
+ Everything rests on one dataclass. An adapter's only job is turning a provider payload into `CostRow`s; it never aggregates, filters or decides anything about attribution. Adding a provider is one file and one fixture.
183
+
184
+ Two design choices worth calling out:
185
+
186
+ **Money is `Decimal`, never `float`.** Attribution that disagrees with the invoice by a cent per row is how you lose an argument with finance.
187
+
188
+ **Label canonicalization is the actual hard part.** OpenCost gives you `label_costCenter`. LiteLLM gives you `team_id` or a `team:platform` request tag. OpenAI gives you a project ID. None of those join on a naive dict lookup, so every adapter runs its labels through `normalize.py` first, which strips provider prefixes (repeatedly, so `label_app_kubernetes_io_name` and `app.kubernetes.io/name` agree), converts camelCase, and applies an alias table you can extend per-org. When two raw keys land on the same canonical key, a fixed precedence decides - explicit key, then alias, then rewritten key, then path-derived key - so the result never depends on the order a provider serialized its labels in.
189
+
190
+ ## Case studies and paper
191
+
192
+ Five studies push real (or realistically simulated) inference workloads through unalloc's own adapters. They exposed nine defects in the tool along the way, all fixed with regression tests, and they're written up as a paper: **[paper/unalloc-case-studies.pdf](https://github.com/timurista/unalloc/blob/main/paper/unalloc-case-studies.pdf)**.
193
+
194
+ | Study | What runs | Headline |
195
+ | --- | --- | --- |
196
+ | [`kv_cache`](https://github.com/timurista/unalloc/blob/main/case_studies/kv_cache) | Discrete-event vLLM-style engine: paged KV blocks, prefix caching, continuous batching, preemption | Step-time metering shows ~0% idle once any request is in flight; KV-memory metering leaves a large share of the bill unowned |
197
+ | [`torch_kv`](https://github.com/timurista/unalloc/blob/main/case_studies/torch_kv) | A from-scratch PyTorch decoder with a real KV cache serving a 4-tenant trace | Per-token showback over-charges a RAG tenant by 33 points of the pool ($5.7K/month) vs measured compute |
198
+ | [`distributed`](https://github.com/timurista/unalloc/blob/main/case_studies/distributed) | Tensor and pipeline parallel on `torch.distributed` (gloo), verified against a single-process reference | Owner label on LeaderWorkerSet leaders only: 66% unallocated; falling back to `name` "fixes" it by sending 61% to a Helm chart name |
199
+ | [`hybrid_e2e`](https://github.com/timurista/unalloc/blob/main/case_studies/hybrid_e2e) | The real CLI as a subprocess against live mock OpenCost / LiteLLM / OpenAI / Anthropic APIs (Postgres-backed LiteLLM in the dev container) | Enabling every source double counts $11.8K; reading only page one of the billing APIs reports 25% of spend |
200
+ | [`use_cases`](https://github.com/timurista/unalloc/blob/main/case_studies/use_cases) | Labeling Pareto, per-feature unit economics, self-host break-even, CI budget gate | Three label fixes take a 67%-unallocated org under 10% |
201
+
202
+ ```bash
203
+ make research # CPU torch, notebook tooling, typst
204
+ make case-studies # all five, full size (a few minutes)
205
+ make paper # figures + PDF
206
+ make notebook # execute case_studies/unalloc_case_studies.ipynb
207
+ make ui # ledger explorer on http://127.0.0.1:8765
208
+ ```
209
+
210
+ ![Share of a shared vLLM pod's bill under five metering rules](https://raw.githubusercontent.com/timurista/unalloc/main/paper/figures/kv_shares.png)
211
+
212
+ The **[ledger explorer](https://timurista.github.io/unalloc/)** (or `python -m case_studies.ui` locally) shows every dataset row by row: pick the label that means "owner", add fallbacks, and watch each row resolve to a team, a fallback value, or the backlog. `python -m case_studies.ui --export explorer.html` writes a self-contained copy you can share.
213
+
214
+ ## Development environment
215
+
216
+ An isolated dev stack lives in [`.devcontainer/`](https://github.com/timurista/unalloc/blob/main/.devcontainer): a Python 3.11 workspace with the case-study dependencies (CPU-only PyTorch) and a small Postgres that backs the mock LiteLLM spend-log store. Open the folder in VS Code's Dev Containers, or from a terminal:
217
+
218
+ ```bash
219
+ make devcontainer # docker compose up
220
+ make devcontainer-check # lint, tests and every case study at smoke size, inside the container
221
+ ```
222
+
223
+ ## Scope, and what this is not
224
+
225
+ OpenCost 1.121.0 added inference cost tracking for vLLM and llm-d deployments: cost per million tokens, KV-cache-corrected pricing, shared infrastructure attribution. That is excellent and `unalloc` does not reimplement it. Those rows arrive through the same `/allocation` shape and land in this ledger tagged `unalloc_layer=inference`.
226
+
227
+ What OpenCost structurally cannot do is see your OpenAI and Anthropic bills, because they aren't Kubernetes objects. What LiteLLM cannot do is see your GPU nodes. `unalloc` lives in exactly that seam and nowhere else. It is:
228
+
229
+ - **not** a dashboard — it prints a number and exits (the explorer is a case-study companion, not part of the CLI)
230
+ - **not** an optimizer — it makes no recommendations about rightsizing or commitments
231
+ - **not** a collector — it queries systems you already run, and stores nothing
232
+
233
+ ## Roadmap
234
+
235
+ - [ ] Prometheus exporter so `unalloc_unallocated_ratio` can be alerted on
236
+ - [ ] OpenCost external-cost plugin, so LLM API spend appears natively in OpenCost
237
+ - [ ] Per-feature unit economics using the `quantity`/`unit` fields already carried on `CostRow`
238
+ - [ ] Azure OpenAI and Bedrock adapters
239
+ - [x] `--budget` mode: exit non-zero when unallocated share crosses a threshold, for CI
240
+ - [ ] `--exclude label=value` on a source, so gateway traffic can be dropped from provider billing instead of whole sources
241
+ - [ ] Warn when distinct raw label keys collide on one canonical key
242
+
243
+ ## Contributing
244
+
245
+ Adding a source is deliberately small: implement `parse()` on a `Source` subclass, add a fixture to `src/unalloc/fixtures/`, add a case to `tests/test_sources.py`. The fixtures are the contract, so a PR with a real (scrubbed) payload from a provider is valuable even without the adapter.
246
+
247
+ ```bash
248
+ pip install -e ".[dev]"
249
+ ruff check . && pytest
250
+ ```
251
+
252
+ ## License
253
+
254
+ Apache 2.0, matching OpenCost.