Skip to main content
Fill-in-the-middle (FIM) generates code that fits between existing code. You send the code before the cursor as prompt (the prefix) and the code after the cursor as suffix; Mercury Edit 2 returns the text that belongs in between. This is what powers inline autocomplete in an editor.

FIM vs. Next Edit

FIM has no separate fields for edit history or other open files. Add any extra context directly to prompt, such as imports, related types, or a short description of the intended code. Use Next Edit when the suggestion should incorporate edit history or recently viewed snippets.
Set your API key as an environment variable and install the SDK.
In the example below, the prefix defines factorial up to return n * and the suffix is the call that uses it. Mercury Edit 2 fills the gap — e.g. factorial(n - 1).