fix: surface poll error message in ModelsLab video generation

When _poll_sync returns status=error, raise BaseLLMException with
the actual error message from ModelsLab API instead of falling
through to the generic 'Unexpected status' error.

Also adds test for the poll-returns-error path (fixes Greptile review).

Addresses feedback from greptile-apps in PR review.
This commit is contained in:
adhikjoshi 2026-03-02 06:04:57 +05:30
parent 89b88ee831
commit 110f6241ce
2 changed files with 34 additions and 0 deletions

View file

@ -179,6 +179,13 @@ class ModelsLabVideoConfig(BaseVideoConfig):
response_data = self._poll_sync(request_id)
status = response_data.get("status", "")
if status == "error":
raise BaseLLMException(
status_code=500,
message=response_data.get("message", "ModelsLab video generation failed"),
headers={},
)
if status == "success":
output = response_data.get("output", [])
output_url = output[0] if output else None

View file

@ -186,3 +186,30 @@ class TestModelsLabVideoTransformation:
assert "req_789" in url
assert "fetch" in url
assert body["key"] == "test-api-key"
def test_transform_video_create_response_poll_error_surfaces_message(self):
"""When _poll_sync returns status=error, the actual error message is raised."""
from litellm.llms.base_llm.chat.transformation import BaseLLMException
mock_response = Mock(spec=httpx.Response)
mock_response.status_code = 200
mock_response.headers = {}
mock_response.json.return_value = {
"status": "processing",
"request_id": "req_err",
}
poll_result = {
"status": "error",
"message": "Insufficient credits",
}
with patch.object(self.config, "_poll_sync", return_value=poll_result):
with pytest.raises(BaseLLMException) as exc_info:
self.config.transform_video_create_response(
model="i2vgen-xl",
raw_response=mock_response,
logging_obj=self.mock_logging_obj,
)
assert "Insufficient credits" in str(exc_info.value)