> ## 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.

# Quickstart

> Go from zero to a working Fast Apply call in 90 seconds

Build an agent that edits files at 10,500 tok/s and searches codebases in 3.8 steps.

## Fast Apply

Your agent outputs a lazy edit snippet (changed lines + `// ... existing code ...` markers). Morph merges it into the original file and returns the result. 98% accuracy, sub-second latency.

<Steps>
  <Step title="Install">
    ```bash theme={null}
    npm install @morphllm/morphsdk
    ```

    Get your API key from the [dashboard](https://morphllm.com/dashboard/api-keys).
  </Step>

  <Step title="Run it">
    Save as `apply.ts` and run:

    <Tabs>
      <Tab title="SDK">
        ```typescript theme={null}
        import { MorphClient } from '@morphllm/morphsdk';

        const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });

        const result = await morph.fastApply.execute({
          target_filepath: 'src/auth.ts',
          instructions: 'Add null check before session creation',
          code_edit: `
        // ... existing code ...
        if (!user) throw new Error("User not found");
        // ... existing code ...
          `
        });

        console.log(result.diff);
        ```
      </Tab>

      <Tab title="Raw API (OpenAI SDK)">
        ```typescript theme={null}
        import OpenAI from "openai";

        const client = new OpenAI({
          apiKey: process.env.MORPH_API_KEY,
          baseURL: "https://api.morphllm.com/v1",
        });

        const response = await client.chat.completions.create({
          model: "morph-v3-fast",
          messages: [
            {
              role: "user",
              content: `<instruction>${instructions}</instruction>\n<code>${originalCode}</code>\n<update>${codeEdit}</update>`,
            },
          ],
        });

        const mergedCode = response.choices[0].message.content;
        ```
      </Tab>

      <Tab title="Python">
        ```python theme={null}
        from openai import OpenAI

        client = OpenAI(
            api_key=os.environ["MORPH_API_KEY"],
            base_url="https://api.morphllm.com/v1",
        )

        response = client.chat.completions.create(
            model="morph-v3-fast",
            messages=[{
                "role": "user",
                "content": f"<instruction>{instructions}</instruction>\n<code>{original_code}</code>\n<update>{code_edit}</update>"
            }],
        )

        merged_code = response.choices[0].message.content
        ```
      </Tab>

      <Tab title="cURL">
        ```bash theme={null}
        curl -X POST "https://api.morphllm.com/v1/chat/completions" \
          -H "Authorization: Bearer $MORPH_API_KEY" \
          -H "Content-Type: application/json" \
          -d '{
            "model": "morph-v3-fast",
            "messages": [{
              "role": "user",
              "content": "<instruction>Add error handling</instruction>\n<code>function login(email, password) {\n  const user = db.find(email);\n  const session = createSession(user);\n  return session;\n}</code>\n<update>function login(email, password) {\n  // ... existing code ...\n  if (!user) throw new Error(\"User not found\");\n  // ... existing code ...\n}</update>"
            }]
          }'
        ```
      </Tab>
    </Tabs>

    <Warning>
      The `instructions` parameter must be generated by the model, not hardcoded. It provides context for ambiguous edits. Example: "Adding error handling to the user auth and removing the old auth functions."
    </Warning>
  </Step>

  <Step title="Add to your agent">
    The SDK provides tool factories for every major framework. One line gives your agent an `edit_file` tool:

    <Tabs>
      <Tab title="Anthropic">
        ```typescript theme={null}
        import Anthropic from '@anthropic-ai/sdk';
        import { MorphClient } from '@morphllm/morphsdk';

        const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });
        const anthropic = new Anthropic();

        const response = await anthropic.messages.create({
          model: "claude-sonnet-4-5-20250929",
          max_tokens: 12000,
          tools: [morph.anthropic.createEditFileTool()],
          messages: [{ role: "user", content: "Add error handling to src/auth.ts" }]
        });
        ```
      </Tab>

      <Tab title="OpenAI">
        ```typescript theme={null}
        import OpenAI from 'openai';
        import { MorphClient } from '@morphllm/morphsdk';

        const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });
        const openai = new OpenAI();

        const response = await openai.chat.completions.create({
          model: "gpt-5-high",
          tools: [morph.openai.createEditFileTool()],
          messages: [{ role: "user", content: "Add error handling to src/auth.ts" }]
        });
        ```
      </Tab>

      <Tab title="Vercel AI SDK">
        ```typescript theme={null}
        import { generateText, stepCountIs } from 'ai';
        import { anthropic } from '@ai-sdk/anthropic';
        import { MorphClient } from '@morphllm/morphsdk';

        const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });

        const result = await generateText({
          model: anthropic('claude-sonnet-4-5-20250929'),
          tools: { editFile: morph.vercel.createEditFileTool() },
          prompt: "Add error handling to src/auth.ts",
          stopWhen: stepCountIs(5)
        });
        ```
      </Tab>
    </Tabs>

    For tool definition schemas, system prompt instructions, and output-parsing mode, see the [Fast Apply product page](/sdk/components/fast-apply).
  </Step>
</Steps>

***

## WarpGrep

Code search subagent. Searches your codebase in its own context window, finds relevant code in 3.8 steps, returns file/line-range spans. Your agent's context stays clean.

<Steps>
  <Step title="Install">
    ```bash theme={null}
    npm install @morphllm/morphsdk
    brew install ripgrep  # also: apt-get install ripgrep, choco install ripgrep
    ```
  </Step>

  <Step title="Run it">
    ```typescript theme={null}
    import { MorphClient } from '@morphllm/morphsdk';

    const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });

    const result = await morph.warpGrep.execute({
      searchTerm: 'Find authentication middleware',
      repoRoot: '.'
    });

    if (result.success) {
      for (const ctx of result.contexts) {
        console.log(`${ctx.file}: ${ctx.content}`);
      }
    }
    ```
  </Step>

  <Step title="Add to your agent">
    <Tabs>
      <Tab title="Anthropic">
        ```typescript theme={null}
        const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });
        const warpGrepTool = morph.anthropic.createWarpGrepTool({ repoRoot: '.' });

        const response = await anthropic.messages.create({
          model: 'claude-sonnet-4-5-20250929',
          max_tokens: 12000,
          tools: [warpGrepTool],
          messages: [{ role: 'user', content: 'Find authentication middleware' }]
        });
        ```
      </Tab>

      <Tab title="OpenAI">
        ```typescript theme={null}
        const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });
        const warpGrepTool = morph.openai.createWarpGrepTool({ repoRoot: '.' });

        const response = await openai.chat.completions.create({
          model: 'gpt-5-high',
          tools: [warpGrepTool],
          messages: [{ role: 'user', content: 'Find authentication middleware' }]
        });
        ```
      </Tab>

      <Tab title="Vercel AI SDK">
        ```typescript theme={null}
        const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });

        const result = await generateText({
          model: anthropic('claude-sonnet-4-5-20250929'),
          tools: { codebaseSearch: morph.vercel.createWarpGrepTool({ repoRoot: '.' }) },
          prompt: 'Find authentication middleware',
          stopWhen: stepCountIs(5)
        });
        ```
      </Tab>
    </Tabs>

    For streaming, GitHub search, sandbox execution, and the raw API protocol, see the [WarpGrep product page](/sdk/components/warp-grep/index).
  </Step>
</Steps>

## Next Steps

<CardGroup cols={2}>
  <Card title="Fast Apply" icon="bolt" href="/sdk/components/fast-apply">
    Tool schemas, system prompts, and the lazy edit format
  </Card>

  <Card title="WarpGrep" icon="search" href="/sdk/components/warp-grep/index">
    Streaming, GitHub search, remote execution
  </Card>

  <Card title="MCP Integration" icon="plug" href="/mcpquickstart">
    One command to add Morph to Claude Code, Cursor, or Codex
  </Card>

  <Card title="SDK Reference" icon="book" href="/sdk/reference">
    Complete API documentation
  </Card>
</CardGroup>
