Skip to main content
POST
Create a chat completion

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:

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

Usage Examples

Error Codes

edit_file Tool Guide

Build AI agent tools with Morph Apply

More Examples

See more implementation patterns

Authorizations

Authorization
string
header
required

Morph API key, passed as Authorization: Bearer sk-.... Create keys at https://www.morphllm.com/dashboard/api-keys.

Body

application/json

Chat completion request for Apply or Warp Grep (OpenAI-compatible)

Either a Morph Apply request or a Warp Grep request, discriminated by model.

model
enum<string>
default:morph-v3-fast
required

ID of the Apply model to use, or auto to let the router choose

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

"morph-v3-fast"

messages
object[]
required

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

Example:
stream
boolean
default:false

Enable streaming response. When true the response is a text/event-stream of OpenAI-style chat.completion.chunk deltas terminated by data: [DONE].

Example:

false

max_tokens
integer

Maximum number of tokens the Apply model may generate

Example:

150

temperature
number
default:0

Sampling temperature for the Apply request (0.0 for deterministic output)

Example:

0

Response

Chat completion response

Completion returned by a Morph chat model.

id
string
required

Unique identifier for the completion

Example:

"chatcmpl-123"

object
string
required

Always chat.completion

Example:

"chat.completion"

created
integer
required

Unix timestamp of when the completion was created

Example:

1677652288

choices
object[]
required

List of completion choices

Example:
usage
object
required

Usage statistics for the completion request

Example: