From db120c524b60ffa78ced7068d66f10f398e70338 Mon Sep 17 00:00:00 2001 From: shin-bot-litellm Date: Sat, 31 Jan 2026 13:36:27 -0800 Subject: [PATCH] fix(test): accept both AuthenticationError and InternalServerError in batch_completion test (#20186) The test uses an invalid API key to verify that batch_completion returns exceptions rather than raising them. However, depending on network conditions, the error may be: - AuthenticationError: API properly rejected the invalid key - InternalServerError: Connection error occurred before API could respond Both are valid outcomes for this test case. Co-authored-by: shin-bot-litellm --- .../test_batch_completion_return_exceptions.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/local_testing/test_batch_completion_return_exceptions.py b/tests/local_testing/test_batch_completion_return_exceptions.py index 2d2ea8675e..24540edf31 100644 --- a/tests/local_testing/test_batch_completion_return_exceptions.py +++ b/tests/local_testing/test_batch_completion_return_exceptions.py @@ -8,11 +8,19 @@ msg2 = [{"role": "user", "content": "hi 2"}] def test_batch_completion_return_exceptions_true(): - """Test batch_completion's return_exceptions.""" + """Test batch_completion's return_exceptions. + + With an invalid API key, we expect an error to be returned rather than raised. + The error type may be AuthenticationError (from API) or InternalServerError + (from connection issues), depending on network conditions. + """ res = litellm.batch_completion( model="gpt-3.5-turbo", messages=[msg1, msg2], api_key="sk_xxx", # deliberately set invalid key ) - assert isinstance(res[0], litellm.exceptions.AuthenticationError) + # batch_completion should return exceptions rather than raise them + # Accept either AuthenticationError (API rejected key) or InternalServerError (network issues) + assert isinstance(res[0], (litellm.exceptions.AuthenticationError, litellm.exceptions.InternalServerError)), \ + f"Expected AuthenticationError or InternalServerError, got {type(res[0])}"