Skip to main content
Artifacts are designed to be refined iteratively. Instead of regenerating a document from scratch to make a change, you can provide editing instructions in a follow-up prompt. The core concept is to make a new API call that includes the existing artifact content as context, along with a new prompt describing the desired modifications.

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.
src/app/api/edit-slides/route.ts
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 }
}