llm-token-costs 0.1.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.
- llm_token_costs-0.1.0/LICENSE +21 -0
- llm_token_costs-0.1.0/PKG-INFO +145 -0
- llm_token_costs-0.1.0/README.md +116 -0
- llm_token_costs-0.1.0/llm_token_costs.egg-info/PKG-INFO +145 -0
- llm_token_costs-0.1.0/llm_token_costs.egg-info/SOURCES.txt +11 -0
- llm_token_costs-0.1.0/llm_token_costs.egg-info/dependency_links.txt +1 -0
- llm_token_costs-0.1.0/llm_token_costs.egg-info/entry_points.txt +2 -0
- llm_token_costs-0.1.0/llm_token_costs.egg-info/requires.txt +10 -0
- llm_token_costs-0.1.0/llm_token_costs.egg-info/top_level.txt +1 -0
- llm_token_costs-0.1.0/llm_token_costs.py +923 -0
- llm_token_costs-0.1.0/pyproject.toml +50 -0
- llm_token_costs-0.1.0/setup.cfg +4 -0
- llm_token_costs-0.1.0/tests/test_llm_token_costs.py +332 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Matthew Busel
|
|
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,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: llm-token-costs
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: LLM plugin: what your logged prompts cost, priced with llm-prices
|
|
5
|
+
Author: Matthew Busel
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Mattbusel/llm-token-costs
|
|
8
|
+
Project-URL: Changelog, https://github.com/Mattbusel/llm-token-costs/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Issues, https://github.com/Mattbusel/llm-token-costs/issues
|
|
10
|
+
Project-URL: CI, https://github.com/Mattbusel/llm-token-costs/actions
|
|
11
|
+
Keywords: llm,llm-plugin,cost,pricing,tokens,openai,anthropic,gemini
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Utilities
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: llm>=0.27
|
|
21
|
+
Requires-Dist: llm-prices>=1.3
|
|
22
|
+
Requires-Dist: sqlite-utils
|
|
23
|
+
Requires-Dist: click
|
|
24
|
+
Provides-Extra: test
|
|
25
|
+
Requires-Dist: pytest; extra == "test"
|
|
26
|
+
Provides-Extra: tiktoken
|
|
27
|
+
Requires-Dist: tiktoken; extra == "tiktoken"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# llm-token-costs
|
|
31
|
+
|
|
32
|
+
[](https://pypi.org/project/llm-token-costs/)
|
|
33
|
+
[](https://github.com/Mattbusel/llm-token-costs/actions/workflows/test.yml)
|
|
34
|
+
[](https://github.com/Mattbusel/llm-token-costs/blob/main/LICENSE)
|
|
35
|
+
|
|
36
|
+
A plugin for [LLM](https://llm.datasette.io/) that tells you what your prompts cost.
|
|
37
|
+
|
|
38
|
+
`llm` already logs the input and output tokens of every response to `logs.db`. This plugin prices those rows, so `llm costs` answers "what did I spend this week, and on which model?" without leaving the terminal. It also estimates a prompt before you send it.
|
|
39
|
+
|
|
40
|
+
Prices come from the [llm-prices](https://github.com/Mattbusel/llm-prices) Python package: a table of USD per 1M token rates for OpenAI, Anthropic, Google, Mistral, DeepSeek, xAI, Groq, Together, Fireworks and Cohere, with a source URL and a checked date on every row. (That package is a separate project from Simon Willison's [llm-prices.com](https://www.llm-prices.com/) calculator.)
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
llm install llm-token-costs
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## What did my prompts cost?
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
$ llm costs
|
|
52
|
+
model responses input cached output cost (USD)
|
|
53
|
+
--------------------------- --------- ------- --------- ------- ----------
|
|
54
|
+
anthropic/claude-sonnet-4-5 23 498,180 1,249,981 58,880 $2.8187
|
|
55
|
+
gemini/gemini-2.5-flash 31 232,996 0 19,778 $0.1193
|
|
56
|
+
gpt-4o-mini 64 86,400 96,000 41,280 $0.0449
|
|
57
|
+
llama3.2:latest 9 11,997 0 4,095 no price
|
|
58
|
+
total 127 829,573 1,345,981 124,033 $2.9830
|
|
59
|
+
|
|
60
|
+
* No price for: llama3.2:latest (9). These are left out of the total.
|
|
61
|
+
Set one with: llm costs set-price llama3.2:latest --input 0 --output 0
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Options:
|
|
65
|
+
|
|
66
|
+
- `--since` / `--until`: a date (`2026-11-01`), an ISO time, `today`, or a span back from now (`30m`, `12h`, `7d`, `4w`).
|
|
67
|
+
- `--by model|day|month|conversation`: how to group the rows.
|
|
68
|
+
- `-m MODEL`: only this model (repeatable; aliases work).
|
|
69
|
+
- `-n 10`: only the first 10 groups.
|
|
70
|
+
- `--json`: machine readable output.
|
|
71
|
+
- `-d path/to/logs.db`: a different database.
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
llm costs --since 7d --by day
|
|
75
|
+
llm costs --by conversation -n 10
|
|
76
|
+
llm costs -m gpt-4o-mini --since 2026-11-01 --json
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## What will this prompt cost?
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
$ cat notes.md | llm costs estimate 'Summarize this' -m gpt-4o-mini -m claude-sonnet-4.5 -m gemini-2.5-flash
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The prompt is read from the argument and standard input, like `llm prompt`. Input tokens are counted with `tiktoken` when it is installed (`llm install 'llm-token-costs[tiktoken]'`) and estimated at about 4 characters per token otherwise. Use `--input-tokens N` to skip counting. The output length is the median output of that model in your own logs (once there are 3 or more responses), else 500, or whatever you pass to `--output-tokens`.
|
|
86
|
+
|
|
87
|
+
## Which price does a model get?
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
$ llm costs price gpt-4o-mini claude-opus-4.5 llama3.2:latest
|
|
91
|
+
model price row input/1M output/1M cached/1M status
|
|
92
|
+
--------------- ------------------------- -------- --------- --------- ------
|
|
93
|
+
gpt-4o-mini openai/gpt-4o-mini 0.15 0.6 0.075 listed
|
|
94
|
+
claude-opus-4.5 anthropic/claude-opus-4-5 5 25 0.5 listed
|
|
95
|
+
llama3.2:latest no price
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
With no arguments it lists every model you have installed. Matching tries the exact model the API reported (`resolved_model`, for example `gpt-4o-mini-2024-07-18`) before the llm model id, and understands plugin ids such as `anthropic/claude-sonnet-4-5`, `gemini/gemini-2.5-pro` and `openrouter/openai/gpt-4o`, plus `claude-opus-4.5` style aliases.
|
|
99
|
+
|
|
100
|
+
## Your own prices
|
|
101
|
+
|
|
102
|
+
For local models, private endpoints or negotiated rates:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
llm costs set-price llama3.2:latest --input 0 --output 0
|
|
106
|
+
llm costs set-price my-azure-gpt --input 2.5 --output 10 --cache-read 1.25
|
|
107
|
+
llm costs set-price my-azure-gpt --remove
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
These are stored in `llm-token-costs.json` in the llm user directory and win over llm-prices.
|
|
111
|
+
|
|
112
|
+
## How tokens are billed
|
|
113
|
+
|
|
114
|
+
- **Cached input.** OpenAI and Gemini count cached tokens inside `input_tokens`; Anthropic counts them outside. The plugin reads `token_details` to split them out and bills cached tokens at the cache-read price.
|
|
115
|
+
- **Anthropic cache writes** bill at the 5 minute or 1 hour write price, from `cache_creation`.
|
|
116
|
+
- **Long context.** Models with a long-context tier (Gemini 2.5 Pro, for example) bill at the higher rate when the prompt is over the threshold.
|
|
117
|
+
- **Responses with no token counts** (some plugins do not report usage) are counted and listed, never guessed.
|
|
118
|
+
- **Prices are today's prices.** `logs.db` does not record the price at call time, so an old response is priced at the current rate. Retired models keep their last listed price.
|
|
119
|
+
|
|
120
|
+
Works with logs written by llm 0.27 and later, including the `turns` table that llm 0.32 introduced and the older `responses` table.
|
|
121
|
+
|
|
122
|
+
## Python API
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
import llm
|
|
126
|
+
from llm_token_costs import cost_of, price_for
|
|
127
|
+
|
|
128
|
+
response = llm.get_model("gpt-4o-mini").prompt("Three names for a pet pelican")
|
|
129
|
+
print(response.text())
|
|
130
|
+
print(cost_of(response)) # USD, or None when the model has no price
|
|
131
|
+
|
|
132
|
+
print(price_for("claude-opus-4.5").output) # USD per 1M output tokens
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Development
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
python -m venv venv && source venv/bin/activate
|
|
139
|
+
pip install -e '.[test]'
|
|
140
|
+
pytest
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
MIT. Maintained by Matthew Busel, who also maintains [llm-prices](https://github.com/Mattbusel/llm-prices).
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# llm-token-costs
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/llm-token-costs/)
|
|
4
|
+
[](https://github.com/Mattbusel/llm-token-costs/actions/workflows/test.yml)
|
|
5
|
+
[](https://github.com/Mattbusel/llm-token-costs/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
A plugin for [LLM](https://llm.datasette.io/) that tells you what your prompts cost.
|
|
8
|
+
|
|
9
|
+
`llm` already logs the input and output tokens of every response to `logs.db`. This plugin prices those rows, so `llm costs` answers "what did I spend this week, and on which model?" without leaving the terminal. It also estimates a prompt before you send it.
|
|
10
|
+
|
|
11
|
+
Prices come from the [llm-prices](https://github.com/Mattbusel/llm-prices) Python package: a table of USD per 1M token rates for OpenAI, Anthropic, Google, Mistral, DeepSeek, xAI, Groq, Together, Fireworks and Cohere, with a source URL and a checked date on every row. (That package is a separate project from Simon Willison's [llm-prices.com](https://www.llm-prices.com/) calculator.)
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
llm install llm-token-costs
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## What did my prompts cost?
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
$ llm costs
|
|
23
|
+
model responses input cached output cost (USD)
|
|
24
|
+
--------------------------- --------- ------- --------- ------- ----------
|
|
25
|
+
anthropic/claude-sonnet-4-5 23 498,180 1,249,981 58,880 $2.8187
|
|
26
|
+
gemini/gemini-2.5-flash 31 232,996 0 19,778 $0.1193
|
|
27
|
+
gpt-4o-mini 64 86,400 96,000 41,280 $0.0449
|
|
28
|
+
llama3.2:latest 9 11,997 0 4,095 no price
|
|
29
|
+
total 127 829,573 1,345,981 124,033 $2.9830
|
|
30
|
+
|
|
31
|
+
* No price for: llama3.2:latest (9). These are left out of the total.
|
|
32
|
+
Set one with: llm costs set-price llama3.2:latest --input 0 --output 0
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Options:
|
|
36
|
+
|
|
37
|
+
- `--since` / `--until`: a date (`2026-11-01`), an ISO time, `today`, or a span back from now (`30m`, `12h`, `7d`, `4w`).
|
|
38
|
+
- `--by model|day|month|conversation`: how to group the rows.
|
|
39
|
+
- `-m MODEL`: only this model (repeatable; aliases work).
|
|
40
|
+
- `-n 10`: only the first 10 groups.
|
|
41
|
+
- `--json`: machine readable output.
|
|
42
|
+
- `-d path/to/logs.db`: a different database.
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
llm costs --since 7d --by day
|
|
46
|
+
llm costs --by conversation -n 10
|
|
47
|
+
llm costs -m gpt-4o-mini --since 2026-11-01 --json
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## What will this prompt cost?
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
$ cat notes.md | llm costs estimate 'Summarize this' -m gpt-4o-mini -m claude-sonnet-4.5 -m gemini-2.5-flash
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The prompt is read from the argument and standard input, like `llm prompt`. Input tokens are counted with `tiktoken` when it is installed (`llm install 'llm-token-costs[tiktoken]'`) and estimated at about 4 characters per token otherwise. Use `--input-tokens N` to skip counting. The output length is the median output of that model in your own logs (once there are 3 or more responses), else 500, or whatever you pass to `--output-tokens`.
|
|
57
|
+
|
|
58
|
+
## Which price does a model get?
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
$ llm costs price gpt-4o-mini claude-opus-4.5 llama3.2:latest
|
|
62
|
+
model price row input/1M output/1M cached/1M status
|
|
63
|
+
--------------- ------------------------- -------- --------- --------- ------
|
|
64
|
+
gpt-4o-mini openai/gpt-4o-mini 0.15 0.6 0.075 listed
|
|
65
|
+
claude-opus-4.5 anthropic/claude-opus-4-5 5 25 0.5 listed
|
|
66
|
+
llama3.2:latest no price
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
With no arguments it lists every model you have installed. Matching tries the exact model the API reported (`resolved_model`, for example `gpt-4o-mini-2024-07-18`) before the llm model id, and understands plugin ids such as `anthropic/claude-sonnet-4-5`, `gemini/gemini-2.5-pro` and `openrouter/openai/gpt-4o`, plus `claude-opus-4.5` style aliases.
|
|
70
|
+
|
|
71
|
+
## Your own prices
|
|
72
|
+
|
|
73
|
+
For local models, private endpoints or negotiated rates:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
llm costs set-price llama3.2:latest --input 0 --output 0
|
|
77
|
+
llm costs set-price my-azure-gpt --input 2.5 --output 10 --cache-read 1.25
|
|
78
|
+
llm costs set-price my-azure-gpt --remove
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
These are stored in `llm-token-costs.json` in the llm user directory and win over llm-prices.
|
|
82
|
+
|
|
83
|
+
## How tokens are billed
|
|
84
|
+
|
|
85
|
+
- **Cached input.** OpenAI and Gemini count cached tokens inside `input_tokens`; Anthropic counts them outside. The plugin reads `token_details` to split them out and bills cached tokens at the cache-read price.
|
|
86
|
+
- **Anthropic cache writes** bill at the 5 minute or 1 hour write price, from `cache_creation`.
|
|
87
|
+
- **Long context.** Models with a long-context tier (Gemini 2.5 Pro, for example) bill at the higher rate when the prompt is over the threshold.
|
|
88
|
+
- **Responses with no token counts** (some plugins do not report usage) are counted and listed, never guessed.
|
|
89
|
+
- **Prices are today's prices.** `logs.db` does not record the price at call time, so an old response is priced at the current rate. Retired models keep their last listed price.
|
|
90
|
+
|
|
91
|
+
Works with logs written by llm 0.27 and later, including the `turns` table that llm 0.32 introduced and the older `responses` table.
|
|
92
|
+
|
|
93
|
+
## Python API
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
import llm
|
|
97
|
+
from llm_token_costs import cost_of, price_for
|
|
98
|
+
|
|
99
|
+
response = llm.get_model("gpt-4o-mini").prompt("Three names for a pet pelican")
|
|
100
|
+
print(response.text())
|
|
101
|
+
print(cost_of(response)) # USD, or None when the model has no price
|
|
102
|
+
|
|
103
|
+
print(price_for("claude-opus-4.5").output) # USD per 1M output tokens
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Development
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
python -m venv venv && source venv/bin/activate
|
|
110
|
+
pip install -e '.[test]'
|
|
111
|
+
pytest
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
MIT. Maintained by Matthew Busel, who also maintains [llm-prices](https://github.com/Mattbusel/llm-prices).
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: llm-token-costs
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: LLM plugin: what your logged prompts cost, priced with llm-prices
|
|
5
|
+
Author: Matthew Busel
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Mattbusel/llm-token-costs
|
|
8
|
+
Project-URL: Changelog, https://github.com/Mattbusel/llm-token-costs/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Issues, https://github.com/Mattbusel/llm-token-costs/issues
|
|
10
|
+
Project-URL: CI, https://github.com/Mattbusel/llm-token-costs/actions
|
|
11
|
+
Keywords: llm,llm-plugin,cost,pricing,tokens,openai,anthropic,gemini
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Utilities
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: llm>=0.27
|
|
21
|
+
Requires-Dist: llm-prices>=1.3
|
|
22
|
+
Requires-Dist: sqlite-utils
|
|
23
|
+
Requires-Dist: click
|
|
24
|
+
Provides-Extra: test
|
|
25
|
+
Requires-Dist: pytest; extra == "test"
|
|
26
|
+
Provides-Extra: tiktoken
|
|
27
|
+
Requires-Dist: tiktoken; extra == "tiktoken"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# llm-token-costs
|
|
31
|
+
|
|
32
|
+
[](https://pypi.org/project/llm-token-costs/)
|
|
33
|
+
[](https://github.com/Mattbusel/llm-token-costs/actions/workflows/test.yml)
|
|
34
|
+
[](https://github.com/Mattbusel/llm-token-costs/blob/main/LICENSE)
|
|
35
|
+
|
|
36
|
+
A plugin for [LLM](https://llm.datasette.io/) that tells you what your prompts cost.
|
|
37
|
+
|
|
38
|
+
`llm` already logs the input and output tokens of every response to `logs.db`. This plugin prices those rows, so `llm costs` answers "what did I spend this week, and on which model?" without leaving the terminal. It also estimates a prompt before you send it.
|
|
39
|
+
|
|
40
|
+
Prices come from the [llm-prices](https://github.com/Mattbusel/llm-prices) Python package: a table of USD per 1M token rates for OpenAI, Anthropic, Google, Mistral, DeepSeek, xAI, Groq, Together, Fireworks and Cohere, with a source URL and a checked date on every row. (That package is a separate project from Simon Willison's [llm-prices.com](https://www.llm-prices.com/) calculator.)
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
llm install llm-token-costs
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## What did my prompts cost?
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
$ llm costs
|
|
52
|
+
model responses input cached output cost (USD)
|
|
53
|
+
--------------------------- --------- ------- --------- ------- ----------
|
|
54
|
+
anthropic/claude-sonnet-4-5 23 498,180 1,249,981 58,880 $2.8187
|
|
55
|
+
gemini/gemini-2.5-flash 31 232,996 0 19,778 $0.1193
|
|
56
|
+
gpt-4o-mini 64 86,400 96,000 41,280 $0.0449
|
|
57
|
+
llama3.2:latest 9 11,997 0 4,095 no price
|
|
58
|
+
total 127 829,573 1,345,981 124,033 $2.9830
|
|
59
|
+
|
|
60
|
+
* No price for: llama3.2:latest (9). These are left out of the total.
|
|
61
|
+
Set one with: llm costs set-price llama3.2:latest --input 0 --output 0
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Options:
|
|
65
|
+
|
|
66
|
+
- `--since` / `--until`: a date (`2026-11-01`), an ISO time, `today`, or a span back from now (`30m`, `12h`, `7d`, `4w`).
|
|
67
|
+
- `--by model|day|month|conversation`: how to group the rows.
|
|
68
|
+
- `-m MODEL`: only this model (repeatable; aliases work).
|
|
69
|
+
- `-n 10`: only the first 10 groups.
|
|
70
|
+
- `--json`: machine readable output.
|
|
71
|
+
- `-d path/to/logs.db`: a different database.
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
llm costs --since 7d --by day
|
|
75
|
+
llm costs --by conversation -n 10
|
|
76
|
+
llm costs -m gpt-4o-mini --since 2026-11-01 --json
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## What will this prompt cost?
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
$ cat notes.md | llm costs estimate 'Summarize this' -m gpt-4o-mini -m claude-sonnet-4.5 -m gemini-2.5-flash
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The prompt is read from the argument and standard input, like `llm prompt`. Input tokens are counted with `tiktoken` when it is installed (`llm install 'llm-token-costs[tiktoken]'`) and estimated at about 4 characters per token otherwise. Use `--input-tokens N` to skip counting. The output length is the median output of that model in your own logs (once there are 3 or more responses), else 500, or whatever you pass to `--output-tokens`.
|
|
86
|
+
|
|
87
|
+
## Which price does a model get?
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
$ llm costs price gpt-4o-mini claude-opus-4.5 llama3.2:latest
|
|
91
|
+
model price row input/1M output/1M cached/1M status
|
|
92
|
+
--------------- ------------------------- -------- --------- --------- ------
|
|
93
|
+
gpt-4o-mini openai/gpt-4o-mini 0.15 0.6 0.075 listed
|
|
94
|
+
claude-opus-4.5 anthropic/claude-opus-4-5 5 25 0.5 listed
|
|
95
|
+
llama3.2:latest no price
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
With no arguments it lists every model you have installed. Matching tries the exact model the API reported (`resolved_model`, for example `gpt-4o-mini-2024-07-18`) before the llm model id, and understands plugin ids such as `anthropic/claude-sonnet-4-5`, `gemini/gemini-2.5-pro` and `openrouter/openai/gpt-4o`, plus `claude-opus-4.5` style aliases.
|
|
99
|
+
|
|
100
|
+
## Your own prices
|
|
101
|
+
|
|
102
|
+
For local models, private endpoints or negotiated rates:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
llm costs set-price llama3.2:latest --input 0 --output 0
|
|
106
|
+
llm costs set-price my-azure-gpt --input 2.5 --output 10 --cache-read 1.25
|
|
107
|
+
llm costs set-price my-azure-gpt --remove
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
These are stored in `llm-token-costs.json` in the llm user directory and win over llm-prices.
|
|
111
|
+
|
|
112
|
+
## How tokens are billed
|
|
113
|
+
|
|
114
|
+
- **Cached input.** OpenAI and Gemini count cached tokens inside `input_tokens`; Anthropic counts them outside. The plugin reads `token_details` to split them out and bills cached tokens at the cache-read price.
|
|
115
|
+
- **Anthropic cache writes** bill at the 5 minute or 1 hour write price, from `cache_creation`.
|
|
116
|
+
- **Long context.** Models with a long-context tier (Gemini 2.5 Pro, for example) bill at the higher rate when the prompt is over the threshold.
|
|
117
|
+
- **Responses with no token counts** (some plugins do not report usage) are counted and listed, never guessed.
|
|
118
|
+
- **Prices are today's prices.** `logs.db` does not record the price at call time, so an old response is priced at the current rate. Retired models keep their last listed price.
|
|
119
|
+
|
|
120
|
+
Works with logs written by llm 0.27 and later, including the `turns` table that llm 0.32 introduced and the older `responses` table.
|
|
121
|
+
|
|
122
|
+
## Python API
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
import llm
|
|
126
|
+
from llm_token_costs import cost_of, price_for
|
|
127
|
+
|
|
128
|
+
response = llm.get_model("gpt-4o-mini").prompt("Three names for a pet pelican")
|
|
129
|
+
print(response.text())
|
|
130
|
+
print(cost_of(response)) # USD, or None when the model has no price
|
|
131
|
+
|
|
132
|
+
print(price_for("claude-opus-4.5").output) # USD per 1M output tokens
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Development
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
python -m venv venv && source venv/bin/activate
|
|
139
|
+
pip install -e '.[test]'
|
|
140
|
+
pytest
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
MIT. Maintained by Matthew Busel, who also maintains [llm-prices](https://github.com/Mattbusel/llm-prices).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
llm_token_costs.py
|
|
4
|
+
pyproject.toml
|
|
5
|
+
llm_token_costs.egg-info/PKG-INFO
|
|
6
|
+
llm_token_costs.egg-info/SOURCES.txt
|
|
7
|
+
llm_token_costs.egg-info/dependency_links.txt
|
|
8
|
+
llm_token_costs.egg-info/entry_points.txt
|
|
9
|
+
llm_token_costs.egg-info/requires.txt
|
|
10
|
+
llm_token_costs.egg-info/top_level.txt
|
|
11
|
+
tests/test_llm_token_costs.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
llm_token_costs
|