txaion-model-pricing 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.
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Txaion LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,2 @@
1
+ include scripts/update_prices.py
2
+ include README.zh-TW.md
@@ -0,0 +1,180 @@
1
+ Metadata-Version: 2.4
2
+ Name: txaion-model-pricing
3
+ Version: 0.1.0
4
+ Summary: Cross-provider AI model pricing for Python
5
+ Author: Txaion LLC
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://txaion.com
8
+ Project-URL: Repository, https://github.com/Txaion/txaion-model-pricing
9
+ Project-URL: Upstream-Data, https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Typing :: Typed
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ License-File: THIRD_PARTY_NOTICES.md
21
+ Requires-Dist: orjson<4,>=3.10
22
+ Provides-Extra: dev
23
+ Requires-Dist: build<2,>=1.2; extra == "dev"
24
+ Requires-Dist: pytest<9,>=8; extra == "dev"
25
+ Requires-Dist: ruff<1,>=0.12; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ <p align="center">
29
+ <a href="https://txaion.com">
30
+ <img
31
+ src="https://static.txaion.com/product/model-price/model-price-tp.png"
32
+ alt="Txaion"
33
+ width="360"
34
+ >
35
+ </a>
36
+ </p>
37
+
38
+ <h1 align="center">Txaion Model Pricing</h1>
39
+
40
+ <p align="center">
41
+ Lightweight, cross-provider model pricing for Python.
42
+ </p>
43
+
44
+ <p align="center">
45
+ <strong>English</strong> |
46
+ <a href="README.zh-TW.md">繁體中文</a>
47
+ </p>
48
+
49
+ `Txaion Model Pricing` is a lightweight Python package for querying
50
+ cross-provider model information and calculating USD costs for input, output,
51
+ and cached-input tokens.
52
+
53
+ Developed and maintained by [Txaion](https://txaion.com).
54
+
55
+ The current version is `0.1.0` and requires Python 3.10 or later.
56
+
57
+ ## Installation
58
+
59
+ Install the package from the project directory:
60
+
61
+ ```bash
62
+ python -m pip install .
63
+ ```
64
+
65
+ Install the development dependencies for testing and building:
66
+
67
+ ```bash
68
+ python -m pip install -e ".[dev]"
69
+ ```
70
+
71
+ ## Quick start
72
+
73
+ ```python
74
+ from txaion_model_pricing import calculate_cost, count_models, get_model_details
75
+
76
+ print(count_models())
77
+
78
+ input_cost = calculate_cost("gpt-4o", 1_000_000, "input")
79
+ output_cost = calculate_cost("gpt-4o", 1_000_000, "output")
80
+ cached_cost = calculate_cost("gpt-4o", 1_000_000, "cached")
81
+
82
+ print(input_cost) # Decimal("2.5000000")
83
+ print(output_cost) # Decimal("10.00000")
84
+ print(cached_cost) # Decimal("1.25000000")
85
+
86
+ details = get_model_details("gpt-4o")
87
+ print(details["max_input_tokens"])
88
+ ```
89
+
90
+ All costs are returned as `decimal.Decimal` values. The package does not round
91
+ results or perform currency conversion.
92
+
93
+ ## Public API
94
+
95
+ ### `count_models() -> int`
96
+
97
+ Returns the number of models in the bundled snapshot. Metadata entries such as
98
+ `sample_spec` are excluded.
99
+
100
+ ### `calculate_cost(model, tokens, token_type) -> Decimal`
101
+
102
+ Calculates the USD cost using the model's per-token price:
103
+
104
+ - `input` maps to `input_cost_per_token`
105
+ - `output` maps to `output_cost_per_token`
106
+ - `cached` maps to `cache_read_input_token_cost`
107
+
108
+ `tokens` must be a non-negative integer. If the requested price field is
109
+ unavailable, the package does not treat the cost as zero or fall back to a
110
+ different price.
111
+
112
+ ### `get_model_details(model) -> dict`
113
+
114
+ Returns a deep copy of the model data. Modifying the returned value does not
115
+ affect the package's internal cache.
116
+
117
+ ## Error handling
118
+
119
+ All domain-specific exceptions inherit from `ModelPriceError`:
120
+
121
+ ```python
122
+ from txaion_model_pricing import (
123
+ InvalidTokenCountError,
124
+ InvalidTokenTypeError,
125
+ NotFound,
126
+ PriceUnavailableError,
127
+ calculate_cost,
128
+ )
129
+
130
+ try:
131
+ cost = calculate_cost("unknown-model", 1_000, "input")
132
+ except NotFound:
133
+ ...
134
+ except PriceUnavailableError:
135
+ ...
136
+ except (InvalidTokenCountError, InvalidTokenTypeError):
137
+ ...
138
+ ```
139
+
140
+ ## Price data
141
+
142
+ The package includes a pinned snapshot of the
143
+ [LiteLLM model price and context-window data](https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json).
144
+ The source commit, retrieval time, and SHA-256 checksum are recorded in
145
+ `src/txaion_model_pricing/data_source.json`. See `THIRD_PARTY_NOTICES.md` for
146
+ third-party attribution and licensing information.
147
+
148
+ Maintainers must specify an immutable commit SHA or tag when updating the
149
+ snapshot:
150
+
151
+ ```bash
152
+ python scripts/update_prices.py <commit-or-tag>
153
+ ```
154
+
155
+ The update tool downloads and validates the JSON before atomically replacing
156
+ the snapshot and its metadata. Moving refs such as `main`, `master`, and
157
+ `latest` are rejected.
158
+
159
+ ## Limitations
160
+
161
+ - Version `0.1.0` only calculates token-based input, output, and cached-input
162
+ costs.
163
+ - Image, audio, search, tool-call, session, and storage pricing are not
164
+ supported by `calculate_cost()`.
165
+ - Model providers may change their prices at any time. Results depend on the
166
+ bundled snapshot and may not match current provider pricing. Verify official
167
+ provider prices before using the results for billing or budget enforcement.
168
+
169
+ ## Development
170
+
171
+ ```bash
172
+ ruff check .
173
+ pytest
174
+ python -m build
175
+ ```
176
+
177
+ ## License
178
+
179
+ This project and the vendored LiteLLM data are redistributed under the MIT
180
+ License. See `LICENSE` and `THIRD_PARTY_NOTICES.md` for details.
@@ -0,0 +1,153 @@
1
+ <p align="center">
2
+ <a href="https://txaion.com">
3
+ <img
4
+ src="https://static.txaion.com/product/model-price/model-price-tp.png"
5
+ alt="Txaion"
6
+ width="360"
7
+ >
8
+ </a>
9
+ </p>
10
+
11
+ <h1 align="center">Txaion Model Pricing</h1>
12
+
13
+ <p align="center">
14
+ Lightweight, cross-provider model pricing for Python.
15
+ </p>
16
+
17
+ <p align="center">
18
+ <strong>English</strong> |
19
+ <a href="README.zh-TW.md">繁體中文</a>
20
+ </p>
21
+
22
+ `Txaion Model Pricing` is a lightweight Python package for querying
23
+ cross-provider model information and calculating USD costs for input, output,
24
+ and cached-input tokens.
25
+
26
+ Developed and maintained by [Txaion](https://txaion.com).
27
+
28
+ The current version is `0.1.0` and requires Python 3.10 or later.
29
+
30
+ ## Installation
31
+
32
+ Install the package from the project directory:
33
+
34
+ ```bash
35
+ python -m pip install .
36
+ ```
37
+
38
+ Install the development dependencies for testing and building:
39
+
40
+ ```bash
41
+ python -m pip install -e ".[dev]"
42
+ ```
43
+
44
+ ## Quick start
45
+
46
+ ```python
47
+ from txaion_model_pricing import calculate_cost, count_models, get_model_details
48
+
49
+ print(count_models())
50
+
51
+ input_cost = calculate_cost("gpt-4o", 1_000_000, "input")
52
+ output_cost = calculate_cost("gpt-4o", 1_000_000, "output")
53
+ cached_cost = calculate_cost("gpt-4o", 1_000_000, "cached")
54
+
55
+ print(input_cost) # Decimal("2.5000000")
56
+ print(output_cost) # Decimal("10.00000")
57
+ print(cached_cost) # Decimal("1.25000000")
58
+
59
+ details = get_model_details("gpt-4o")
60
+ print(details["max_input_tokens"])
61
+ ```
62
+
63
+ All costs are returned as `decimal.Decimal` values. The package does not round
64
+ results or perform currency conversion.
65
+
66
+ ## Public API
67
+
68
+ ### `count_models() -> int`
69
+
70
+ Returns the number of models in the bundled snapshot. Metadata entries such as
71
+ `sample_spec` are excluded.
72
+
73
+ ### `calculate_cost(model, tokens, token_type) -> Decimal`
74
+
75
+ Calculates the USD cost using the model's per-token price:
76
+
77
+ - `input` maps to `input_cost_per_token`
78
+ - `output` maps to `output_cost_per_token`
79
+ - `cached` maps to `cache_read_input_token_cost`
80
+
81
+ `tokens` must be a non-negative integer. If the requested price field is
82
+ unavailable, the package does not treat the cost as zero or fall back to a
83
+ different price.
84
+
85
+ ### `get_model_details(model) -> dict`
86
+
87
+ Returns a deep copy of the model data. Modifying the returned value does not
88
+ affect the package's internal cache.
89
+
90
+ ## Error handling
91
+
92
+ All domain-specific exceptions inherit from `ModelPriceError`:
93
+
94
+ ```python
95
+ from txaion_model_pricing import (
96
+ InvalidTokenCountError,
97
+ InvalidTokenTypeError,
98
+ NotFound,
99
+ PriceUnavailableError,
100
+ calculate_cost,
101
+ )
102
+
103
+ try:
104
+ cost = calculate_cost("unknown-model", 1_000, "input")
105
+ except NotFound:
106
+ ...
107
+ except PriceUnavailableError:
108
+ ...
109
+ except (InvalidTokenCountError, InvalidTokenTypeError):
110
+ ...
111
+ ```
112
+
113
+ ## Price data
114
+
115
+ The package includes a pinned snapshot of the
116
+ [LiteLLM model price and context-window data](https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json).
117
+ The source commit, retrieval time, and SHA-256 checksum are recorded in
118
+ `src/txaion_model_pricing/data_source.json`. See `THIRD_PARTY_NOTICES.md` for
119
+ third-party attribution and licensing information.
120
+
121
+ Maintainers must specify an immutable commit SHA or tag when updating the
122
+ snapshot:
123
+
124
+ ```bash
125
+ python scripts/update_prices.py <commit-or-tag>
126
+ ```
127
+
128
+ The update tool downloads and validates the JSON before atomically replacing
129
+ the snapshot and its metadata. Moving refs such as `main`, `master`, and
130
+ `latest` are rejected.
131
+
132
+ ## Limitations
133
+
134
+ - Version `0.1.0` only calculates token-based input, output, and cached-input
135
+ costs.
136
+ - Image, audio, search, tool-call, session, and storage pricing are not
137
+ supported by `calculate_cost()`.
138
+ - Model providers may change their prices at any time. Results depend on the
139
+ bundled snapshot and may not match current provider pricing. Verify official
140
+ provider prices before using the results for billing or budget enforcement.
141
+
142
+ ## Development
143
+
144
+ ```bash
145
+ ruff check .
146
+ pytest
147
+ python -m build
148
+ ```
149
+
150
+ ## License
151
+
152
+ This project and the vendored LiteLLM data are redistributed under the MIT
153
+ License. See `LICENSE` and `THIRD_PARTY_NOTICES.md` for details.
@@ -0,0 +1,148 @@
1
+ <p align="center">
2
+ <a href="https://txaion.com">
3
+ <img
4
+ src="https://static.txaion.com/product/model-price/model-price-tp.png"
5
+ alt="Txaion"
6
+ width="360"
7
+ >
8
+ </a>
9
+ </p>
10
+
11
+ <h1 align="center">Txaion Model Pricing</h1>
12
+
13
+ <p align="center">
14
+ 輕量、跨供應商的 Python 模型價格套件。
15
+ </p>
16
+
17
+ <p align="center">
18
+ <a href="README.md">English</a> |
19
+ <strong>繁體中文</strong>
20
+ </p>
21
+
22
+ `Txaion Model Pricing` 是一個輕量的 Python 套件,用來查詢跨供應商模型
23
+ 資訊,並依 token 數量計算 input、output 與 cached input 的美元成本。
24
+
25
+ 本專案由 [Txaion](https://txaion.com) 開發與維護。
26
+
27
+ 目前版本為 `0.1.0`,支援 Python 3.10 以上版本。
28
+
29
+ ## 安裝
30
+
31
+ 從本專案目錄安裝:
32
+
33
+ ```bash
34
+ python -m pip install .
35
+ ```
36
+
37
+ 開發環境可安裝測試與建置工具:
38
+
39
+ ```bash
40
+ python -m pip install -e ".[dev]"
41
+ ```
42
+
43
+ ## 快速開始
44
+
45
+ ```python
46
+ from txaion_model_pricing import (
47
+ calculate_cost,
48
+ count_models,
49
+ get_model_details,
50
+ )
51
+
52
+ print(count_models())
53
+
54
+ input_cost = calculate_cost("gpt-4o", 1_000_000, "input")
55
+ output_cost = calculate_cost("gpt-4o", 1_000_000, "output")
56
+ cached_cost = calculate_cost("gpt-4o", 1_000_000, "cached")
57
+
58
+ print(input_cost) # Decimal("2.5000000")
59
+ print(output_cost) # Decimal("10.00000")
60
+ print(cached_cost) # Decimal("1.25000000")
61
+
62
+ details = get_model_details("gpt-4o")
63
+ print(details["max_input_tokens"])
64
+ ```
65
+
66
+ 所有成本均以 `decimal.Decimal` 回傳;套件不會自行四捨五入或轉換貨幣。
67
+
68
+ ## 公開 API
69
+
70
+ ### `count_models() -> int`
71
+
72
+ 回傳快照中的模型數量。`sample_spec` 等資料格式描述不會被計入。
73
+
74
+ ### `calculate_cost(model, tokens, token_type) -> Decimal`
75
+
76
+ 依模型的每 token 價格計算美元成本:
77
+
78
+ - `input` 對應 `input_cost_per_token`
79
+ - `output` 對應 `output_cost_per_token`
80
+ - `cached` 對應 `cache_read_input_token_cost`
81
+
82
+ `tokens` 必須是非負整數。價格資料缺少指定欄位時,套件不會將成本視為零,
83
+ 也不會退回其他價格。
84
+
85
+ ### `get_model_details(model) -> dict`
86
+
87
+ 回傳模型資料的深層副本。修改回傳值不會污染套件內部快取。
88
+
89
+ ## 錯誤處理
90
+
91
+ 所有領域例外都繼承自 `ModelPriceError`:
92
+
93
+ ```python
94
+ from txaion_model_pricing import (
95
+ InvalidTokenCountError,
96
+ InvalidTokenTypeError,
97
+ NotFound,
98
+ PriceUnavailableError,
99
+ calculate_cost,
100
+ )
101
+
102
+ try:
103
+ cost = calculate_cost("unknown-model", 1_000, "input")
104
+ except NotFound:
105
+ ...
106
+ except PriceUnavailableError:
107
+ ...
108
+ except (InvalidTokenCountError, InvalidTokenTypeError):
109
+ ...
110
+ ```
111
+
112
+ ## 價格資料
113
+
114
+ 內附資料是
115
+ [LiteLLM 模型價格與 context-window 資料](https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json)
116
+ 的固定快照。來源 commit、擷取時間與 SHA-256 記錄在
117
+ `src/txaion_model_pricing/data_source.json`,第三方授權資訊請見
118
+ `THIRD_PARTY_NOTICES.md`。
119
+
120
+ 維護者更新資料時必須指定固定 commit SHA 或 tag:
121
+
122
+ ```bash
123
+ python scripts/update_prices.py <commit-or-tag>
124
+ ```
125
+
126
+ 更新工具會先下載及驗證 JSON,再原子替換資料與 metadata;`main`、`master`
127
+ 及 `latest` 等浮動 ref 會被拒絕。
128
+
129
+ ## 限制
130
+
131
+ - `0.1.0` 僅計算 token-based input、output 與 cached input 成本。
132
+ - 圖片、音訊、搜尋、工具呼叫、工作階段及儲存空間等計價方式尚未納入
133
+ `calculate_cost()`。
134
+ - 模型供應商可能隨時調整價格;本套件結果取決於內附快照,不保證與供應商
135
+ 當下價格一致。進行實際帳務或預算控管前,請核對供應商官方價格。
136
+
137
+ ## 開發
138
+
139
+ ```bash
140
+ ruff check .
141
+ pytest
142
+ python -m build
143
+ ```
144
+
145
+ ## 授權
146
+
147
+ 本專案及 vendored LiteLLM 資料皆依 MIT License 再散布。詳細內容請見
148
+ `LICENSE` 與 `THIRD_PARTY_NOTICES.md`。
@@ -0,0 +1,18 @@
1
+ # Third-Party Notices
2
+
3
+ ## LiteLLM model price data
4
+
5
+ `src/txaion_model_pricing/model_prices_and_context_window.json` is a vendored
6
+ snapshot of the LiteLLM model price and context-window data:
7
+
8
+ - Source: https://github.com/BerriAI/litellm
9
+ - Upstream file:
10
+ https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json
11
+ - Upstream copyright: Copyright (c) 2023 Berri AI
12
+ - License: MIT
13
+
14
+ The full LiteLLM license is available at:
15
+ https://github.com/BerriAI/litellm/blob/main/LICENSE
16
+
17
+ The snapshot is redistributed under the MIT License. See `LICENSE` for the
18
+ license text that applies to this project.
@@ -0,0 +1,61 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "txaion-model-pricing"
7
+ version = "0.1.0"
8
+ description = "Cross-provider AI model pricing for Python"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = ["LICENSE", "THIRD_PARTY_NOTICES.md"]
13
+ authors = [
14
+ { name = "Txaion LLC" },
15
+ ]
16
+ dependencies = [
17
+ "orjson>=3.10,<4",
18
+ ]
19
+ classifiers = [
20
+ "Development Status :: 3 - Alpha",
21
+ "Intended Audience :: Developers",
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3.10",
24
+ "Programming Language :: Python :: 3.11",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Typing :: Typed",
27
+ ]
28
+
29
+ [project.optional-dependencies]
30
+ dev = [
31
+ "build>=1.2,<2",
32
+ "pytest>=8,<9",
33
+ "ruff>=0.12,<1",
34
+ ]
35
+
36
+ [project.urls]
37
+ Homepage = "https://txaion.com"
38
+ Repository = "https://github.com/Txaion/txaion-model-pricing"
39
+ Upstream-Data = "https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json"
40
+
41
+ [tool.setuptools]
42
+ package-dir = { "" = "src" }
43
+ include-package-data = true
44
+
45
+ [tool.setuptools.packages.find]
46
+ where = ["src"]
47
+
48
+ [tool.setuptools.package-data]
49
+ txaion_model_pricing = ["*.json", "py.typed"]
50
+
51
+ [tool.pytest.ini_options]
52
+ addopts = "-ra"
53
+ pythonpath = ["src"]
54
+ testpaths = ["tests"]
55
+
56
+ [tool.ruff]
57
+ target-version = "py310"
58
+ line-length = 88
59
+
60
+ [tool.ruff.lint]
61
+ select = ["E", "F", "I", "UP", "B", "SIM", "RUF"]