Skip to content

fix transcription exception handling - /audio/transcriptions - #16791

Merged
ishaan-jaff merged 2 commits into
BerriAI:mainfrom
otaviofbrito:fix/audio-transcription-exception
Nov 26, 2025
Merged

fix transcription exception handling - /audio/transcriptions#16791
ishaan-jaff merged 2 commits into
BerriAI:mainfrom
otaviofbrito:fix/audio-transcription-exception

Conversation

@otaviofbrito

@otaviofbrito otaviofbrito commented Nov 18, 2025

Copy link
Copy Markdown
Contributor

Title

fix transcription exception handling - /audio/transcriptions

Relevant issues

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🐛 Bug Fix
✅ Test

Changes

Removed the try-except block that was masking the real exception and causing all errors to return a 500 status code.

Before:
image

After:

Screenshot 2025-11-18 at 19 25 31

200:

image

@vercel

vercel Bot commented Nov 18, 2025

Copy link
Copy Markdown

@otaviofbrito is attempting to deploy a commit to the CLERKIEAI Team on Vercel.

A member of the Team first needs to authorize it.

@AlexsanderHamir

Copy link
Copy Markdown
Contributor

Thank you @otaviofbrito, I believe something like this would solve this specific issue:

        except Exception as e:
            status_code = _extract_exception_status_code(e, default=500)
            raise HTTPException(status_code=status_code, detail=str(e))
        finally:
            file_object.close()
def _extract_exception_status_code(e: Exception, default: int = 500) -> int:
 
    status_code = getattr(e, "status_code", None)
    if status_code is None:
        status_code = getattr(e, "code", None)
    
    if status_code is not None:
        if isinstance(status_code, str):
            try:
                status_code = int(status_code)
            except (ValueError, TypeError):
                status_code = default
    else:
        status_code = default
    
    return status_code

@otaviofbrito

Copy link
Copy Markdown
Contributor Author

Thanks for the reply, @AlexsanderHamir ! I initially tried a similar approach, but it turns out the logging messages are being duplicated.

Is there a reason for raising HTTP exceptions? When that happens, async_log_failure_event ends up being called twice. Here's what I found:

  1. async_log_failure_event is first triggered inside the LLM API call through the hook — this logs the first message.
  2. After that, the code hits this section
  3. Then it goes here, where self._is_proxy_only_llm_api_error evaluates to true because the error is an HTTP exception, causing it to log again in self._handle_logging_proxy_only_error

The workaround I've found was to avoid raising the HTTP exception. With that, the message is only logged once.

@ghost

ghost commented Nov 19, 2025

Copy link
Copy Markdown

@otaviofbrito why not just re-raise the error, seems like we should maintain the finally block, so we close the file object

@ishaan-jaff ishaan-jaff left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ishaan-jaff
ishaan-jaff merged commit 6e5c7c0 into BerriAI:main Nov 26, 2025
3 of 6 checks passed
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…#16791)

* fix transcription exception handling

* reraise the exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants