From 618dbc3636490b358ce33c429ecb352f8f1eca88 Mon Sep 17 00:00:00 2001 From: Yanhu007 Date: Sun, 12 Apr 2026 14:35:45 +0800 Subject: [PATCH] fix(ollama): strip provider suffix from api_base before /api/show call get_model_info receives api_base that may already contain a provider suffix like /api/chat (appended by the completion path). Appending /api/show to this produces /api/chat/api/show which returns 404. Strip known provider suffixes (/api/chat, /api/generate) before constructing the /api/show URL. Fixes #25567 --- litellm/llms/ollama/completion/transformation.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/litellm/llms/ollama/completion/transformation.py b/litellm/llms/ollama/completion/transformation.py index 6a03325e6c7..face19d0e46 100644 --- a/litellm/llms/ollama/completion/transformation.py +++ b/litellm/llms/ollama/completion/transformation.py @@ -236,12 +236,20 @@ class OllamaConfig(BaseConfig): api_base = ( api_base or get_secret_str("OLLAMA_API_BASE") or "http://localhost:11434" ) + # Strip provider-specific suffixes that may have been appended to + # api_base before this method is called (e.g. /api/chat, /api/generate). + # Without this, the URL becomes /api/chat/api/show → 404. + _base = api_base.rstrip("/") + for _suffix in ("/api/chat", "/api/generate"): + if _base.endswith(_suffix): + _base = _base[: -len(_suffix)] + break api_key = self.get_api_key() headers = {"Authorization": f"Bearer {api_key}"} if api_key else {} try: response = litellm.module_level_client.post( - url=f"{api_base}/api/show", + url=f"{_base}/api/show", json={"name": model}, headers=headers, )