The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
add util to pick_cheapest_model_from_llm_provider
Ishaan Jaff45774010f789
diff --git a/litellm/litellm_core_utils/llm_request_utils.py b/litellm/litellm_core_utils/llm_request_utils.pyindex 557d73b0ab8..ab0c231123a 100644--- a/litellm/litellm_core_utils/llm_request_utils.py+++ b/litellm/litellm_core_utils/llm_request_utils.py@@ -1,5 +1,7 @@from typing import Dict, Optional+import litellm+def _ensure_extra_body_is_safe(extra_body: Optional[Dict]) -> Optional[Dict]:"""@@ -26,3 +28,26 @@ def _ensure_extra_body_is_safe(extra_body: Optional[Dict]) -> Optional[Dict]:extra_body["metadata"]["prompt"] = _prompt.__dict__return extra_body+++def pick_cheapest_model_from_llm_provider(custom_llm_provider: str):+ """+ Pick a random model from the LLM provider.+ """+ if custom_llm_provider not in litellm.models_by_provider:+ raise ValueError(f"Unknown LLM provider: {custom_llm_provider}")++ known_models = litellm.models_by_provider.get(custom_llm_provider, [])+ min_cost = float("inf")+ cheapest_model = None+ for model in known_models:+ model_info = litellm.get_model_info(+ model=model, custom_llm_provider=custom_llm_provider+ )+ _cost = model_info.get("input_cost_per_token", 0) + model_info.get(+ "output_cost_per_token", 0+ )+ if _cost < min_cost:+ min_cost = _cost+ cheapest_model = model+ return cheapest_model