Skip to main content

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

Call a model

Point the OpenAI SDK at Morph and pick a model. Same key as everything else.
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);
Every model and its context window is on the Open Source Models page.
2

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.
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 });
See the labels two ways: open the Traces dashboard, 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:
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");

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

Install

npm install @morphllm/morphsdk
Get your API key from the dashboard.
2

Run it

Save as apply.ts and run:
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);
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.”
3

Add to your agent

The SDK provides tool factories for every major framework. One line gives your agent an edit_file tool:
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" }]
});
For tool definition schemas, system prompt instructions, and output-parsing mode, see the Fast Apply product page.

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

Install

brew install ripgrep   # or: apt-get install ripgrep / choco install ripgrep
Same @morphllm/morphsdk from above — WarpGrep just needs ripgrep on your PATH.
2

Run it

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}`);
  }
}
3

Add to your agent

Same factory pattern as Fast Apply — createWarpGrepTool for any framework:
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.

Next Steps

Open Source Models

Qwen, GLM, MiniMax, DeepSeek — context windows and pricing

Reflexes

Label every turn — jailbreaks, loops, frustration, and more

Fast Apply

Tool schemas, system prompts, and the lazy edit format

WarpGrep

Streaming, GitHub search, remote execution

MCP Integration

One command to add Morph to Claude Code, Cursor, or Codex

SDK Reference

Complete API documentation