> ## Documentation Index
> Fetch the complete documentation index at: https://docs.relace.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Apply file edits from your coding agent at >10k tok/s

## Overview

When using frontier models to edit your codebase, you’re paying premium rates for both valuable changes and unchanged sections alike.

Instant apply is about the separation of concerns — use heavyweight models for new sections of code, and use a lightweight model to merge the new into the old.

Using `relace-apply-3` running at 10k+ tok/s, this method is **over 3x faster and cheaper** than rewriting files from scratch.

We explain how we train/inference the model to achieve these speeds in our [blog post](https://www.relace.ai/blog/relace-apply-3).

## Prerequisites

* [Sign up](https://app.relace.ai) for a Relace account.
* Create an [API key](https://app.relace.ai/settings/api-keys).

<Steps>
  <Step title="Generate Code Snippets">
    Add instructions for formatting edits somewhere in the system prompt for your LLM of choice. See our [edit tool](/docs/instant-apply/agent) definition if you're building an agent.

    ````
      - Abbreviate sections of the code in your response that will remain the same by replacing those sections with a comment like  "// ... rest of code ...", "// ... keep existing code ...", "// ... code remains the same".
      - Be precise with the location of these comments within your edit snippet. A less intelligent model will use the context clues you provide to accurately merge your edit snippet.
      - If applicable, it can help to include some concise information about the specific code segments you wish to retain "// ... keep calculateTotalFunction ... ".
      - If you plan on deleting a section, you must provide the context to delete it. Some options:
          1. 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 ```// ... keep existing code ... \n Block 1 \n  Block 3 \n // ... rest of code ...```.
          2. If the initial code is ```code \n Block \n code```, and you want to remove Block, you can also specify ```// ... keep existing code ... \n // remove Block \n // ... rest of code ...```.
      - You must use the comment format applicable to the specific code provided to express these truncations.
      - Preserve the indentation and code structure of exactly how you believe the final code will look (do not output lines that will not be in the final code after they are merged).
      - Be as length efficient as possible without omitting key context.
    ````
  </Step>

  <Step title="Merge with Instant Apply">
    Pass the abbreviated edit snippet along with the initial code to the Instant Apply endpoint.

    <CodeGroup>
      ```typescript Relace API theme={null}
      const url = "https://instantapply.endpoint.relace.run/v1/code/apply";
      const apiKey = "[YOUR_API_KEY]";

      const headers = {
        "Authorization": `Bearer ${apiKey}`,
        "Content-Type": "application/json"
      };

      const data = {
        initial_code: initialCode,
        edit_snippet: editSnippet,
      };

      const response = await fetch(url, {
        method: "POST",
        headers: headers,
        body: JSON.stringify(data)
      });

      return await response.json();
      ```

      ```typescript OpenAI Compatible theme={null}
      import OpenAI from "openai";

      const client = new OpenAI({
        apiKey: "YOUR_API_KEY",
        baseURL: "https://instantapply.endpoint.relace.run/v1/apply"
      });

      const userMessage = `
      <code>${initialCode}</code>
      <update>${editSnippet}</update>
      `;

      const response = await client.chat.completions.create({
        model: "auto",
        messages: [
          {
            role: "user",
            content: userMessage
          }
        ]
      });
      ```
    </CodeGroup>
  </Step>

  <Step title="Parse Final Code from Response">
    Collect the merged code from the response json.

    ```typescript theme={null}
    {
      "mergedCode": mergedCode,
      "usage": {
        "prompt_tokens": promptTokens,
        "completion_tokens": completionTokens,
        "total_tokens": totalTokens
      }
    }
    ```
  </Step>
</Steps>

For more information and explanation of additional parameters see our [API reference](/api-reference/instant-apply/apply).
