POST
/
v1
/
chat
/
completions
cURL
curl --request POST \
  --url https://api.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 4500+ 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

The body is of type object.

Response

200
application/json

Chat completion response

The response is of type object.