From eacea13a257d934627714b554dd1fd2c2b44b261 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Thu, 13 Aug 2026 21:24:54 -0700 Subject: [PATCH] fix(batches): persist real terminal status when billing expired batches --- .../litellm_enterprise/proxy/common_utils/check_batch_cost.py | 2 +- tests/proxy_unit_tests/test_check_batch_cost.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py b/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py index 00cc184a515..38266f6c3ea 100644 --- a/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py +++ b/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py @@ -698,7 +698,7 @@ class CheckBatchCost: # mark the job as complete try: update_data: dict = { - "status": "complete", + "status": response.status if response.status != "completed" else "complete", "file_object": response.model_dump_json(), } if self._has_batch_processed_column: diff --git a/tests/proxy_unit_tests/test_check_batch_cost.py b/tests/proxy_unit_tests/test_check_batch_cost.py index 7616a1d5ddc..ca9d5f7f7d4 100644 --- a/tests/proxy_unit_tests/test_check_batch_cost.py +++ b/tests/proxy_unit_tests/test_check_batch_cost.py @@ -1036,6 +1036,9 @@ class TestCheckBatchCost: 1 ]["data"] assert update_data["batch_processed"] is True + assert ( + update_data["status"] == "expired" + ), "billed expired batch must keep its real terminal status in the DB" @pytest.mark.asyncio async def test_raw_output_file_id_converted_to_managed_id(