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

# Apply code edit

> Uses the configured LLM provider (Relace or Morph) to apply a code edit to the original content.

To use this endpoint as an agent tool, follow these guidelines:

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.

Example format:
// ... 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 "Block 1\nBlock 2\nBlock 3", and you want to remove Block 2, you would output "// ... existing code ...\nBlock 1\nBlock 3\n// ... existing code ...".

Make sure it is clear what the edit should be, and where it should be applied. Make edits to a file in a single edit_file call instead of multiple edit_file calls to the same file. The apply model can handle many distinct edits at once.



## OpenAPI

````yaml https://raw.githubusercontent.com/blaxel-ai/sandbox/refs/heads/main/sandbox-api/docs/openapi.yml put /codegen/fastapply/{path}
openapi: 3.0.0
info:
  contact: {}
  description: API for manipulating filesystem, processes and network.
  title: Sandbox API
  version: 0.0.1
servers:
  - url: https://sbx-{sandbox_id}-{workspace_id}.{region}.bl.run
    variables:
      sandbox_id:
        default: unknown
      workspace_id:
        default: unknown
      region:
        default: unknown
security:
  - BearerAuth: []
paths:
  /codegen/fastapply/{path}:
    put:
      tags:
        - fastapply
      summary: Apply code edit
      description: >-
        Uses the configured LLM provider (Relace or Morph) to apply a code edit
        to the original content.


        To use this endpoint as an agent tool, follow these guidelines:


        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.


        Example format:

        // ... 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 "Block 1\nBlock 2\nBlock 3",
        and you want to remove Block 2, you would output "// ... existing code
        ...\nBlock 1\nBlock 3\n// ... existing code ...".


        Make sure it is clear what the edit should be, and where it should be
        applied. Make edits to a file in a single edit_file call instead of
        multiple edit_file calls to the same file. The apply model can handle
        many distinct edits at once.
      parameters:
        - description: Path to the file to edit (relative to workspace)
          in: path
          name: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApplyEditRequest'
        description: Code edit request
        required: true
      responses:
        '200':
          description: Code edit applied successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApplyEditResponse'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Unprocessable entity - failed to process the request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '503':
          description: Service unavailable - no provider configured
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    ApplyEditRequest:
      properties:
        codeEdit:
          example: |-
            // Add world parameter
            function hello(world) {
              console.log('Hello', world);
            }
          type: string
        model:
          example: auto
          type: string
      required:
        - codeEdit
      type: object
    ApplyEditResponse:
      properties:
        message:
          example: Code edit applied successfully
          type: string
        originalContent:
          example: |-
            function hello() {
              console.log('Hello');
            }
          type: string
        path:
          example: src/main.js
          type: string
        provider:
          example: Relace
          type: string
        success:
          example: true
          type: boolean
        updatedContent:
          example: |-
            function hello(world) {
              console.log('Hello', world);
            }
          type: string
      type: object
    ErrorResponse:
      properties:
        error:
          example: Error message
          type: string
      required:
        - error
      type: object
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````