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
Squashed commit of the following:
Krrish Dholakiab899e7d44c0e
diff --git a/litellm/llms/ollama/completion/transformation.py b/litellm/llms/ollama/completion/transformation.pyindex c619fd8cfb7..b2557a53e95 100644--- a/litellm/llms/ollama/completion/transformation.py+++ b/litellm/llms/ollama/completion/transformation.py@@ -150,6 +150,7 @@ class OllamaConfig(BaseConfig):"frequency_penalty","stop","response_format",+ "max_completion_tokens",]def map_openai_params(@@ -160,7 +161,7 @@ class OllamaConfig(BaseConfig):drop_params: bool,) -> dict:for param, value in non_default_params.items():- if param == "max_tokens":+ if param == "max_tokens" or param == "max_completion_tokens":optional_params["num_predict"] = valueif param == "stream":optional_params["stream"] = value@@ -257,9 +258,13 @@ class OllamaConfig(BaseConfig):model_response.choices[0].finish_reason = "stop"if request_data.get("format", "") == "json":response_content = json.loads(response_json["response"])-+# Check if this is a function call format with name/arguments structure- if isinstance(response_content, dict) and "name" in response_content and "arguments" in response_content:+ if (+ isinstance(response_content, dict)+ and "name" in response_content+ and "arguments" in response_content+ ):# Handle as function call (original behavior)function_call = response_contentmessage = litellm.Message(diff --git a/litellm/proxy/_experimental/out/onboarding.html b/litellm/proxy/_experimental/out/onboarding.htmldeleted file mode 100644index dedc191cf5c..00000000000--- a/litellm/proxy/_experimental/out/onboarding.html+++ /dev/null@@ -1 +0,0 @@-<!DOCTYPE html><html id="__next_error__"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="preload" as="script" fetchPriority="low" href="/ui/_next/static/chunks/webpack-75a5453f51d60261.js"/><script src="/ui/_next/static/chunks/fd9d1056-205af899b895cbac.js" async=""></script><script src="/ui/_next/static/chunks/117-1c5bfc45bfc4237d.js" async=""></script><script src="/ui/_next/static/chunks/main-app-475d6efe4080647d.js" async=""></script><title>LiteLLM Dashboard</title><meta name="description" content="LiteLLM Proxy Admin UI"/><link rel="icon" href="/ui/favicon.ico" type="image/x-icon" sizes="16x16"/><meta name="next-size-adjust"/><script src="/ui/_next/static/chunks/polyfills-42372ed130431b0a.js" noModule=""></script></head><body><script src="/ui/_next/static/chunks/webpack-75a5453f51d60261.js" async=""></script><script>(self.__next_f=self.__next_f||[]).push([0]);self.__next_f.push([2,null])</script><script>self.__next_f.push([1,"1:HL[\"/ui/_next/static/media/a34f9d1faa5f3315-s.p.woff2\",\"font\",{\"crossOrigin\":\"\",\"type\":\"font/woff2\"}]\n2:HL[\"/ui/_next/static/css/86f6cc749f6b8493.css\",\"style\"]\n3:HL[\"/ui/_next/static/css/54496271690538df.css\",\"style\"]\n"])</script><script>self.__next_f.push([1,"4:I[12846,[],\"\"]\n6:I[19107,[],\"ClientPageRoot\"]\n7:I[12011,[\"665\",\"static/chunks/3014691f-b7b79b78e27792f3.js\",\"42\",\"static/chunks/42-014374badc35fe9b.js\",\"899\",\"static/chunks/899-54ea329f41297bf0.js\",\"250\",\"static/chunks/250-5f869ffc9c01f4db.js\",\"461\",\"static/chunks/app/onboarding/page-3860e653ff5358c5.js\"],\"default\",1]\n8:I[4707,[],\"\"]\n9:I[36423,[],\"\"]\nb:I[61060,[],\"\"]\nc:[]\n"])</script><script>self.__next_f.push([1,"0:[\"$\",\"$L4\",null,{\"buildId\":\"fCqN9Ykh6xGUiicPaINzX\",\"assetPrefix\":\"/ui\",\"urlParts\":[\"\",\"onboarding\"],\"initialTree\":[\"\",{\"children\":[\"onboarding\",{\"children\":[\"__PAGE__\",{}]}]},\"$undefined\",\"$undefined\",true],\"initialSeedData\":[\"\",{\"children\":[\"onboarding\",{\"children\":[\"__PAGE__\",{},[[\"$L5\",[\"$\",\"$L6\",null,{\"props\":{\"params\":{},\"searchParams\":{}},\"Component\":\"$7\"}],null],null],null]},[null,[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\",\"onboarding\",\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L9\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"notFoundStyles\":\"$undefined\"}]],null]},[[[[\"$\",\"link\",\"0\",{\"rel\":\"stylesheet\",\"href\":\"/ui/_next/static/css/86f6cc749f6b8493.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[\"$\",\"link\",\"1\",{\"rel\":\"stylesheet\",\"href\":\"/ui/_next/static/css/54496271690538df.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}]],[\"$\",\"html\",null,{\"lang\":\"en\",\"children\":[\"$\",\"body\",null,{\"className\":\"__className_cf7686\",\"children\":[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L9\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":[[\"$\",\"title\",null,{\"children\":\"404: This page could not be found.\"}],[\"$\",\"div\",null,{\"style\":{\"fontFamily\":\"system-ui,\\\"Segoe UI\\\",Roboto,Helvetica,Arial,sans-serif,\\\"Apple Color Emoji\\\",\\\"Segoe UI Emoji\\\"\",\"height\":\"100vh\",\"textAlign\":\"center\",\"display\":\"flex\",\"flexDirection\":\"column\",\"alignItems\":\"center\",\"justifyContent\":\"center\"},\"children\":[\"$\",\"div\",null,{\"children\":[[\"$\",\"style\",null,{\"dangerouslySetInnerHTML\":{\"__html\":\"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}\"}}],[\"$\",\"h1\",null,{\"className\":\"next-error-h1\",\"style\":{\"display\":\"inline-block\",\"margin\":\"0 20px 0 0\",\"padding\":\"0 23px 0 0\",\"fontSize\":24,\"fontWeight\":500,\"verticalAlign\":\"top\",\"lineHeight\":\"49px\"},\"children\":\"404\"}],[\"$\",\"div\",null,{\"style\":{\"display\":\"inline-block\"},\"children\":[\"$\",\"h2\",null,{\"style\":{\"fontSize\":14,\"fontWeight\":400,\"lineHeight\":\"49px\",\"margin\":0},\"children\":\"This page could not be found.\"}]}]]}]}]],\"notFoundStyles\":[]}]}]}]],null],null],\"couldBeIntercepted\":false,\"initialHead\":[null,\"$La\"],\"globalErrorComponent\":\"$b\",\"missingSlots\":\"$Wc\"}]\n"])</script><script>self.__next_f.push([1,"a:[[\"$\",\"meta\",\"0\",{\"name\":\"viewport\",\"content\":\"width=device-width, initial-scale=1\"}],[\"$\",\"meta\",\"1\",{\"charSet\":\"utf-8\"}],[\"$\",\"title\",\"2\",{\"children\":\"LiteLLM Dashboard\"}],[\"$\",\"meta\",\"3\",{\"name\":\"description\",\"content\":\"LiteLLM Proxy Admin UI\"}],[\"$\",\"link\",\"4\",{\"rel\":\"icon\",\"href\":\"/ui/favicon.ico\",\"type\":\"image/x-icon\",\"sizes\":\"16x16\"}],[\"$\",\"meta\",\"5\",{\"name\":\"next-size-adjust\"}]]\n5:null\n"])</script></body></html>\ No newline at end of filediff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yamlindex e1a444a6d9c..11069452097 100644--- a/litellm/proxy/_new_secret_config.yaml+++ b/litellm/proxy/_new_secret_config.yaml@@ -60,16 +60,9 @@ model_list:- model_name: gemini/gemini-2.0-flashlitellm_params:model: gemini/gemini-2.0-flash--litellm_settings:- num_retries: 0- check_provider_endpoint: true- cache: true- callbacks: ["otel"]--files_settings:- - custom_llm_provider: gemini- api_key: os.environ/GEMINI_API_KEY--general_settings:- store_prompts_in_spend_logs: true\ No newline at end of file+ - model_name: llama-qwen+ litellm_params:+ model: ollama/qwen2:0.5b+ model_info:+ input_cost_per_token: 0.75+ output_cost_per_token: 3diff --git a/litellm/utils.py b/litellm/utils.pyindex 9b8d11cfd5d..8217a1860ad 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -523,9 +523,9 @@ def function_setup( # noqa: PLR0915function_id: Optional[str] = kwargs["id"] if "id" in kwargs else None## DYNAMIC CALLBACKS ##- dynamic_callbacks: Optional[List[Union[str, Callable, CustomLogger]]] = (- kwargs.pop("callbacks", None)- )+ dynamic_callbacks: Optional[+ List[Union[str, Callable, CustomLogger]]+ ] = kwargs.pop("callbacks", None)all_callbacks = get_dynamic_callbacks(dynamic_callbacks=dynamic_callbacks)if len(all_callbacks) > 0:@@ -1209,9 +1209,9 @@ def client(original_function): # noqa: PLR0915exception=e,retry_policy=kwargs.get("retry_policy"),)- kwargs["retry_policy"] = (- reset_retry_policy()- ) # prevent infinite loops+ kwargs[+ "retry_policy"+ ] = reset_retry_policy() # prevent infinite loopslitellm.num_retries = (None # set retries to None to prevent infinite loops)@@ -2754,16 +2754,16 @@ def get_optional_params( # noqa: PLR0915True # so that main.py adds the function call to the prompt)if "tools" in non_default_params:- optional_params["functions_unsupported_model"] = (- non_default_params.pop("tools")- )+ optional_params[+ "functions_unsupported_model"+ ] = non_default_params.pop("tools")non_default_params.pop("tool_choice", None) # causes ollama requests to hangelif "functions" in non_default_params:- optional_params["functions_unsupported_model"] = (- non_default_params.pop("functions")- )+ optional_params[+ "functions_unsupported_model"+ ] = non_default_params.pop("functions")elif (litellm.add_function_to_prompt): # if user opts to add it to prompt instead@@ -2786,10 +2786,10 @@ def get_optional_params( # noqa: PLR0915if "response_format" in non_default_params:if provider_config is not None:- non_default_params["response_format"] = (- provider_config.get_json_schema_from_pydantic_object(- response_format=non_default_params["response_format"]- )+ non_default_params[+ "response_format"+ ] = provider_config.get_json_schema_from_pydantic_object(+ response_format=non_default_params["response_format"])else:non_default_params["response_format"] = type_to_response_format_param(@@ -3805,9 +3805,9 @@ def _count_characters(text: str) -> int:def get_response_string(response_obj: Union[ModelResponse, ModelResponseStream]) -> str:- _choices: Union[List[Union[Choices, StreamingChoices]], List[StreamingChoices]] = (- response_obj.choices- )+ _choices: Union[+ List[Union[Choices, StreamingChoices]], List[StreamingChoices]+ ] = response_obj.choicesresponse_str = ""for choice in _choices:@@ -4127,6 +4127,18 @@ def get_provider_info(return model_info+def _is_potential_model_name_in_model_cost(+ potential_model_names: PotentialModelNamesAndCustomLLMProvider,+) -> bool:+ """+ Check if the potential model name is in the model cost.+ """+ return any(+ potential_model_name in litellm.model_cost+ for potential_model_name in potential_model_names.values()+ )++def _get_model_info_helper( # noqa: PLR0915model: str, custom_llm_provider: Optional[str] = None) -> ModelInfoBase:@@ -4182,7 +4194,9 @@ def _get_model_info_helper( # noqa: PLR0915supports_prompt_caching=None,supports_pdf_input=None,)- elif custom_llm_provider == "ollama" or custom_llm_provider == "ollama_chat":+ elif (+ custom_llm_provider == "ollama" or custom_llm_provider == "ollama_chat"+ ) and not _is_potential_model_name_in_model_cost(potential_model_names):return litellm.OllamaConfig().get_model_info(model)else:"""