fix(cost): keep the deployment's OCR page rate when the model has no published price

When a deployment priced one OCR batch family and the other still needed a
published rate, a failed cost-map lookup returned zero for the whole line and
discarded the deployment rate that was already resolved. Those pages were
billed as free. The lookup failure now only logs, and the families the
deployment prices are billed at the configured rate
This commit is contained in:
mateo-berri 2026-09-19 01:59:39 -07:00
parent 00214ac371
commit dd79c1f77d
2 changed files with 15 additions and 2 deletions

View file

@ -2151,11 +2151,11 @@ def ocr_batch_cost(
)
if needs_published_pricing and published is None:
verbose_logger.warning(
"OCR batch cost: model=%s custom_llm_provider=%s has no pricing entry; returning 0.0 cost.",
"OCR batch cost: model=%s custom_llm_provider=%s has no pricing entry; "
"billing only the per-page families the deployment prices.",
_single_log_line(model),
_single_log_line(custom_llm_provider),
)
return 0.0, 0.0
page_rate: Final = (
deployment_page_rate

View file

@ -1957,6 +1957,19 @@ def test_ocr_rows_keep_the_published_page_rate_when_the_deployment_prices_only_a
assert result.cost == pytest.approx(4 * 0.002 + 4 * 0.01)
def test_ocr_rows_keep_the_deployment_page_rate_when_the_unmapped_model_has_no_annotation_price(monkeypatch):
def _unmapped(model, custom_llm_provider=None):
raise Exception(f"This model isn't mapped yet: {model}")
monkeypatch.setattr(litellm, "get_model_info", _unmapped)
result = bu._aggregate_batch_cost_usage_models(
entries=[_ocr_row(4, annotation_pages=4, model="my-private-ocr-model")],
custom_llm_provider="mistral",
model_info={"ocr_cost_per_page_batches": 0.001},
)
assert result.cost == pytest.approx(4 * 0.001 + 4 * 0.001)
def test_ocr_rows_bill_the_deployment_sync_page_rate_over_the_published_batch_rate(monkeypatch):
monkeypatch.setattr(
litellm, "get_model_info", lambda model, custom_llm_provider=None: pytest.fail("cost map must not be consulted")