Skip to content

Commit 2d06919

Browse files
committed
All i do is fix model cost issues now
1 parent dcbd4a7 commit 2d06919

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

src/commands/models.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,21 @@ async def list_models_async():
104104
input_cost_per_token = pricing.get('input_cost_per_1m_tokens', 0)
105105
output_cost_per_token = pricing.get('output_cost_per_1m_tokens', 0)
106106

107-
# Convert from per-token to per-million-tokens for display
108-
input_cost_per_million = input_cost_per_token * 1_000_000
109-
output_cost_per_million = output_cost_per_token * 1_000_000
107+
# The cached values can be either per-token or per-million-tokens
108+
# Very small values (< 0.01) are per-token, larger values are per-million-tokens
109+
if input_cost_per_token > 0 and input_cost_per_token < 0.01:
110+
# Values are per-token, convert to per-million-tokens
111+
input_cost_per_million = input_cost_per_token * 1_000_000
112+
else:
113+
# Values are already per-million-tokens
114+
input_cost_per_million = input_cost_per_token
115+
116+
if output_cost_per_token > 0 and output_cost_per_token < 0.01:
117+
# Values are per-token, convert to per-million-tokens
118+
output_cost_per_million = output_cost_per_token * 1_000_000
119+
else:
120+
# Values are already per-million-tokens
121+
output_cost_per_million = output_cost_per_token
110122

111123
# Format costs
112124
def format_list_cost(cost):
@@ -194,8 +206,20 @@ async def search_models_async():
194206

195207
for model in matching_models:
196208
pricing = model.get('pricing', {})
197-
input_cost = pricing.get('input_cost_per_1m_tokens', 0)
198-
output_cost = pricing.get('output_cost_per_1m_tokens', 0)
209+
input_cost_per_token = pricing.get('input_cost_per_1m_tokens', 0)
210+
output_cost_per_token = pricing.get('output_cost_per_1m_tokens', 0)
211+
212+
# Convert per-token costs to per-million-tokens for display
213+
# Very small values (< 0.01) are per-token, larger values are per-million-tokens
214+
if input_cost_per_token > 0 and input_cost_per_token < 0.01:
215+
input_cost = input_cost_per_token * 1_000_000
216+
else:
217+
input_cost = input_cost_per_token
218+
219+
if output_cost_per_token > 0 and output_cost_per_token < 0.01:
220+
output_cost = output_cost_per_token * 1_000_000
221+
else:
222+
output_cost = output_cost_per_token
199223

200224
table.add_row(
201225
(model.get('provider', 'Unknown')).title(),

src/models/openrouter.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,21 @@ def _parse_model_data(self, model_data: Dict[str, Any]) -> Optional[Dict[str, An
418418
output_cost = 0.0
419419

420420
if pricing_info:
421-
# OpenRouter pricing is typically in the format per 1M tokens
421+
# OpenRouter pricing can come in different formats - handle both
422+
# Format 1: Direct per-1M-token pricing
422423
input_cost = float(pricing_info.get('prompt', 0))
423424
output_cost = float(pricing_info.get('completion', 0))
425+
426+
# Format 2: Already converted per-1M-token pricing
427+
if input_cost == 0 and output_cost == 0:
428+
input_cost = float(pricing_info.get('input_cost_per_1m_tokens', 0))
429+
output_cost = float(pricing_info.get('output_cost_per_1m_tokens', 0))
430+
431+
# Convert from per-token to per-1M-tokens if values are very small (likely per-token)
432+
if input_cost > 0 and input_cost < 0.01:
433+
input_cost = input_cost * 1_000_000
434+
if output_cost > 0 and output_cost < 0.01:
435+
output_cost = output_cost * 1_000_000
424436

425437
# Extract capabilities and features
426438
capabilities = []

0 commit comments

Comments
 (0)