unique_toolkit 2026.46.0.dev3__py3-none-any.whl → 2026.46.0.dev4__py3-none-any.whl
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.
- unique_toolkit/language_model/model_costs.py +31 -4
- {unique_toolkit-2026.46.0.dev3.dist-info → unique_toolkit-2026.46.0.dev4.dist-info}/METADATA +1 -1
- {unique_toolkit-2026.46.0.dev3.dist-info → unique_toolkit-2026.46.0.dev4.dist-info}/RECORD +4 -4
- {unique_toolkit-2026.46.0.dev3.dist-info → unique_toolkit-2026.46.0.dev4.dist-info}/WHEEL +0 -0
|
@@ -145,7 +145,12 @@ def calculate_invocation_cost_usd(
|
|
|
145
145
|
token_usage: LanguageModelTokenUsage,
|
|
146
146
|
catalog: ModelCostCatalog | None = None,
|
|
147
147
|
) -> float | None:
|
|
148
|
-
"""Calculate invocation cost
|
|
148
|
+
"""Calculate invocation cost, pricing cache reads and writes at their own rates.
|
|
149
|
+
|
|
150
|
+
Mirrors node-chat's ``ModelCostService.computeSpent`` so debug-info spend and
|
|
151
|
+
the platform ledger agree. Cache reads and writes are counted inside
|
|
152
|
+
``prompt_tokens``; a row without a cache rate bills them at ``input``.
|
|
153
|
+
"""
|
|
149
154
|
|
|
150
155
|
if token_usage.prompt_tokens is None or token_usage.completion_tokens is None:
|
|
151
156
|
return None
|
|
@@ -163,10 +168,32 @@ def calculate_invocation_cost_usd(
|
|
|
163
168
|
if model_cost is None:
|
|
164
169
|
return None
|
|
165
170
|
|
|
166
|
-
|
|
167
|
-
|
|
171
|
+
prompt_tokens = token_usage.prompt_tokens
|
|
172
|
+
cache_read_tokens = min(token_usage.cached_tokens or 0, prompt_tokens)
|
|
173
|
+
cache_write_tokens = min(
|
|
174
|
+
token_usage.cache_write_tokens or 0, prompt_tokens - cache_read_tokens
|
|
175
|
+
)
|
|
176
|
+
uncached_tokens = prompt_tokens - cache_read_tokens - cache_write_tokens
|
|
177
|
+
cache_read_rate = (
|
|
178
|
+
model_cost.cached_input
|
|
179
|
+
if model_cost.cached_input is not None
|
|
180
|
+
else model_cost.input
|
|
168
181
|
)
|
|
182
|
+
# The usage payload does not say which TTL a write used; node-chat bills an
|
|
183
|
+
# unsplit write at the 5-minute rate too.
|
|
184
|
+
cache_write_rate = (
|
|
185
|
+
model_cost.cache_write
|
|
186
|
+
if model_cost.cache_write is not None
|
|
187
|
+
else model_cost.input
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
input_multiplier, completion_multiplier = model_cost.multipliers_for(prompt_tokens)
|
|
169
191
|
return (
|
|
170
|
-
|
|
192
|
+
(
|
|
193
|
+
uncached_tokens * model_cost.input
|
|
194
|
+
+ cache_read_tokens * cache_read_rate
|
|
195
|
+
+ cache_write_tokens * cache_write_rate
|
|
196
|
+
)
|
|
197
|
+
* input_multiplier
|
|
171
198
|
+ token_usage.completion_tokens * model_cost.completion * completion_multiplier
|
|
172
199
|
) / _TOKENS_PER_MILLION
|
{unique_toolkit-2026.46.0.dev3.dist-info → unique_toolkit-2026.46.0.dev4.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: unique-toolkit
|
|
3
|
-
Version: 2026.46.0.
|
|
3
|
+
Version: 2026.46.0.dev4
|
|
4
4
|
Summary:
|
|
5
5
|
Author: Cedric Klinkert, Martin Fadler, Sadique Sheik, Fabian Schläpfer, Pascal Hauri, Ejiroghene Oki-Peter, Rami Azouz, Ricardo Visini, Sanzio Monti
|
|
6
6
|
Author-email: Cedric Klinkert <cedric.klinkert@unique.ch>, Martin Fadler <martin.fadler@unique.ch>, Sadique Sheik <sadique@unique.ch>, Fabian Schläpfer <fabian@unique.ch>, Pascal Hauri <pascal@unique.ch>, Ejiroghene Oki-Peter <oki-peter.ejiroghene@unique.ai>, Rami Azouz <rami.ext@unique.ch>, Ricardo Visini <ricardo.visini@unique.ch>, Sanzio Monti <sanzio.monti@unique.ai>
|
|
@@ -402,7 +402,7 @@ unique_toolkit/language_model/errors.py,sha256=0nm4psGCGJM2B7LIyKXy7WuswRzwARIgI
|
|
|
402
402
|
unique_toolkit/language_model/functions.py,sha256=6Le6dDm9su6xk3sQ8IPiyUn2tf1qvzxHVUhyTTgP8Kw,28109
|
|
403
403
|
unique_toolkit/language_model/infos.py,sha256=IAwSmmFEdX51bYXsx62XQqJ4wwaJMz7fGf3nsNcHlZE,183833
|
|
404
404
|
unique_toolkit/language_model/invocation_stats.py,sha256=CQbpUz394IsVd8eNTB1gPSMt5f0UXmkN1amNsqtAW6U,5857
|
|
405
|
-
unique_toolkit/language_model/model_costs.py,sha256=
|
|
405
|
+
unique_toolkit/language_model/model_costs.py,sha256=AVHAuMTzsglzusWsVF_xwBVEndST-TVCVi0H49OhdvE,7419
|
|
406
406
|
unique_toolkit/language_model/prompt.py,sha256=JSawaLjQg3VR-E2fK8engFyJnNdk21zaO8pPIodzN4Q,3991
|
|
407
407
|
unique_toolkit/language_model/provider_token_count.py,sha256=mS597Mvrc7EsAc9iJSmASIEwvETSPLtIEsWxusPrQVc,5337
|
|
408
408
|
unique_toolkit/language_model/reference.py,sha256=T3wr2jP_uRg5wKVIbKqLbxJlcgxfbZQGq3XdjbQ2kSo,6984
|
|
@@ -430,6 +430,6 @@ unique_toolkit/short_term_memory/service.py,sha256=2JMBEBn6GoyK-a0xvdcWpPft-3C74
|
|
|
430
430
|
unique_toolkit/smart_rules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
431
431
|
unique_toolkit/smart_rules/compile.py,sha256=vRe0aMJWuVIK-VsqomgxQImzke7MDmwgSxxJfYCa7zw,1386
|
|
432
432
|
unique_toolkit/test_utilities/events.py,sha256=FLrhMh0A_mQutAUjoD0FdMcVQ4Gq31r35OVGzRjvLro,6760
|
|
433
|
-
unique_toolkit-2026.46.0.
|
|
434
|
-
unique_toolkit-2026.46.0.
|
|
435
|
-
unique_toolkit-2026.46.0.
|
|
433
|
+
unique_toolkit-2026.46.0.dev4.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
|
|
434
|
+
unique_toolkit-2026.46.0.dev4.dist-info/METADATA,sha256=S3pb1MeBajfmMuiG1-DzzHjYwlu1YKRqAbgpw0XhhWA,7821
|
|
435
|
+
unique_toolkit-2026.46.0.dev4.dist-info/RECORD,,
|
|
File without changes
|