> ## Documentation Index
> Fetch the complete documentation index at: https://docs.morphllm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Apply Model

> Code merging at 10,500 tok/s with 98% accuracy

# Fast Apply

Fast Apply takes original code and an edit snippet and merges them. 10,500 tokens/sec, 98% accuracy. It's the same concept [Cursor uses](https://web.archive.org/web/20240823050616/https://www.cursor.com/blog/instant-apply) for instant apply.

The alternative is search-and-replace, which requires a separate tool call for each edit chunk and fails on whitespace, reordering, and ambiguous matches. Or full-file rewrites, which are slow and expensive. Fast Apply handles all edits to a file in a single call.

The speed comes from a 7B model trained specifically on code merging, served on custom CUDA kernels with speculative decoding that exploits code's syntactic predictability (70% hit rate).

<Card title="Try the API Playground" icon="play" href="/api-reference/endpoint/apply" horizontal>
  Test Fast Apply with live examples
</Card>

### Models

| Model              | Speed           | Accuracy | Best For                   |
| ------------------ | --------------- | -------- | -------------------------- |
| **morph-v3-fast**  | 10,500+ tok/sec | 96%      | Real-time edits            |
| **morph-v3-large** | 2500+ tok/sec   | 98%      | Complex multi-edit changes |
| **auto**           | Variable        | \~98%    | Automatic selection        |

## Quick Start

<Steps>
  <Step title="Setup Client">
    ```python Python theme={null}
    from openai import OpenAI

    client = OpenAI(
        api_key="your-morph-api-key",
        base_url="https://api.morphllm.com/v1"
    )
    ```
  </Step>

  <Step title="Apply Changes">
    ```python Python theme={null}
    def apply_edit(instruction: str, original: str, update: str):
        response = client.chat.completions.create(
            model="morph-v3-fast",
            messages=[{
                "role": "user",
                "content": f"<instruction>{instruction}</instruction>\n<code>{original}</code>\n<update>{update}</update>"
            }]
        )
        return response.choices[0].message.content

    # Example
    original = """
    const a = 1
    const authenticateUser = () => {
      return "Authenticated"
    }
    """
    # These should be coming from your Agent
    instruction = "I will change the return text to be French"
    update = """
    // ... existing code ...
      return "Authentifié"
    }
    """

    final_code = apply_edit(instruction, original, update)
    ```
  </Step>
</Steps>

## Best Practices

**Update Snippets**: Use `// ... existing code ...` for unchanged sections:

```javascript theme={null}
// Good
const authenticateUser = async (email, password) => {
  // ... existing code ...
  const result = await verifyUser(email, password)
  return result ? "Authenticated" : "Unauthenticated"
}
```

**Instructions**: Have the agent write clear, first-person descriptions to "disambiguate uncertainty in the edit":

* ✅ "I will add async/await error handling"
* ❌ "Change this function"

## Next Steps

<CardGroup cols={2}>
  <Card title="API Reference" icon="book" href="/guides/apply">
    Complete technical reference and error handling
  </Card>

  <Card title="Build AI Tools" icon="wrench" href="/guides/tools">
    Integration guide for AI agents
  </Card>
</CardGroup>
