POST
/
v1
/
chat
/
completions
cURL
curl --request POST \
  --url https://morphllm.com/v1/chat/completions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "morph-v3-large",
  "messages": [
    {
      "role": "user",
      "content": "<instruction>I will add error handling to the divide function</instruction>\n<code>function divide(a, b) {\n  return a / b;\n}</code>\n<update>function divide(a, b) {\n  if (b === 0) throw new Error('\''Division by zero'\'');\n  return a / b;\n}</update>"
    }
  ],
  "stream": false
}'
{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "\ndef calculate_total(items):\n    total = 0\n    for item in items:\n        total += item.price\n    return total * 1.1  # Add 10% tax\n"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 32,
    "total_tokens": 57
  }
}

Overview

The Apply API enables lightning-fast code editing at 10,500+ tokens/second with 98% accuracy. This OpenAI-compatible endpoint intelligently merges code changes while preserving structure and formatting.

Models

Choose the model that best fits your use case:

Message Format

The Apply API uses a structured XML format within the message content:
<instruction>Brief description of what you're changing</instruction>
<code>Original code content</code>
<update>Code snippet showing only the changes with // ... existing code ... markers</update>

Format Guidelines

  • <instruction>: Optional but recommended. Use first-person, clear descriptions
  • <code>: The complete original code that needs modification
  • <update>: Show only what changes, using // ... existing code ... for unchanged sections

Example Message Structure

{
  "role": "user",
  "content": "<instruction>I will add error handling to prevent division by zero</instruction>\n<code>function divide(a, b) {\n  return a / b;\n}</code>\n<update>function divide(a, b) {\n  if (b === 0) {\n    throw new Error('Cannot divide by zero');\n  }\n  return a / b;\n}</update>"
}

Error Codes

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

Code update request

model
enum<string>
required

ID of the model to use

Available options:
morph-v3-fast,
morph-v3-large,
auto
Example:

"morph-v3-large"

messages
object[]
required

Array containing a single user message with structured content using instruction-guided format

stream
boolean
default:false

Enable streaming response

Example:

false

Response

Chat completion response

id
string
required

Unique identifier for the completion

Example:

"chatcmpl-123"

object
string
required

Object type

Example:

"chat.completion"

created
integer
required

Unix timestamp of when the completion was created

Example:

1677652288

choices
object[]
required

List of completion choices

usage
object
required

Usage statistics for the completion request