diff --git a/litellm/__init__.py b/litellm/__init__.py index 1d49cba7590..dffb6d26d8e 100644 --- a/litellm/__init__.py +++ b/litellm/__init__.py @@ -602,7 +602,7 @@ text_completion_codestral_models: Set = set() text_completion_inception_models: Set = set() anthropic_models: Set = set() openrouter_models: Set = set() -requesty_models: Set = set() +requesty_models: Set = set() # mutable-ok: populated at import time like the sibling provider model sets datarobot_models: Set = set() vertex_language_models: Set = set() vertex_vision_models: Set = set() diff --git a/litellm/litellm_core_utils/get_llm_provider_logic.py b/litellm/litellm_core_utils/get_llm_provider_logic.py index b56447b518e..9af9dc8ddbb 100644 --- a/litellm/litellm_core_utils/get_llm_provider_logic.py +++ b/litellm/litellm_core_utils/get_llm_provider_logic.py @@ -358,7 +358,7 @@ def get_llm_provider( custom_llm_provider = "hyperbolic" dynamic_api_key = get_secret_str("HYPERBOLIC_API_KEY") elif endpoint == "https://router.requesty.ai/v1": - custom_llm_provider = "requesty" + custom_llm_provider = "requesty" # rebind-ok: provider resolution rebinds the parameter like every branch above dynamic_api_key = get_secret_str("REQUESTY_API_KEY") elif endpoint == "https://ai-gateway.vercel.sh/v1": custom_llm_provider = "vercel_ai_gateway" @@ -844,8 +844,8 @@ def _get_openai_compatible_provider_info( ) = litellm.HyperbolicChatConfig()._get_openai_compatible_provider_info(api_base, api_key) elif custom_llm_provider == "requesty": ( - api_base, - dynamic_api_key, + api_base, # rebind-ok: provider resolution rebinds the parameter like every branch above + dynamic_api_key, # rebind-ok: provider resolution rebinds the parameter like every branch above ) = litellm.RequestyConfig()._get_openai_compatible_provider_info(api_base, api_key) elif custom_llm_provider == "vercel_ai_gateway": ( diff --git a/litellm/llms/requesty/chat/transformation.py b/litellm/llms/requesty/chat/transformation.py index a414fcacb2e..04610aa1e68 100644 --- a/litellm/llms/requesty/chat/transformation.py +++ b/litellm/llms/requesty/chat/transformation.py @@ -47,21 +47,21 @@ class RequestyConfig(OpenrouterConfig): except Exception: return False - def get_supported_openai_params(self, model: str) -> list[str]: - supported_params: Final[list[str]] = super(OpenrouterConfig, self).get_supported_openai_params(model=model) + def get_supported_openai_params(self, model: str) -> list[str]: # mutable-ok: OpenrouterConfig signature + supported_params: Final[list[str]] = super(OpenrouterConfig, self).get_supported_openai_params(model=model) # mutable-ok: OpenrouterConfig.get_supported_openai_params returns a list if not self._supports_reasoning(model): return supported_params - return list(dict.fromkeys((*supported_params, *REQUESTY_REASONING_PARAMS))) + return list(dict.fromkeys((*supported_params, *REQUESTY_REASONING_PARAMS))) # mutable-ok: OpenrouterConfig.get_supported_openai_params returns a list def map_openai_params( self, - non_default_params: dict[str, object], - optional_params: dict, + non_default_params: dict[str, object], # mutable-ok: OpenrouterConfig signature + optional_params: dict, # mutable-ok: OpenrouterConfig signature model: str, drop_params: bool, - ) -> dict: + ) -> dict: # mutable-ok: OpenrouterConfig signature mapped_params: Final = ( - {**non_default_params, "reasoning_effort": "xhigh"} + {**non_default_params, "reasoning_effort": "xhigh"} # mutable-ok: optional params are plain JSON dicts the base transform mutates if non_default_params.get("reasoning_effort") == "max" else non_default_params ) @@ -70,18 +70,18 @@ class RequestyConfig(OpenrouterConfig): def transform_request( self, model: str, - messages: list[AllMessageValues], - optional_params: dict, - litellm_params: dict, - headers: dict, - ) -> dict: + messages: list[AllMessageValues], # mutable-ok: OpenrouterConfig signature + optional_params: dict, # mutable-ok: OpenrouterConfig signature + litellm_params: dict, # mutable-ok: OpenrouterConfig signature + headers: dict, # mutable-ok: OpenrouterConfig signature + ) -> dict: # mutable-ok: OpenrouterConfig signature transformed_messages: Final = ( self._move_cache_control_to_content(messages) if self._supports_cache_control_in_content(model) else messages ) - extra_body: Final = optional_params.pop("extra_body", {}) + extra_body: Final = optional_params.pop("extra_body", {}) # mutable-ok: extra_body is a JSON dict from the caller response: Final = super(OpenrouterConfig, self).transform_request( model, transformed_messages, optional_params, litellm_params, headers ) @@ -90,9 +90,9 @@ class RequestyConfig(OpenrouterConfig): # `messages`), otherwise a caller could route to an unauthorized model after # model-authorization and request-inspection checks have run. protected_fields: Final = frozenset({"model", "messages"}) - return {**response, **{key: value for key, value in extra_body.items() if key not in protected_fields}} + return {**response, **{key: value for key, value in extra_body.items() if key not in protected_fields}} # mutable-ok: request body is a plain JSON dict - def get_error_class(self, error_message: str, status_code: int, headers: dict | httpx.Headers) -> BaseLLMException: + def get_error_class(self, error_message: str, status_code: int, headers: dict | httpx.Headers) -> BaseLLMException: # mutable-ok: OpenrouterConfig signature return RequestyException( message=error_message, status_code=status_code, @@ -113,19 +113,19 @@ class RequestyConfig(OpenrouterConfig): class RequestyChatCompletionStreamingHandler(BaseModelResponseIterator): - def chunk_parser(self, chunk: dict) -> ModelResponseStream: + def chunk_parser(self, chunk: dict) -> ModelResponseStream: # mutable-ok: OpenrouterConfig signature try: if "error" in chunk: error_chunk: Final = chunk["error"] raise RequestyException( - message="Message: {}, Metadata: {}".format(error_chunk["message"], error_chunk.get("metadata", {})), + message="Message: {}, Metadata: {}".format(error_chunk["message"], error_chunk.get("metadata", {})), # mutable-ok: error metadata is a plain JSON dict status_code=error_chunk["code"], - headers=error_chunk.get("metadata", {}).get("headers", {}), + headers=error_chunk.get("metadata", {}).get("headers", {}), # mutable-ok: headers are a plain JSON dict ) - choices: Final = [ + choices: Final = [ # mutable-ok: StreamingChoices expects a list StreamingChoices( - **{**choice, "delta": {**choice["delta"], "reasoning_content": choice["delta"].get("reasoning")}} + **{**choice, "delta": {**choice["delta"], "reasoning_content": choice["delta"].get("reasoning")}} # mutable-ok: wire delta is a plain JSON dict ) for choice in chunk["choices"] ] @@ -141,5 +141,5 @@ class RequestyChatCompletionStreamingHandler(BaseModelResponseIterator): raise RequestyException( message=f"KeyError: {e}, Got unexpected response from Requesty: {chunk}", status_code=400, - headers={"Content-Type": "application/json"}, + headers={"Content-Type": "application/json"}, # mutable-ok: headers are a plain JSON dict ) diff --git a/litellm/proxy/public_endpoints/provider_create_fields.json b/litellm/proxy/public_endpoints/provider_create_fields.json index cd781abee26..e936bd1cbda 100644 --- a/litellm/proxy/public_endpoints/provider_create_fields.json +++ b/litellm/proxy/public_endpoints/provider_create_fields.json @@ -2759,6 +2759,24 @@ ], "default_model_placeholder": "gpt-3.5-turbo" }, + { + "provider": "REQUESTY", + "provider_display_name": "Requesty", + "litellm_provider": "requesty", + "credential_fields": [ + { + "key": "api_key", + "label": "API Key", + "placeholder": null, + "tooltip": null, + "required": true, + "field_type": "password", + "options": null, + "default_value": null + } + ], + "default_model_placeholder": "openai/gpt-4o-mini" + }, { "provider": "RUNWAYML", "provider_display_name": "Runwayml",