From c02f40a6bba5811cbe411650cf7e3a7b331d911a Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Wed, 28 Oct 2026 14:44:39 -0700 Subject: [PATCH] refactor(bedrock): return unsupported transcription params as a value and raise at the param step --- .../bedrock/audio_transcription/__init__.py | 14 +++++++++----- litellm/utils.py | 17 +++++++++++------ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/litellm/llms/bedrock/audio_transcription/__init__.py b/litellm/llms/bedrock/audio_transcription/__init__.py index 6588d75bab6..bc74e9c38ab 100644 --- a/litellm/llms/bedrock/audio_transcription/__init__.py +++ b/litellm/llms/bedrock/audio_transcription/__init__.py @@ -1,12 +1,12 @@ import base64 import math from collections.abc import Mapping +from dataclasses import dataclass from typing import Final import httpx from pydantic import BaseModel, ConfigDict -from litellm.exceptions import UnsupportedParamsError from litellm.litellm_core_utils.audio_utils.utils import process_audio_file from litellm.rust_bridge import runtime from litellm.rust_bridge.catalog import Route, RouteContext @@ -45,16 +45,20 @@ def _rejection(key: str, value: object) -> str | None: return None +@dataclass(frozen=True, slots=True) +class UnsupportedTranscriptionParams: + message: str + + def map_openai_transcription_params( non_default_params: Mapping[str, object], drop_params: bool -) -> Mapping[str, object]: +) -> Mapping[str, object] | UnsupportedTranscriptionParams: rejections: Final = { key: reason for key, value in non_default_params.items() if (reason := _rejection(key, value)) is not None } if rejections and not drop_params: - raise UnsupportedParamsError( - message=f"{' '.join(rejections.values())} To drop it from the call, set `litellm.drop_params = True`.", - llm_provider="bedrock", + return UnsupportedTranscriptionParams( + message=f"{' '.join(rejections.values())} To drop it from the call, set `litellm.drop_params = True`." ) return { key: _as_float(value) if key == "temperature" else value diff --git a/litellm/utils.py b/litellm/utils.py index da7309d7f29..2eccc9f5ce3 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -4107,13 +4107,18 @@ def get_optional_params_transcription( drop_params=drop_params if drop_params is not None else False, ) elif custom_llm_provider == "bedrock": - from litellm.llms.bedrock.audio_transcription import map_openai_transcription_params - - optional_params = dict( - map_openai_transcription_params( - non_default_params, drop_params=drop_params is True or litellm.drop_params is True - ) + from litellm.llms.bedrock.audio_transcription import ( + UnsupportedTranscriptionParams, + map_openai_transcription_params, ) + + match map_openai_transcription_params( + non_default_params, drop_params=drop_params is True or litellm.drop_params is True + ): + case UnsupportedTranscriptionParams(message=message): + raise UnsupportedParamsError(message=message, llm_provider="bedrock") + case mapped_params: + optional_params = dict(mapped_params) elif provider_config is not None: # custom audio transcription config supported_params = provider_config.get_supported_openai_params(model=model) _check_valid_arg(supported_params=supported_params)