Skip to content

Commit ff774ae

Browse files
Switch cost estimation to genai-prices with disclaimer
1 parent e165b8e commit ff774ae

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ dependencies = [
3535
"tomli==2.2.1",
3636
"claude-agent-sdk>=0.1.0",
3737
"tiktoken==0.12.0",
38+
"genai-prices==0.0.51",
3839
]
3940
classifiers = [
4041
"Development Status :: 5 - Production/Stable",

python_gpt_po/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ def main():
231231
cost_str = f"${data['cost']:.4f}" if data['cost'] is not None else "unavailable"
232232
print(f" - {lang:5}: {data['tokens']:8,} tokens | {cost_str}")
233233

234+
print("\nNote: Cost estimates are approximate and may not reflect current provider pricing.")
234235
print(f"{'=' * 40}\n")
235236

236237
if estimation['total_tokens'] == 0:

python_gpt_po/tests/unit/test_cost_estimator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_minimal_token_math(self):
3737
self.assertEqual(t3, t1 * 3)
3838

3939
def test_pricing_lookup(self):
40-
"""Verify static pricing lookup."""
40+
"""Verify dynamic pricing lookup via genai-prices."""
4141
po_path = os.path.join(self.test_dir, "test.po")
4242
po = polib.POFile()
4343
po.append(polib.POEntry(msgid="Test", msgstr=""))

python_gpt_po/utils/cost_estimator.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,8 @@
1111

1212

1313
class CostEstimator:
14-
"""Estimates token usage and costs for translation tasks."""
15-
16-
# Pricing per 1,000 tokens (Input price, Output price)
17-
# Data sourced from provider websites (Jan 2026)
18-
PRICING = {
19-
"gpt-4o": (0.0025, 0.010),
20-
"gpt-4o-mini": (0.00015, 0.0006),
21-
"claude-3-5-sonnet": (0.003, 0.015),
22-
"claude-3-5-sonnet-20241022": (0.003, 0.015),
23-
"deepseek-chat": (0.00014, 0.00028),
24-
"deepseek-v3": (0.00014, 0.00028),
25-
}
26-
27-
OUTPUT_MULTIPLIER = 1.3 # Conservative estimate for translation expansion
14+
# Conservative estimate for translation expansion
15+
OUTPUT_MULTIPLIER = 1.3
2816

2917
@classmethod
3018
def estimate_cost(
@@ -124,5 +112,15 @@ def _get_token_count(text: str, model: str) -> int:
124112

125113
@classmethod
126114
def _get_pricing(cls, model: str) -> Optional[Tuple[float, float]]:
127-
"""Lookup pricing for the active model name."""
128-
return cls.PRICING.get(model)
115+
"""Lookup pricing for the active model name using genai-prices."""
116+
try:
117+
import genai_prices
118+
from genai_prices.types import Usage
119+
120+
# Exact match only. genai-prices raises LookupError if not found.
121+
# We use a unit usage of 1000 tokens to get the price per 1k tokens.
122+
usage = Usage(input_tokens=1000, output_tokens=1000)
123+
price_detail = genai_prices.calc_price(usage, model)
124+
return float(price_detail.input_price), float(price_detail.output_price)
125+
except (ImportError, LookupError, Exception):
126+
return None

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ responses==0.25.6
1111
isort==6.0.1
1212
tomli==2.2.1
1313
tiktoken==0.12.0
14+
genai-prices==0.0.51

0 commit comments

Comments
 (0)