diff --git a/litellm/litellm_core_utils/exception_mapping_utils.py b/litellm/litellm_core_utils/exception_mapping_utils.py index 9ae30bf4dde..82708d412c9 100644 --- a/litellm/litellm_core_utils/exception_mapping_utils.py +++ b/litellm/litellm_core_utils/exception_mapping_utils.py @@ -2195,15 +2195,12 @@ def _map_openrouter_exception( ) else: # if no status code then it is an APIConnectionError: https://github.com/openai/openai-python#handling-errors - fallback_api_base: Final = ( - "https://api.opper.ai/v3/compat" if custom_llm_provider == "opper" else "https://api.openai.com/v1/" - ) raise APIConnectionError( message=f"APIConnectionError: {exception_provider} - {error_str}", llm_provider=custom_llm_provider, model=model, litellm_debug_info=extra_information, - request=httpx.Request(method="POST", url=fallback_api_base), + request=httpx.Request(method="POST", url="https://api.openai.com/v1/"), ) @@ -2612,7 +2609,7 @@ def exception_type( exception_provider=exception_provider, extra_information=extra_information, ) - if custom_llm_provider in ("openrouter", "opper"): + if custom_llm_provider == "openrouter": _map_openrouter_exception( model=model, original_exception=mappable_exception, diff --git a/litellm/litellm_core_utils/get_llm_provider_logic.py b/litellm/litellm_core_utils/get_llm_provider_logic.py index c54b7b100e9..f7feb9bdf94 100644 --- a/litellm/litellm_core_utils/get_llm_provider_logic.py +++ b/litellm/litellm_core_utils/get_llm_provider_logic.py @@ -703,11 +703,9 @@ def _get_openai_compatible_provider_info( dynamic_api_key = api_key or get_secret_str("TENCENT_API_KEY") elif custom_llm_provider == "opper": - # rebind-ok: provider chain assigns api_base per branch - api_base = api_base or get_secret("OPPER_API_BASE") or OPPER_API_BASE + api_base = api_base or get_secret("OPPER_API_BASE") or OPPER_API_BASE # rebind-ok: set per provider branch - # rebind-ok: provider chain assigns dynamic_api_key per branch - dynamic_api_key = api_key or get_secret_str("OPPER_API_KEY") + dynamic_api_key = api_key or get_secret_str("OPPER_API_KEY") # rebind-ok: set per provider branch elif custom_llm_provider == "fireworks_ai": # fireworks is openai compatible, we just need to set this to custom_openai and have the api_base be https://api.fireworks.ai/inference/v1 ( diff --git a/litellm/llms/opper/chat/transformation.py b/litellm/llms/opper/chat/transformation.py index 852dcf436c9..cfa486b178b 100644 --- a/litellm/llms/opper/chat/transformation.py +++ b/litellm/llms/opper/chat/transformation.py @@ -3,7 +3,7 @@ Translate from OpenAI's `/v1/chat/completions` to the Opper AI gateway's `/v3/co """ from collections.abc import AsyncIterator, Iterator -from typing import Final +from typing import TYPE_CHECKING, Final import httpx @@ -21,6 +21,9 @@ from ...openai.chat.gpt_transformation import ( ) from ..common_utils import OpperException +if TYPE_CHECKING: + import tiktoken + class OpperConfig(OpenAIGPTConfig): @property @@ -65,7 +68,7 @@ class OpperConfig(OpenAIGPTConfig): messages: list[AllMessageValues], # mutable-ok: mirrors the OpenAIGPTConfig signature optional_params: dict, # mutable-ok: mirrors the OpenAIGPTConfig signature litellm_params: dict, # mutable-ok: mirrors the OpenAIGPTConfig signature - encoding: object, + encoding: "tiktoken.Encoding | None", api_key: str | None = None, json_mode: bool | None = None, ) -> ModelResponse: @@ -88,7 +91,7 @@ class OpperConfig(OpenAIGPTConfig): if response_json.get("usage"): response_cost: Final = response_json["usage"].get("cost") if response_cost is not None: - headers: Final = transformed._hidden_params.setdefault( + headers: Final = transformed._hidden_params.setdefault( # pyright: ignore[reportPrivateUsage] # the cost hand-off channel every provider writes "additional_headers", {}, # mutable-ok: _hidden_params carries plain dicts ) diff --git a/litellm/main.py b/litellm/main.py index 6ad63481476..423e1e591f2 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -3499,7 +3499,7 @@ def _complete_opper(ctx: _CompletionDispatchContext) -> _CompletionDispatchResul litellm_params=litellm_params, shared_session=shared_session, custom_llm_provider="opper", - timeout=timeout, + timeout=timeout, # pyright: ignore[reportArgumentType] # ctx types timeout wider than the handler headers=headers, encoding=_get_encoding(), api_key=api_key, diff --git a/litellm/utils.py b/litellm/utils.py index 596189928b1..d5014f5630b 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -4700,13 +4700,11 @@ def get_optional_params( drop_params=bool(drop_params), ) elif custom_llm_provider == "opper": - optional_params = ( - litellm.OpperConfig().map_openai_params( # rebind-ok: provider chain assigns optional_params per branch - non_default_params=non_default_params, - optional_params=optional_params, - model=model, - drop_params=(drop_params if drop_params is not None and isinstance(drop_params, bool) else False), - ) + optional_params = litellm.OpperConfig().map_openai_params( # rebind-ok: set per provider branch + non_default_params=non_default_params, + optional_params=optional_params, + model=model, + drop_params=(drop_params if drop_params is not None and isinstance(drop_params, bool) else False), ) elif custom_llm_provider == "watsonx": optional_params = litellm.IBMWatsonXChatConfig().map_openai_params( diff --git a/tests/test_litellm/llms/opper/test_opper.py b/tests/test_litellm/llms/opper/test_opper.py index f0838933923..664f0aabba1 100644 --- a/tests/test_litellm/llms/opper/test_opper.py +++ b/tests/test_litellm/llms/opper/test_opper.py @@ -303,14 +303,19 @@ def test_opper_preserves_cache_control_in_content(): def test_opper_connection_error_reports_opper_endpoint(): - """Status-less failures carry Opper request metadata, not the OpenAI default.""" + """Status-less failures carry the Opper request they came from, not the OpenAI default.""" + import httpx + import litellm from litellm.litellm_core_utils.exception_mapping_utils import exception_type + transport_failure = Exception("connection reset") + transport_failure.request = httpx.Request("POST", f"{OPPER_API_BASE}/chat/completions") + with pytest.raises(litellm.APIConnectionError) as excinfo: exception_type( model="anthropic/claude-haiku-4-5", - original_exception=Exception("connection reset"), + original_exception=transport_failure, custom_llm_provider="opper", )