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

> Run a model, apply edits at 10,500 tok/s, and search code — one OpenAI-compatible API

## Try GLM-5.2 on 5% of your traffic

A canary rollout: keep your current provider, send a slice of production traffic to GLM-5.2, and compare Reflex results before switching over. Paste this into your coding agent:

```
Add a canary rollout for GLM-5.2 (morph-glm52-744b) on Morph's API, running alongside my current LLM provider so I can compare quality before switching:

1. Route ~5% of production requests (random, or hashed by user_id for consistency) to https://api.morphllm.com/v1/chat/completions with model "morph-glm52-744b" and MORPH_API_KEY. Leave the other 95% on my current provider, unchanged.
2. Install @morphllm/morphsdk (or morphsdk[otel] for Python) and call morphTracing({ apiKey }) once at startup — this auto-instruments both my current provider's SDK and the OpenAI client I point at Morph.
3. Wrap every turn, on both branches, in morph.begin({ userId, convoId, event }) / turn.setInput(...) / turn.finish({ output }), with evals: { user: ["user-frustrated"], assistant: ["leaked-thinking", "stuck-in-a-loop"] } so Morph labels both providers the same way, off the request path.
4. After a day of traffic, open https://morphllm.com/dashboard/traces (or GET /v1/reflex/traces) and compare Reflex fire rates between the two "model" values — my current provider's model name vs. morph-glm52-744b. If GLM-5.2 holds steady or improves, raise the split.

Docs: https://docs.morphllm.com/guides/reflex-tracing (tracing + Reflexes walkthrough), https://docs.morphllm.com/sdk/components/fast-models (GLM-5.2 and the rest of the open-weight lineup), https://docs.morphllm.com/sdk/components/reflexes (every Reflex class)
```

<Card title="Full tracing + Reflexes guide" icon="timeline" href="/guides/reflex-tracing">
  How `begin()` / `finish()` and `evals` fit together, plus reading labels back by model.
</Card>

## 24 hours later: ask Claude Code what happened

Your canary now has a day of labeled production traffic. Install the Morph MCP so Claude Code can read it:

```bash Terminal theme={null}
npx -y @morphllm/morph-setup --morph-api-key YOUR_API_KEY
```

Then paste this:

```text Prompt: compare the canary against your old model theme={null}
Use the Morph MCP reflex tools to check how the GLM-5.2 canary is doing in production:

1. list_reflexes — see which classifiers are labeling our traffic.
2. reflex_summary over the last 24 hours — Reflex firing rates by model. Compare morph-glm52-744b against our previous model on user-frustrated, stuck-in-a-loop, and leaked-thinking.
3. get_reflex_traces for the worst label on the canary — pull the conversations that fired and read what actually happened.
4. Report: per-model rates for each label, the 3 worst conversations (convo_id and what went wrong), and whether each failure traces to the model or to our prompts and code. If it's ours, propose the fix. If the canary holds up, say so — I'll raise the split.
```

The one-liner adds `list_reflexes`, `reflex_summary`, and `get_reflex_traces` (plus `codebase_search` and `edit_file`) to Claude Code, Cursor, and Codex. [MCP setup guide →](/mcpquickstart)

***

## Open Source Models + Reflexes

Open-weight models — GLM-5.2, MiniMax, DeepSeek V4 — on the same OpenAI-compatible API. Call one with the OpenAI package, then label every turn with a [Reflex](/sdk/components/reflexes).

<Steps>
  <Step title="Call a model">
    Point the OpenAI SDK at Morph and pick a model.

    <Tabs>
      <Tab title="TypeScript">
        ```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-glm52-744b",
          messages: [{ role: "user", content: "Refactor this Express handler to async/await: ..." }],
        });

        console.log(response.choices[0].message.content);
        ```
      </Tab>

      <Tab title="Python">
        ```python theme={null}
        import os
        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-glm52-744b",
            messages=[{"role": "user", "content": "Refactor this Express handler to async/await: ..."}],
        )

        print(response.choices[0].message.content)
        ```
      </Tab>
    </Tabs>

    Every model and its context window is on the [Open Source Models page](/sdk/components/fast-models).
  </Step>

  <Step title="Label every turn with Reflexes">
    One `morphTracing` call instruments the OpenAI SDK. Wrap the turn, name the Reflexes that label it, and Morph classifies each one async — off your request path, no added latency.

    <Tabs>
      <Tab title="TypeScript">
        ```typescript theme={null}
        import OpenAI from "openai";
        import { morphTracing } from "@morphllm/morphsdk/tracing";

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

        const turn = morph.begin({
          userId: "u1",
          convoId: "c1",
          event: "chat",
          evals: { user: ["jailbreak", "user-frustrated"], assistant: ["leaked-thinking"] },
        });
        turn.setInput(userMessage);

        const response = await client.chat.completions.create({
          model: "morph-glm52-744b",
          messages: [{ role: "user", content: userMessage }],
        });

        await turn.finish({ output: response.choices[0].message.content });
        ```
      </Tab>

      <Tab title="Python">
        ```python theme={null}
        # pip install 'morphsdk[otel]'
        import os
        from openai import OpenAI
        from morphsdk.tracing import morph_tracing

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

        turn = morph.begin({
            "user_id": "u1",
            "convo_id": "c1",
            "event": "chat",
            "evals": {"user": ["jailbreak", "user-frustrated"], "assistant": ["leaked-thinking"]},
        })
        turn.set_input(user_message)

        response = client.chat.completions.create(
            model="morph-glm52-744b",
            messages=[{"role": "user", "content": user_message}],
        )

        turn.finish({"output": response.choices[0].message.content})
        ```
      </Tab>
    </Tabs>

    **See the labels** two ways: open the [Traces dashboard](https://morphllm.com/dashboard/traces), or pull them in code with `morph.traces.list()` — each turn carries its labels under `reflexResults`. Tracing is async, so labels land shortly after the turn does.

    Want a label **inline** instead of async? Call `morph.reflex.predict()` and read the result on the spot:

    ```typescript theme={null}
    import { MorphClient } from "@morphllm/morphsdk";

    const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });
    const result = await morph.reflex.predict({ model: "jailbreak", text: userMessage });

    console.log(result.label, result.confidence); // "jailbreak" 0.95
    if (result.selected.includes("jailbreak")) throw new Error("blocked");
    ```
  </Step>
</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="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}
    brew install ripgrep   # or: apt-get install ripgrep / choco install ripgrep
    ```

    Same `@morphllm/morphsdk` from above — WarpGrep just needs ripgrep on your PATH.
  </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">
    Same factory pattern as Fast Apply — `createWarpGrepTool` for any framework:

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

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

    `morph.openai.createWarpGrepTool()` and `morph.vercel.createWarpGrepTool()` mirror this. 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="Open Source Models" icon="rocket" href="/sdk/components/fast-models">
    Qwen, GLM, MiniMax, DeepSeek — context windows and pricing
  </Card>

  <Card title="Reflexes" icon="bullseye" href="/sdk/components/reflexes">
    Label every turn — jailbreaks, loops, frustration, and more
  </Card>

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