Skip to main content

Morph

LiteLLM supports all models on Morph

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โ€‹

import os 
os.environ["MORPH_API_KEY"] = "your-api-key"

Sample Usageโ€‹

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โ€‹

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 NameFunction CallDescriptionContext Window
morph-v3-fastcompletion('morph/morph-v3-fast', messages)Fastest model, optimized for quick responses16k tokens
morph-v3-largecompletion('morph/morph-v3-large', messages)Most capable model for complex tasks16k tokens

Usage - LiteLLM Proxy Serverโ€‹

Here's how to use Morph with the LiteLLM Proxy Server:

  1. Save API key in your environment
export MORPH_API_KEY="your-api-key"
  1. Add model to config.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
  1. Start the proxy server
litellm --config config.yaml

Advanced Usageโ€‹

Setting API Baseโ€‹

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โ€‹

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)