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]

feat: add Morph provider support (#12821)

Cole McIntoshc5b51cd2b4cc
diff --git a/docs/my-website/docs/providers/morph.md b/docs/my-website/docs/providers/morph.md
new file mode 100644
index 00000000000..e49c60b5665
--- /dev/null
+++ b/docs/my-website/docs/providers/morph.md
@@ -0,0 +1,123 @@
+# Morph
+
+LiteLLM supports all models on [Morph](https://morphllm.com)
+
+## Overview
+
+Morph provides specialized AI models designed for agentic workflows, particularly excelling at precise code editing and manipulation. Their "Apply" models enable targeted code changes without full file rewrites, making them ideal for AI agents that need to make intelligent, context-aware code modifications.
+
+## API Key
+```python
+import os
+os.environ["MORPH_API_KEY"] = "your-api-key"
+```
+
+## Sample Usage
+
+```python
+from litellm import completion
+
+# set env variable
+os.environ["MORPH_API_KEY"] = "your-api-key"
+
+messages = [
+ {"role": "user", "content": "Write a Python function to calculate factorial"}
+]
+
+## Morph v3 Fast - Optimized for speed
+response = completion(
+ model="morph/morph-v3-fast",
+ messages=messages,
+)
+print(response)
+
+## Morph v3 Large - Most capable model
+response = completion(
+ model="morph/morph-v3-large",
+ messages=messages,
+)
+print(response)
+```
+
+## Sample Usage - Streaming
+```python
+from litellm import completion
+
+# set env variable
+os.environ["MORPH_API_KEY"] = "your-api-key"
+
+messages = [
+ {"role": "user", "content": "Write a Python function to calculate factorial"}
+]
+
+## Morph v3 Fast with streaming
+response = completion(
+ model="morph/morph-v3-fast",
+ messages=messages,
+ stream=True,
+)
+
+for chunk in response:
+ print(chunk)
+```
+
+## Supported Models
+
+| Model Name | Function Call | Description | Context Window |
+|--------------------------|--------------------------------------------|-----------------------|----------------|
+| morph-v3-fast | `completion('morph/morph-v3-fast', messages)` | Fastest model, optimized for quick responses | 16k tokens |
+| morph-v3-large | `completion('morph/morph-v3-large', messages)` | Most capable model for complex tasks | 16k tokens |
+
+## Usage - LiteLLM Proxy Server
+
+Here's how to use Morph with the LiteLLM Proxy Server:
+
+1. Save API key in your environment
+```bash
+export MORPH_API_KEY="your-api-key"
+```
+
+2. Add model to config.yaml
+```yaml
+model_list:
+ - model_name: morph-v3-fast
+ litellm_params:
+ model: morph/morph-v3-fast
+
+ - model_name: morph-v3-large
+ litellm_params:
+ model: morph/morph-v3-large
+```
+
+3. Start the proxy server
+```bash
+litellm --config config.yaml
+```
+
+## Advanced Usage
+
+### Setting API Base
+```python
+import litellm
+
+# set custom api base
+response = completion(
+ model="morph/morph-v3-large",
+ messages=[{"role": "user", "content": "Hello, world!"}],
+ api_base="https://api.morphllm.com/v1"
+)
+print(response)
+```
+
+### Setting API Key
+```python
+import litellm
+
+# set api key via completion
+response = completion(
+ model="morph/morph-v3-large",
+ messages=[{"role": "user", "content": "Hello, world!"}],
+ api_key="your-api-key"
+)
+print(response)
+```
\ No newline at end of file
diff --git a/docs/my-website/sidebars.js b/docs/my-website/sidebars.js
index b770ac625a0..8c210d437b2 100644
--- a/docs/my-website/sidebars.js
+++ b/docs/my-website/sidebars.js
@@ -447,6 +447,7 @@ const sidebars = {
"providers/replicate",
"providers/togetherai",
"providers/v0",
+ "providers/morph",
"providers/lambda_ai",
"providers/novita",
"providers/voyage",
diff --git a/litellm/__init__.py b/litellm/__init__.py
index db77eca6c39..1f08a6c03ab 100644
--- a/litellm/__init__.py
+++ b/litellm/__init__.py
@@ -503,6 +503,7 @@ elevenlabs_models: List = []
dashscope_models: List = []
moonshot_models: List = []
v0_models: List = []
+morph_models: List = []
lambda_ai_models: List = []
def is_bedrock_pricing_only_model(key: str) -> bool:
@@ -684,6 +685,8 @@ def add_known_models():
moonshot_models.append(key)
elif value.get("litellm_provider") == "v0":
v0_models.append(key)
+ elif value.get("litellm_provider") == "morph":
+ morph_models.append(key)
elif value.get("litellm_provider") == "lambda_ai":
lambda_ai_models.append(key)
@@ -771,6 +774,7 @@ model_list = (
+ dashscope_models
+ moonshot_models
+ v0_models
+ + morph_models
+ lambda_ai_models
)
@@ -840,6 +844,7 @@ models_by_provider: dict = {
"dashscope": dashscope_models,
"moonshot": moonshot_models,
"v0": v0_models,
+ "morph": morph_models,
"lambda_ai": lambda_ai_models,
}
@@ -1161,6 +1166,7 @@ from .llms.nebius.chat.transformation import NebiusConfig
from .llms.dashscope.chat.transformation import DashScopeChatConfig
from .llms.moonshot.chat.transformation import MoonshotChatConfig
from .llms.v0.chat.transformation import V0ChatConfig
+from .llms.morph.chat.transformation import MorphChatConfig
from .llms.lambda_ai.chat.transformation import LambdaAIChatConfig
from .main import * # type: ignore
from .integrations import *
diff --git a/litellm/constants.py b/litellm/constants.py
index d7d38748822..3089ae131d1 100644
--- a/litellm/constants.py
+++ b/litellm/constants.py
@@ -279,6 +279,7 @@ LITELLM_CHAT_PROVIDERS = [
"dashscope",
"moonshot",
"v0",
+ "morph",
"lambda_ai",
]
@@ -409,6 +410,7 @@ openai_compatible_endpoints: List = [
"https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
"https://api.moonshot.ai/v1",
"https://api.v0.dev/v1",
+ "https://api.morphllm.com/v1",
"https://api.lambda.ai/v1",
]
@@ -448,6 +450,7 @@ openai_compatible_providers: List = [
"dashscope",
"moonshot",
"v0",
+ "morph",
"lambda_ai",
]
openai_text_completion_compatible_providers: List = (
diff --git a/litellm/litellm_core_utils/get_llm_provider_logic.py b/litellm/litellm_core_utils/get_llm_provider_logic.py
index 2b5ee4b18c8..32d837c1e0a 100644
--- a/litellm/litellm_core_utils/get_llm_provider_logic.py
+++ b/litellm/litellm_core_utils/get_llm_provider_logic.py
@@ -694,6 +694,13 @@ def _get_openai_compatible_provider_info( # noqa: PLR0915
) = litellm.V0ChatConfig()._get_openai_compatible_provider_info(
api_base, api_key
)
+ elif custom_llm_provider == "morph":
+ (
+ api_base,
+ dynamic_api_key,
+ ) = litellm.MorphChatConfig()._get_openai_compatible_provider_info(
+ api_base, api_key
+ )
elif custom_llm_provider == "lambda_ai":
(
api_base,
diff --git a/litellm/llms/morph/__init__.py b/litellm/llms/morph/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/litellm/llms/morph/chat/__init__.py b/litellm/llms/morph/chat/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/litellm/llms/morph/chat/transformation.py b/litellm/llms/morph/chat/transformation.py
new file mode 100644
index 00000000000..f37ed8e45e3
--- /dev/null
+++ b/litellm/llms/morph/chat/transformation.py
@@ -0,0 +1,46 @@
+"""
+Transform request from OpenAI format to Morph format.
+
+[TODO] Docs: Morph supports the OpenAI API format.
+https://docs.morphllm.com/quickstart
+"""
+
+from typing import Optional, Tuple
+
+from litellm.secret_managers.main import get_secret_str
+
+from ...openai_like.chat.transformation import OpenAILikeChatConfig
+
+
+class MorphChatConfig(OpenAILikeChatConfig):
+ """
+ Transform request from OpenAI format to Morph format.
+ """
+
+ @property
+ def custom_llm_provider(self) -> Optional[str]:
+ return "morph"
+
+ def _get_openai_compatible_provider_info(
+ self, api_base: Optional[str], api_key: Optional[str]
+ ) -> Tuple[Optional[str], Optional[str]]:
+ api_base = (
+ api_base
+ or get_secret_str("MORPH_API_BASE")
+ or "https://api.morphllm.com/v1" # default api base
+ )
+ dynamic_api_key = api_key or get_secret_str("MORPH_API_KEY")
+ return api_base, dynamic_api_key
+
+ def get_supported_openai_params(self, model: str) -> list:
+ return [
+ "messages",
+ "model",
+ "stream",
+ ]
+
+ def pre_call(self, messages: list, model: str, api_key: str, api_base: str):
+ """
+ Hook for any pre-processing before the API call.
+ """
+ return
\ No newline at end of file
diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json
index 4920f560c8c..e3257a6ebfa 100644
--- a/litellm/model_prices_and_context_window_backup.json
+++ b/litellm/model_prices_and_context_window_backup.json
@@ -16889,5 +16889,33 @@
"supports_vision": true,
"mode": "chat",
"source": "https://platform.moonshot.ai/docs/pricing"
+ },
+ "morph/morph-v3-fast": {
+ "max_tokens": 16000,
+ "max_input_tokens": 16000,
+ "max_output_tokens": 16000,
+ "input_cost_per_token": 8e-07,
+ "output_cost_per_token": 1.2e-06,
+ "litellm_provider": "morph",
+ "mode": "chat",
+ "supports_function_calling": false,
+ "supports_parallel_function_calling": false,
+ "supports_vision": false,
+ "supports_system_messages": true,
+ "supports_tool_choice": false
+ },
+ "morph/morph-v3-large": {
+ "max_tokens": 16000,
+ "max_input_tokens": 16000,
+ "max_output_tokens": 16000,
+ "input_cost_per_token": 9e-07,
+ "output_cost_per_token": 1.9e-06,
+ "litellm_provider": "morph",
+ "mode": "chat",
+ "supports_function_calling": false,
+ "supports_parallel_function_calling": false,
+ "supports_vision": false,
+ "supports_system_messages": true,
+ "supports_tool_choice": false
}
}
diff --git a/litellm/types/utils.py b/litellm/types/utils.py
index eba8f65c379..45714a18d05 100644
--- a/litellm/types/utils.py
+++ b/litellm/types/utils.py
@@ -2276,6 +2276,7 @@ class LlmProviders(str, Enum):
DASHSCOPE = "dashscope"
MOONSHOT = "moonshot"
V0 = "v0"
+ MORPH = "morph"
LAMBDA_AI = "lambda_ai"
DEEPSEEK = "deepseek"
SAMBANOVA = "sambanova"
diff --git a/litellm/utils.py b/litellm/utils.py
index fbfe71cf96c..1556351e604 100644
--- a/litellm/utils.py
+++ b/litellm/utils.py
@@ -6834,6 +6834,8 @@ class ProviderConfigManager:
return litellm.MoonshotChatConfig()
elif litellm.LlmProviders.V0 == provider:
return litellm.V0ChatConfig()
+ elif litellm.LlmProviders.MORPH == provider:
+ return litellm.MorphChatConfig()
elif litellm.LlmProviders.BEDROCK == provider:
bedrock_route = BedrockModelInfo.get_bedrock_route(model)
bedrock_invoke_provider = litellm.BedrockLLM.get_bedrock_invoke_provider(
diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json
index 4920f560c8c..e3257a6ebfa 100644
--- a/model_prices_and_context_window.json
+++ b/model_prices_and_context_window.json
@@ -16889,5 +16889,33 @@
"supports_vision": true,
"mode": "chat",
"source": "https://platform.moonshot.ai/docs/pricing"
+ },
+ "morph/morph-v3-fast": {
+ "max_tokens": 16000,
+ "max_input_tokens": 16000,
+ "max_output_tokens": 16000,
+ "input_cost_per_token": 8e-07,
+ "output_cost_per_token": 1.2e-06,
+ "litellm_provider": "morph",
+ "mode": "chat",
+ "supports_function_calling": false,
+ "supports_parallel_function_calling": false,
+ "supports_vision": false,
+ "supports_system_messages": true,
+ "supports_tool_choice": false
+ },
+ "morph/morph-v3-large": {
+ "max_tokens": 16000,
+ "max_input_tokens": 16000,
+ "max_output_tokens": 16000,
+ "input_cost_per_token": 9e-07,
+ "output_cost_per_token": 1.9e-06,
+ "litellm_provider": "morph",
+ "mode": "chat",
+ "supports_function_calling": false,
+ "supports_parallel_function_calling": false,
+ "supports_vision": false,
+ "supports_system_messages": true,
+ "supports_tool_choice": false
}
}
diff --git a/tests/llm_translation/test_morph.py b/tests/llm_translation/test_morph.py
new file mode 100644
index 00000000000..7d2568a0a7f
--- /dev/null
+++ b/tests/llm_translation/test_morph.py
@@ -0,0 +1,108 @@
+"""Unit tests for Morph provider integration."""
+
+import os
+import sys
+from unittest.mock import patch
+
+sys.path.insert(
+ 0, os.path.abspath("../..")
+) # Adds the parent directory to the system path
+
+import litellm
+from litellm import MorphChatConfig, get_llm_provider
+
+# Force model loading
+litellm.add_known_models()
+
+
+def test_morph_config_get_provider_info():
+ """Test that MorphChatConfig returns correct provider info."""
+ config = MorphChatConfig()
+
+ # Test with environment variable
+ with patch.dict(os.environ, {"MORPH_API_KEY": "test-key-from-env"}):
+ api_base, api_key = config._get_openai_compatible_provider_info(None, None)
+ assert api_base == "https://api.morphllm.com/v1"
+ assert api_key == "test-key-from-env"
+
+ # Test with passed api_key
+ api_base, api_key = config._get_openai_compatible_provider_info(None, "direct-key")
+ assert api_base == "https://api.morphllm.com/v1"
+ assert api_key == "direct-key"
+
+ # Test with custom api_base
+ api_base, api_key = config._get_openai_compatible_provider_info("https://custom.morph.com", "key")
+ assert api_base == "https://custom.morph.com"
+ assert api_key == "key"
+
+
+def test_morph_get_llm_provider():
+ """Test that get_llm_provider correctly identifies morph models."""
+ # Test with morph/model format
+ _, custom_llm_provider, _, _ = get_llm_provider("morph/morph-v3-large")
+ assert custom_llm_provider == "morph"
+
+ _, custom_llm_provider, _, _ = get_llm_provider("morph/morph-v3-fast")
+ assert custom_llm_provider == "morph"
+
+
+def test_morph_in_provider_lists():
+ """Test that morph is included in all necessary provider lists."""
+ import litellm
+ from litellm.constants import openai_compatible_providers, openai_compatible_endpoints
+
+ # Check morph is in openai_compatible_providers
+ assert "morph" in openai_compatible_providers
+
+ # Check morph endpoint is in openai_compatible_endpoints
+ assert "https://api.morphllm.com/v1" in openai_compatible_endpoints
+
+ # Check morph is in provider_list
+ assert "morph" in litellm.provider_list
+
+ # Check models are in model_list after initialization
+ assert all(model in litellm.model_list for model in ["morph/morph-v3-large", "morph/morph-v3-fast"])
+
+
+def test_morph_model_info():
+ """Test that morph models have correct configuration."""
+ import litellm
+ model_info = litellm.get_model_info("morph/morph-v3-large")
+
+ assert model_info["litellm_provider"] == "morph"
+ assert model_info["mode"] == "chat"
+ assert model_info["max_tokens"] == 16000
+ assert model_info["max_input_tokens"] == 16000
+ assert model_info["max_output_tokens"] == 16000
+ assert model_info["input_cost_per_token"] == 9e-07 # $0.9/1M tokens
+ assert model_info["output_cost_per_token"] == 1.9e-06 # $1.9/1M tokens
+ assert model_info["supports_function_calling"] is False
+ assert model_info["supports_vision"] is False
+ assert model_info["supports_system_messages"] is True
+
+
+def test_morph_supported_params():
+ """Test that MorphChatConfig returns correct supported parameters."""
+ config = MorphChatConfig()
+ supported_params = config.get_supported_openai_params("morph/morph-v3-large")
+
+ expected_params = [
+ "messages",
+ "model",
+ "stream",
+ "temperature",
+ "max_tokens",
+ "tools",
+ "tool_choice",
+ "response_format",
+ ]
+
+ assert all(param in supported_params for param in expected_params)
+
+
+def test_morph_custom_llm_provider():
+ """Test that morph models are correctly identified."""
+ config = MorphChatConfig()
+ assert config.custom_llm_provider == "morph"
+
+