Skip to main content
🔒 CONFIDENTIAL - INTERNAL USE ONLYThis page contains proprietary enterprise API documentation and is linked to your account. Do not share any information mentioned here with anyone external to your company. This documentation is for internal development and integration purposes only.

Quickstart

Switch to instruction-guided editing with 98% accuracy in 3 steps.

Prerequisites

  • Enterprise API key from your Morph account
  • Access to https://api.morphllm.com/v1/
ModelSpeedAccuracyInput LimitOutput Limit
morph-v3-fast10,500+ tok/sec96%16k tokens16k tokens
morph-v3-large5000+ tok/sec98%16k tokens16k tokens
auto5000-10,500tok/sec98%16k tokens16k tokens

1. Configure Your Edit Tool

Set up your AI agent to generate the proper instructions guided format for the highest accuracy editing.
Edit File Tool Description:
Use this tool to make an edit to an existing file.

This will be read by a less intelligent model, which will quickly apply the edit. You should make it clear what the edit is, while also minimizing the unchanged code you write.
When writing the edit, you should specify each edit in sequence, with the special comment // ... existing code ... to represent unchanged code in between edited lines.

For example:

// ... existing code ...
FIRST_EDIT
// ... existing code ...
SECOND_EDIT
// ... existing code ...
THIRD_EDIT
// ... existing code ...

You should still bias towards repeating as few lines of the original file as possible to convey the change.
But, each edit should contain minimally sufficient context of unchanged lines around the code you're editing to resolve ambiguity.
DO NOT omit spans of pre-existing code (or comments) without using the // ... existing code ... comment to indicate its absence. If you omit the existing code comment, the model may inadvertently delete these lines.
If you plan on deleting a section, you must provide context before and after to delete it. If the initial code is ```code \n Block 1 \n Block 2 \n Block 3 \n code```, and you want to remove Block 2, you would output ```// ... existing code ... \n Block 1 \n  Block 3 \n // ... existing code ...```.
Make sure it is clear what the edit should be, and where it should be applied.
ALWAYS make all edits to a file in a single edit_file instead of multiple edit_file calls to the same file. The apply model can handle many distinct edits at once.
Parameters:
  • target_filepath (string, required): The path of the target file to modify
  • instructions (string, required): A single sentence written in the first person describing what you’re changing. Used to help disambiguate uncertainty in the edit.
  • code_edit (string, required): Specify ONLY the precise lines of code that you wish to edit. Use // ... existing code ... for unchanged sections.
The instructions field should be generated by your AI model, not user input. Follow the tool description above nearly verbatim - terminology like “use it to disambiguate uncertainty in the edit” should be used. Example: “I am adding error handling to the user authentication function”

2. Send to Morph Enterprise API

import { OpenAI } from 'openai';

const client = new OpenAI({
  apiKey: 'your-enterprise-api-key',
  baseURL: 'https://api.morphllm.com/v1'
});

const testOriginalCode = `
const a = 1
const b = 2
function add(a, b) {
  return a + b
}

function subtract(a, b) {
  return a - b
}

const authenticateUser () => {
  return "Authenticated"
}
`;

// Test data - your agent should generate these
const testInstruction = "I will add the real user authentication function and remove the old authentication method";

const testUpdateSnippet = `
  // ... existing code ...
const authenticateUser = (email, password) => {
  const result = await verifyUser(email, password)
  if (result) {
    return "Authenticated"
  } else {
    return "Unauthenticated"
  }
}
`;

async function applyEnterpriseEdit(
  instruction: string, 
  originalCode: string, 
  updateSnippet: string
): Promise<string> {
  const response = await client.chat.completions.create({
    model: "morph-v3-fast",
    messages: [
      {
        role: "user",
        content: `<instruction>${instruction}</instruction>\n<code>${originalCode}</code>\n<update>${updateSnippet}</update>`
      }
    ]
  });
  
  return response.choices[0].message.content || '';
}

// Example usage
async function main() {
  try {
    const finalCode = await applyEnterpriseEdit(
      testInstruction, 
      testOriginalCode, 
      testUpdateSnippet
    );
    console.log("Final merged code:");
    console.log(finalCode);
  } catch (error) {
    console.error("Error applying edit:", error);
  }
}

// Run the example
main();

3. Handle the Response

Extract the merged code from the enterprise API response. Response Format:
final_code = response.choices[0].message.content
Extract the Final Code:
const finalCode = response.choices[0].message.content;
// Write to file or return to your application
await fs.writeFile(targetFile, finalCode);

Enterprise Features

Perfect Accuracy

Instruction-guided editing achieves 98% accuracy on complex code changes

44k Input Tokens

Handle entire large files, complete modules, and complex codebases

36k Output Tokens

Generate complete implementations, full refactors, and comprehensive updates
Migration from Standard API:
Enterprise API requires an <instruction> field but maintains backward compatibility with existing <update> patterns.