Skip to content

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]

Add support for DataRobot as a provider in LiteLLM (#10385)

Matt Nitzkendd17661b13ae
diff --git a/litellm/__init__.py b/litellm/__init__.py
index b99750b5928..841711f6e67 100644
--- a/litellm/__init__.py
+++ b/litellm/__init__.py
@@ -190,6 +190,7 @@ maritalk_key: Optional[str] = None
ai21_key: Optional[str] = None
ollama_key: Optional[str] = None
openrouter_key: Optional[str] = None
+datarobot_key: Optional[str] = None
predibase_key: Optional[str] = None
huggingface_key: Optional[str] = None
vertex_project: Optional[str] = None
@@ -402,6 +403,7 @@ mistral_chat_models: List = []
text_completion_codestral_models: List = []
anthropic_models: List = []
openrouter_models: List = []
+datarobot_models: List = []
vertex_language_models: List = []
vertex_vision_models: List = []
vertex_chat_models: List = []
@@ -509,6 +511,8 @@ def add_known_models():
empower_models.append(key)
elif value.get("litellm_provider") == "openrouter":
openrouter_models.append(key)
+ elif value.get("litellm_provider") == "datarobot":
+ datarobot_models.append(key)
elif value.get("litellm_provider") == "vertex_ai-text-models":
vertex_text_models.append(key)
elif value.get("litellm_provider") == "vertex_ai-code-text-models":
@@ -659,6 +663,7 @@ model_list = (
+ anthropic_models
+ replicate_models
+ openrouter_models
+ + datarobot_models
+ huggingface_models
+ vertex_chat_models
+ vertex_text_models
@@ -719,6 +724,7 @@ models_by_provider: dict = {
"together_ai": together_ai_models,
"baseten": baseten_models,
"openrouter": openrouter_models,
+ "datarobot": datarobot_models,
"vertex_ai": vertex_chat_models
+ vertex_text_models
+ vertex_anthropic_models
@@ -869,6 +875,7 @@ from .llms.huggingface.embedding.transformation import HuggingFaceEmbeddingConfi
from .llms.oobabooga.chat.transformation import OobaboogaConfig
from .llms.maritalk import MaritalkConfig
from .llms.openrouter.chat.transformation import OpenrouterConfig
+from .llms.datarobot.chat.transformation import DataRobotConfig
from .llms.anthropic.chat.transformation import AnthropicConfig
from .llms.anthropic.common_utils import AnthropicModelInfo
from .llms.groq.stt.transformation import GroqSTTConfig
diff --git a/litellm/constants.py b/litellm/constants.py
index d36ad0f228a..b4f1b3fec90 100644
--- a/litellm/constants.py
+++ b/litellm/constants.py
@@ -180,6 +180,7 @@ LITELLM_CHAT_PROVIDERS = [
"replicate",
"huggingface",
"together_ai",
+ "datarobot",
"openrouter",
"vertex_ai",
"vertex_ai_beta",
diff --git a/litellm/litellm_core_utils/get_llm_provider_logic.py b/litellm/litellm_core_utils/get_llm_provider_logic.py
index 79e7020eb2a..33e0b47d840 100644
--- a/litellm/litellm_core_utils/get_llm_provider_logic.py
+++ b/litellm/litellm_core_utils/get_llm_provider_logic.py
@@ -514,6 +514,14 @@ def _get_openai_compatible_provider_info( # noqa: PLR0915
) = litellm.LlamafileChatConfig()._get_openai_compatible_provider_info(
api_base, api_key
)
+ elif custom_llm_provider == "datarobot":
+ # DataRobot is OpenAI compatible.
+ (
+ api_base,
+ dynamic_api_key
+ ) = litellm.DataRobotConfig()._get_openai_compatible_provider_info(
+ api_base, api_key
+ )
elif custom_llm_provider == "lm_studio":
# lm_studio is openai compatible, we just need to set this to custom_openai
(
diff --git a/litellm/llms/datarobot/chat/transformation.py b/litellm/llms/datarobot/chat/transformation.py
new file mode 100644
index 00000000000..e334c94e517
--- /dev/null
+++ b/litellm/llms/datarobot/chat/transformation.py
@@ -0,0 +1,80 @@
+"""
+Support for OpenAI's `/v1/chat/completions` endpoint.
+
+Calls done in OpenAI/openai.py as DataRobot is openai-compatible.
+"""
+
+from typing import Optional, Tuple
+from litellm.secret_managers.main import get_secret_str
+from ...openai_like.chat.transformation import OpenAILikeChatConfig
+
+
+class DataRobotConfig(OpenAILikeChatConfig):
+ @staticmethod
+ def _resolve_api_key(api_key: Optional[str] = None) -> str:
+ """Attempt to ensure that the API key is set, preferring the user-provided key
+ over the secret manager key (``DATAROBOT_API_TOKEN``).
+
+ If both are None, a fake API key is returned for testing.
+ """
+ return api_key or get_secret_str("DATAROBOT_API_TOKEN") or "fake-api-key"
+
+ @staticmethod
+ def _resolve_api_base(api_base: Optional[str] = None) -> Optional[str]:
+ """Attempt to ensure that the API base is set, preferring the user-provided key
+ over the secret manager key (``DATAROBOT_ENDPOINT``).
+
+ If both are None, a default Llamafile server URL is returned.
+ See: https://github.com/Mozilla-Ocho/llamafile/blob/bd1bbe9aabb1ee12dbdcafa8936db443c571eb9d/README.md#L61
+ """
+ api_base = api_base or get_secret_str("DATAROBOT_ENDPOINT")
+
+ if api_base is None:
+ api_base = "https://app.datarobot.com"
+
+ # If the api_base is a deployment URL, we do not append the chat completions path
+ if "api/v2/deployments" not in api_base:
+ # If the api_base is not a deployment URL, we need to append the chat completions path
+ if "api/v2/genai/llmgw/chat/completions" not in api_base:
+ api_base += "/api/v2/genai/llmgw/chat/completions"
+
+ # Ensure the url ends with a trailing slash
+ if not api_base.endswith("/"):
+ api_base += "/"
+
+ return api_base # type: ignore
+
+ def _get_openai_compatible_provider_info(
+ self,
+ api_base: Optional[str],
+ api_key: Optional[str]
+ ) -> Tuple[Optional[str], Optional[str]]:
+ """Attempts to ensure that the API base and key are set, preferring user-provided values,
+ before falling back to secret manager values (``DATAROBOT_ENDPOINT`` and ``DATAROBOT_API_TOKEN``
+ respectively).
+
+ If an API key cannot be resolved via either method, a fake key is returned.
+ """
+ api_base = DataRobotConfig._resolve_api_base(api_base)
+ dynamic_api_key = DataRobotConfig._resolve_api_key(api_key)
+
+ return api_base, dynamic_api_key
+
+ def get_complete_url(
+ self,
+ api_base: Optional[str],
+ api_key: Optional[str],
+ model: str,
+ optional_params: dict,
+ litellm_params: dict,
+ stream: Optional[bool] = None,
+ ) -> str:
+ """
+ Get the complete URL for the API call. Datarobot's API base is set to
+ the complete value, so it does not need to be updated to additionally add
+ chat completions.
+
+ Returns:
+ str: The complete URL for the API call.
+ """
+ return str(api_base) # type: ignore
diff --git a/litellm/main.py b/litellm/main.py
index 64039f357b3..73bc88a1098 100644
--- a/litellm/main.py
+++ b/litellm/main.py
@@ -2335,6 +2335,26 @@ def completion( # type: ignore # noqa: PLR0915
original_response=response,
additional_args={"headers": headers},
)
+
+ elif custom_llm_provider == "datarobot":
+ response = base_llm_http_handler.completion(
+ model=model,
+ messages=messages,
+ headers=headers,
+ model_response=model_response,
+ api_key=api_key,
+ api_base=api_base,
+ acompletion=acompletion,
+ logging_obj=logging,
+ optional_params=optional_params,
+ litellm_params=litellm_params,
+ timeout=timeout, # type: ignore
+ client=client,
+ custom_llm_provider=custom_llm_provider,
+ encoding=encoding,
+ stream=stream,
+ provider_config=provider_config,
+ )
elif custom_llm_provider == "openrouter":
api_base = (
api_base
diff --git a/litellm/types/utils.py b/litellm/types/utils.py
index 84b7a7997ee..e94dbc225c6 100644
--- a/litellm/types/utils.py
+++ b/litellm/types/utils.py
@@ -2207,6 +2207,7 @@ class LlmProviders(str, Enum):
HUGGINGFACE = "huggingface"
TOGETHER_AI = "together_ai"
OPENROUTER = "openrouter"
+ DATAROBOT = "datarobot"
VERTEX_AI = "vertex_ai"
VERTEX_AI_BETA = "vertex_ai_beta"
GEMINI = "gemini"
diff --git a/litellm/utils.py b/litellm/utils.py
index 4bb4cb5e83c..63a01f3ad59 100644
--- a/litellm/utils.py
+++ b/litellm/utils.py
@@ -4933,6 +4933,11 @@ def validate_environment( # noqa: PLR0915
keys_in_environment = True
else:
missing_keys.append("OPENROUTER_API_KEY")
+ elif custom_llm_provider == "datarobot":
+ if "DATAROBOT_API_TOKEN" in os.environ:
+ keys_in_environment = True
+ else:
+ missing_keys.append("DATAROBOT_API_TOKEN")
elif custom_llm_provider == "vertex_ai":
if "VERTEXAI_PROJECT" in os.environ and "VERTEXAI_LOCATION" in os.environ:
keys_in_environment = True
@@ -5135,6 +5140,12 @@ def validate_environment( # noqa: PLR0915
keys_in_environment = True
else:
missing_keys.append("OPENROUTER_API_KEY")
+ ## datarobot
+ elif model in litellm.datarobot_models:
+ if "DATAROBOT_API_TOKEN" in os.environ:
+ keys_in_environment = True
+ else:
+ missing_keys.append("DATAROBOT_API_TOKEN")
## vertex - text + chat models
elif (
model in litellm.vertex_chat_models
@@ -6474,6 +6485,8 @@ class ProviderConfigManager:
return litellm.TogetherAIConfig()
elif litellm.LlmProviders.OPENROUTER == provider:
return litellm.OpenrouterConfig()
+ elif litellm.LlmProviders.DATAROBOT == provider:
+ return litellm.DataRobotConfig()
elif litellm.LlmProviders.GEMINI == provider:
return litellm.GoogleAIStudioGeminiConfig()
elif (
diff --git a/tests/test_litellm/llms/datarobot/chat/test_datarobot_chat_transformation.py b/tests/test_litellm/llms/datarobot/chat/test_datarobot_chat_transformation.py
new file mode 100644
index 00000000000..4999b078caa
--- /dev/null
+++ b/tests/test_litellm/llms/datarobot/chat/test_datarobot_chat_transformation.py
@@ -0,0 +1,69 @@
+import os
+from unittest.mock import patch
+
+import pytest
+
+from litellm.llms.datarobot.chat.transformation import DataRobotConfig
+
+
[email protected](os.environ, {}, clear=True)
+class TestDataRobotConfig:
+ @pytest.fixture
+ def handler(self):
+ return DataRobotConfig()
+
+ @pytest.mark.parametrize(
+ "api_base, expected_url",
+ [
+ (None, "https://app.datarobot.com/api/v2/genai/llmgw/chat/completions/"),
+ ("http://localhost:5001", "http://localhost:5001/api/v2/genai/llmgw/chat/completions/"),
+ ("https://app.datarobot.com", "https://app.datarobot.com/api/v2/genai/llmgw/chat/completions/"),
+ ("https://app.datarobot.com/api/v2/genai/llmgw/chat/completions", "https://app.datarobot.com/api/v2/genai/llmgw/chat/completions/"),
+ ("https://app.datarobot.com/api/v2/genai/llmgw/chat/completions/", "https://app.datarobot.com/api/v2/genai/llmgw/chat/completions/"),
+ ("https://staging.datarobot.com", "https://staging.datarobot.com/api/v2/genai/llmgw/chat/completions/"),
+ ("https://app.datarobot.com/api/v2/deployments/deployment_id", "https://app.datarobot.com/api/v2/deployments/deployment_id/"),
+ ("https://app.datarobot.com/api/v2/deployments/deployment_id/", "https://app.datarobot.com/api/v2/deployments/deployment_id/"),
+ ]
+ )
+ def test_resolve_api_base(self, api_base, expected_url, handler):
+ """Test that URLs properly resolve to the expected format."""
+ assert handler._resolve_api_base(api_base) == expected_url
+
+ # Check that the complete url with the resolution is expected
+ assert handler.get_complete_url(
+ api_base=handler._resolve_api_base(api_base),
+ api_key="PASSTHROUGH_KEY",
+ model="datarobot/vertex_ai/gemini-1.5-flash-002",
+ optional_params={},
+ litellm_params={},
+ ) == expected_url
+
+ # Check that the complete url with the original api_base does not change the url
+ if api_base is not None:
+ assert handler.get_complete_url(
+ api_base=api_base,
+ api_key="PASSTHROUGH_KEY",
+ model="datarobot/vertex_ai/gemini-1.5-flash-002",
+ optional_params={},
+ litellm_params={},
+ ) == api_base
+
+ def test_resolve_api_base_with_environment_variable(self, handler):
+ os.environ["DATAROBOT_ENDPOINT"] = "https://env.datarobot.com"
+ assert handler._resolve_api_base(None) == "https://env.datarobot.com/api/v2/genai/llmgw/chat/completions/"
+ del os.environ["DATAROBOT_ENDPOINT"]
+
+ @pytest.mark.parametrize(
+ "api_key, expected_api_key",
+ [
+ (None, "fake-api-key"),
+ ("PASSTHROUGH_KEY", "PASSTHROUGH_KEY"),
+ ]
+ )
+ def test_resolve_api_key(self, api_key, expected_api_key, handler):
+ assert handler._resolve_api_key(api_key) == expected_api_key
+
+ def test_resolve_api_key_with_environment_variable(self, handler):
+ os.environ["DATAROBOT_API_TOKEN"] = "env_key"
+ assert handler._resolve_api_key(None) == "env_key"
+ del os.environ["DATAROBOT_API_TOKEN"]
diff --git a/tests/test_litellm/llms/datarobot/test_datarobot.py b/tests/test_litellm/llms/datarobot/test_datarobot.py
new file mode 100644
index 00000000000..88bd047f9c7
--- /dev/null
+++ b/tests/test_litellm/llms/datarobot/test_datarobot.py
@@ -0,0 +1,85 @@
+import json
+import os
+
+from unittest.mock import patch
+
+import pytest
+
+from litellm import completion
+from litellm.llms.custom_httpx.http_handler import HTTPHandler
+
+
[email protected](os.environ, {}, clear=True)
+def test_completion_datarobot():
+ """Ensure that the completion function works with DataRobot API."""
+ messages = [{"role": "user", "content": "What's the weather like in San Francisco?"}]
+ try:
+ client = HTTPHandler()
+ with patch.object(client, "post") as mock_post:
+ response = completion(
+ model="datarobot/vertex_ai/gemini-1.5-flash-002",
+ messages=messages,
+ client=client,
+ max_tokens=5,
+ clientId="custom-model",
+ )
+ print(response)
+
+ # Add any assertions here to check the response
+ mock_post.assert_called_once()
+ mocks_kwargs = mock_post.call_args.kwargs
+ assert mocks_kwargs["url"] == "https://app.datarobot.com/api/v2/genai/llmgw/chat/completions/"
+ assert mocks_kwargs["headers"]["Authorization"] == "Bearer fake-api-key"
+ json_data = json.loads(mock_post.call_args.kwargs["data"])
+ assert json_data["clientId"] == "custom-model"
+ except Exception as e:
+ pytest.fail(f"Error occurred: {e}")
+
+
+ os.environ, {"DATAROBOT_ENDPOINT": "https://app.datarobot.com/api/v2/deployments/deployment_id/"}, clear=True
+)
+def test_completion_datarobot_with_deployment():
+ """Ensure that deployment URL is used correctly."""
+ messages = [{"role": "user", "content": "What's the weather like in San Francisco?"}]
+ try:
+ client = HTTPHandler()
+ with patch.object(client, "post") as mock_post:
+ response = completion(
+ model="datarobot/vertex_ai/gemini-1.5-flash-002",
+ messages=messages,
+ client=client,
+ max_tokens=5,
+ clientId="custom-model",
+ )
+ print(response)
+
+ # Add any assertions here to check the response
+ mock_post.assert_called_once()
+ mocks_kwargs = mock_post.call_args.kwargs
+ assert mocks_kwargs["url"] == "https://app.datarobot.com/api/v2/deployments/deployment_id/"
+ assert mocks_kwargs["headers"]["Authorization"] == "Bearer fake-api-key"
+ json_data = json.loads(mock_post.call_args.kwargs["data"])
+ assert json_data["clientId"] == "custom-model"
+ except Exception as e:
+ pytest.fail(f"Error occurred: {e}")
+
+
+def test_completion_datarobot_with_environment_variables():
+ """Allow the test to run with environment variables if they are set for integrations."""
+ # If keys are not set, the test will be skipped
+ if os.environ.get("DATAROBOT_API_TOKEN") is None:
+ return
+
+ messages = [{"role": "user", "content": "What's the weather like in San Francisco?"}]
+ try:
+ response = completion(
+ model="datarobot/vertex_ai/gemini-1.5-flash-002", messages=messages, max_tokens=5, clientId="custom-model"
+ )
+ print(response)
+ assert response["object"] == "chat.completion"
+ assert response["model"] == "gemini-1.5-flash-002"
+ assert len(response["choices"]) == 1
+ assert len(response["choices"][0]["message"]["content"]) > 0
+ except Exception as e:
+ pytest.fail(f"Error occurred: {e}")