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

# API Reference

> Complete MorphClient API and types

## MorphClient

Unified client for all Morph tools.

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

const morph = new MorphClient({
  apiKey?: string;          // Your Morph API key
  debug?: boolean;          // Default: false (enables logging)
  timeout?: number;         // Default: varies by tool
  retryConfig?: RetryConfig; // Optional retry configuration
});
```

### Namespaces

```typescript theme={null}
morph.fastApply         // FastApplyClient
morph.warpGrep          // WarpGrepClient
morph.git               // MorphGit
```

### Standalone Clients (Advanced)

Need custom configuration per tool? Use individual clients:

```typescript theme={null}
import { FastApplyClient } from '@morphllm/morphsdk';

// FastApply with custom settings
const fastApply = new FastApplyClient({
  apiKey: "YOUR_API_KEY",
  timeout: 60000
});
```

<Tip>
  **Use when:** You need tool-specific configuration that differs from defaults (custom URLs, different timeouts, etc.).
</Tip>

***

## Fast Apply

### `morph.fastApply.execute(input, overrides?)`

Edit files with AI-powered merge.

```typescript theme={null}
const result = await morph.fastApply.execute({
  target_filepath: 'src/auth.ts',
  baseDir: './my-project',      // Optional: defaults to cwd
  instructions: 'Add error handling',
  code_edit: '// ... existing code ...\nif (!user) throw new Error("Invalid");\n// ... existing code ...'
}, {
  // Optional overrides
  generateUdiff: true,
  autoWrite: true,
  timeout: 60000
});

console.log(result.udiff);
console.log(result.changes);  // { linesAdded, linesRemoved, linesModified }
```

### Framework Adapters

<CodeGroup>
  ```typescript Anthropic theme={null}
  import { createEditFileTool } from '@morphllm/morphsdk/tools/fastapply/anthropic';

  const tool = createEditFileTool(morph.fastApply);
  // OR with config: createEditFileTool({ morphApiKey: '...' })
  ```

  ```typescript OpenAI theme={null}
  import { createEditFileTool } from '@morphllm/morphsdk/tools/fastapply/openai';

  const tool = createEditFileTool(morph.fastApply);
  ```

  ```typescript Vercel theme={null}
  import { createEditFileTool } from '@morphllm/morphsdk/tools/fastapply/vercel';

  const tool = createEditFileTool(morph.fastApply);
  ```
</CodeGroup>

### Types

```typescript theme={null}
interface EditFileInput {
  target_filepath: string;
  instructions: string;
  code_edit: string;
}

interface EditFileResult {
  success: boolean;
  filepath: string;
  udiff?: string;
  changes: {
    linesAdded: number;
    linesRemoved: number;
    linesModified: number;
  };
  error?: string;
}
```

***

## WarpGrep

### `morph.warpGrep.execute(input)`

Agentic code search. Runs grep and file reads in a separate context window.

```typescript theme={null}
const result = await morph.warpGrep.execute({
  searchTerm: 'How does user authentication work?',
  repoRoot: '.',
  includes: ['src/auth/**']  // Optional glob filters
});

for (const ctx of result.contexts ?? []) {
  console.log(ctx.file, ctx.content);
}
```

### Framework Adapters

<CodeGroup>
  ```typescript Anthropic theme={null}
  const tool = morph.anthropic.createWarpGrepTool({ repoRoot: '.' });
  ```

  ```typescript OpenAI theme={null}
  const tool = morph.openai.createWarpGrepTool({ repoRoot: '.' });
  ```

  ```typescript Vercel theme={null}
  const tool = morph.vercel.createWarpGrepTool({ repoRoot: '.' });
  ```
</CodeGroup>

### Types

```typescript theme={null}
interface WarpGrepInput {
  searchTerm: string;      // Natural language search query
  repoRoot: string;        // Root directory to search
  excludes?: string[];     // Glob patterns to exclude
  includes?: string[];     // Glob patterns to include
  streamSteps?: boolean;   // Stream progress
}

interface WarpGrepResult {
  success: boolean;
  contexts?: Array<{
    file: string;          // File path relative to repo root
    content: string;       // Relevant code section
  }>;
  summary?: string;
  error?: string;
}
```

<Note>
  **Requires ripgrep** on the machine running the search. Full options — streaming, GitHub search, sandbox execution — are on the [WarpGrep pages](/sdk/components/warp-grep/index).
</Note>

***

## Git Operations

### `morph.git.*`

Access the MorphGit client via `morph.git`.

```typescript theme={null}
// All standard git operations available
await morph.git.init({ repoId: 'my-project', dir: './project' });
await morph.git.clone({ repoId: 'my-project', dir: './project' });
await morph.git.add({ dir: './project', filepath: '.' });
await morph.git.commit({ dir: './project', message: 'Update' });
await morph.git.push({ dir: './project' });
await morph.git.pull({ dir: './project' });
```

### Repository Management

```typescript theme={null}
// Initialize new repository
await morph.git.init({
  repoId: string;
  dir: string;
  defaultBranch?: string;  // Default: 'main'
});

// Clone existing repository
await morph.git.clone({
  repoId: string;
  dir: string;
  branch?: string;
  depth?: number;
  singleBranch?: boolean;  // Default: true
});
```

### Basic Operations

```typescript theme={null}
// Stage files
await morph.git.add({
  dir: string;
  filepath: string;  // Use '.' for all files
});

// Commit changes
const sha = await morph.git.commit({
  dir: string;
  message: string;
  author?: { name: string; email: string; };
});

// Push to remote
await morph.git.push({
  dir: string;
  remote?: string;   // Default: 'origin'
  branch?: string;
});

// Pull from remote
await morph.git.pull({
  dir: string;
  remote?: string;
  branch?: string;
});
```

### Status & History

```typescript theme={null}
// Get file status
const status = await morph.git.status({
  dir: string;
  filepath: string;
});
// Returns: 'modified' | '*added' | 'deleted' | 'unmodified' | 'absent'

// Get all file statuses
const matrix = await morph.git.statusMatrix({ dir: string });
// Returns: { filepath: string; status: string; }[]

// Get commit history
const commits = await morph.git.log({
  dir: string;
  depth?: number;
  ref?: string;
});
```

### Branching

```typescript theme={null}
// Create branch
await morph.git.branch({
  dir: string;
  name: string;
  checkout?: boolean;  // Default: false
});

// Checkout branch/commit
await morph.git.checkout({
  dir: string;
  ref: string;
});

// List all branches
const branches = await morph.git.listBranches({ dir: string });

// Get current branch
const current = await morph.git.currentBranch({ dir: string });

// Get commit hash
const hash = await morph.git.resolveRef({ dir: string; ref: 'HEAD' });
```

***

## Environment Variables

```bash theme={null}
# Required for most tools
MORPH_API_KEY=YOUR_API_KEY

# Optional overrides (advanced users only)
MORPH_API_URL=https://api.morphllm.com      # Fast Apply API
MORPH_ENVIRONMENT=DEV                        # Use localhost for browser worker
```

Get your API key: [morphllm.com/dashboard/api-keys](https://morphllm.com/dashboard/api-keys)

***

## Import Patterns

### Main SDK (Recommended)

```typescript theme={null}
// Unified client
import { MorphClient } from '@morphllm/morphsdk';

// Individual clients (for advanced use)
import { 
  FastApplyClient, 
  MorphGit 
} from '@morphllm/morphsdk';

// All types
import type { 
  EditFileInput,
  WarpGrepInput,
  // ... etc
} from '@morphllm/morphsdk';
```

### Framework Adapters

```typescript theme={null}
// Anthropic
import { createEditFileTool } from '@morphllm/morphsdk/tools/fastapply/anthropic';

// OpenAI
import { createEditFileTool } from '@morphllm/morphsdk/tools/fastapply/openai';

// Vercel
import { createEditFileTool } from '@morphllm/morphsdk/tools/fastapply/vercel';
```

WarpGrep tools come off the client: `morph.anthropic.createWarpGrepTool()`, `morph.openai.createWarpGrepTool()`, `morph.vercel.createWarpGrepTool()`.

***

## Error Handling

All tools return results with `success: boolean` and optional `error: string`.

```typescript theme={null}
const result = await morph.fastApply.execute({ ... });

if (!result.success) {
  console.error('Edit failed:', result.error);
  // Handle error...
}

const searchResults = await morph.warpGrep.execute({ ... });
if (!searchResults.success) {
  console.error('Search failed:', searchResults.error);
}
```

<Tip>
  **Automatic retries:** SDK automatically retries failed requests with exponential backoff for transient errors (rate limits, timeouts).
</Tip>

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Examples" icon="code" href="/sdk/examples">
    See real-world usage patterns
  </Card>

  <Card title="Dashboard" icon="chart-line" href="https://morphllm.com/dashboard">
    Monitor usage and manage API keys
  </Card>
</CardGroup>
