Skip to content

Fix speech-to-text fallbacks #11663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

colesmcintosh
Copy link
Collaborator

@colesmcintosh colesmcintosh commented Jun 12, 2025

Title

Fix speech-to-text fallbacks

Relevant issues

Fixes issue where speech-to-text (/audio/transcriptions) fallbacks were not working

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
Screenshot 2025-06-12 at 9 37 05 AM
  • 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

Changes

Root Cause

Fixed critical infinite recursion bug in fallback system that was preventing speech-to-text fallbacks from working:

  1. Infinite Recursion Bug: In litellm/router_utils/fallback_event_handlers.py line 139, the fallback handler was calling async_function_with_fallbacks instead of original_function, creating infinite loops.

  2. Parameter Loss Bug: In litellm/router.py line 3598, kwargs.pop("original_function") was permanently removing the function reference needed for fallbacks.

  3. Parameter Conflict Bug: original_function was being passed as both positional and keyword arguments causing "multiple values" errors.

Fixes Applied

  • Fixed infinite recursion: Changed fallback handler to call original_function instead of async_function_with_fallbacks
  • Preserved function reference: Changed .pop("original_function") to .get("original_function") to maintain parameter
  • Resolved parameter conflicts: Remove original_function from kwargs before calling to avoid conflicts

Testing

  • Added tests in tests/test_litellm/test_router.py:
    • test_router_transcription_fallbacks() for same-provider fallbacks
    • test_router_transcription_fallbacks_cross_provider() for cross-provider fallbacks
  • All 11 router tests pass

Documentation

  • Updated docs/my-website/docs/audio_transcription.md with:
    • Client-side fallback examples using litellm.transcription()
    • Router configuration examples
    • Proxy YAML configuration examples
    • Testing instructions with mock_testing_fallbacks=true

Impact

  • Speech-to-text fallbacks now work correctly
  • Maintains backward compatibility
  • No breaking changes to existing API
  • Comprehensive test coverage ensures reliability

The fix resolves the core issue preventing audio transcription fallbacks while maintaining all existing functionality.

colesmcintosh and others added 3 commits June 12, 2025 09:13
…s and examples. Update Router class to handle fallbacks more effectively, ensuring proper function calls without infinite recursion. Add tests for transcription fallbacks, covering both same-provider and cross-provider scenarios.
…usage and fallback configurations. Replace "whisper" with "whisper-1" in code examples, enhance fallback implementation details, and streamline Router and proxy configurations for better clarity and usability.
Copy link

vercel bot commented Jun 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 26, 2025 8:35pm

@colesmcintosh colesmcintosh changed the title Fix infinite recursion in speech-to-text fallbacks Fix speech-to-text fallbacks Jun 12, 2025
….py. Add async_transcription_with_fallbacks and transcription_with_fallbacks functions to handle model fallbacks during transcription, enhancing error handling and preventing infinite recursion. Update atranscription and transcription functions to utilize these new fallback mechanisms.
…nts for model and file parameters, improving code clarity and type safety. Include litellm_logging_obj in the function call to support logging during transcription attempts.
…ling logic. This simplifies the atranscription and transcription functions, delegating fallback management to dedicated utilities, enhancing code clarity and maintainability.
…to streamline the codebase. This change focuses on enhancing clarity and maintainability by delegating fallback handling to dedicated utilities, following recent refactoring efforts.
- Implemented `transcription` and `_transcription` methods to handle audio file input and model selection.
- Added example usage in the docstring for clarity.
- Enhanced error handling and logging for better debugging and tracking of calls.
- Introduced a new test `test_router_sync_transcription_fallbacks` to verify that the Router's synchronous transcription method correctly handles fallbacks between primary and backup models.
- The test simulates an API error for the primary model and checks that the backup model is used successfully, ensuring robust error handling in the transcription process.
@ishaan-jaff
Copy link
Contributor

closing as the fallbacks work already

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.

2 participants