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

# Prompt-Based Editing

> Modify existing artifacts by sending existing artifact back to the API with a new prompt

Prompt-based editing allows you to modify an artifact by making a new API call that includes the **existing artifact content** as context, along with a new prompt describing the desired modifications. Instead of regenerating a document from scratch, you provide editing instructions in a follow-up prompt.

### Editing Pattern

To edit an artifact, you call the same Artifact API endpoint used for generation. The key difference is the structure of the `messages` array, which must contain two messages in this specific order:

1. **An `assistant` message:** The `content` of this message must be the full **artifact content string** of the document you want to edit.
2. **A `user` message:** The `content` of this message is your new prompt with the editing instructions, for example, "Add a slide about our key competitors" or "Change the title to 'Q4 Financial Report'".

The `metadata` object (with the `c1_artifact_type`) should be included just as it was in the original generation call to ensure the context is maintained.

### Full Example: Adding a Slide to a Presentation

This example shows the complete workflow for adding a new slide to an existing presentation.

<CodeGroup dropdown>
  ```typescript src/app/api/edit-slides/route.ts theme={null}
  import { NextRequest, NextResponse } from "next";
  import OpenAI from "openai";

  const client = new OpenAI({
    baseURL: "https://api.thesys.dev/v1/artifact",
    apiKey: process.env.THESYS_API_KEY,
  });

  export async function POST(req: NextRequest): Promise<NextResponse> {
    { existingArtifactContent: string } = await req.json()
    const editPrompt = "Add a new slide at the end summarizing the key takeaways.";

    const updatedArtifact = await client.chat.completions.create({
      model: "c1/artifact/v-20251030",
      messages: [
        // 1. Provide the existing artifact content as the assistant's message.
        {
          role: 'assistant',
          content: existingArtifactContent,
        },
        // 2. Provide the new editing instruction as the user's message.
        {
          role: 'user',
          content: editPrompt,
        },
      ],
      metadata: {
        thesys: JSON.stringify({
          c1_artifact_type: 'slides',
          id: 'unique-id', // previously generated unique id for the artifact
        }),
      },
    });

    // The response contains the new, modified artifact content string.
    return { content: updatedArtifact.choices[0].message.content }
  }
  ```

  ```python theme={null}
  import os
  import json
  import openai
  from pydantic import BaseModel

  client = openai.OpenAI(
      base_url="https://api.thesys.dev/v1/artifact",
      api_key=os.environ.get("THESYS_API_KEY"),
  )

  class EditSlidesRequest(BaseModel):
    existing_artifact_content: str

  @app.post('/edit-slides')
  def add_slide_to_artifact(req: EditSlidesRequest):
      edit_prompt = "Add a new slide at the end summarizing the key takeaways."

      updated_artifact = client.chat.completions.create(
          model="c1/artifact/v-20251030",
          messages=[
              # 1. Provide the existing artifact content as the assistant's message.
              {
                  "role": "assistant",
                  "content": req.existing_artifact_content,
              },
              # 2. Provide the new editing instruction as the user's message.
              {
                  "role": "user",
                  "content": edit_prompt,
              },
          ],
          metadata={
              "thesys": json.dumps({
                  "c1_artifact_type": "slides"
                  "id": "unique-id", # previously generated unique id for the artifact
              })
          }
      )

      # The response contains the new, modified artifact content string.
      return { "content": updated_artifact.choices[0].message.content }
  ```
</CodeGroup>
