> ## 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.

# Generating Artifacts

> Call the Artifact API to create new reports and slides from a prompt

Generating an artifact involves making an API call to a dedicated C1 endpoint. This is done using a standard OpenAI client library, configured to connect to the C1 Artifacts service.

### Configuring the API Client

To begin, initialize your OpenAI client to use the C1 Artifacts endpoint and your Thesys API key.

**Artifact API Endpoint:** `https://api.thesys.dev/v1/artifact`

<Note>
  You can create a new API key from [Developer Console](https://console.thesys.dev/keys).
</Note>

<CodeGroup dropdown>
  ```typescript theme={null}
  import OpenAI from "openai";

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

  ```python theme={null}
  import os
  import openai

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

### Structuring the Request

The API call's payload has two main parts:

* `messages` array for your prompt
* `metadata` object for C1-specific instructions.

#### The `messages` Array

This is where you provide the prompt to generate the artifact. The `content` of the `user` message can include rich context, like data or a detailed description of the desired output.
You can also include a `system` prompt to provide high-level instructions.

#### The `metadata` Object

This object provides C1-specific instructions for the generation. It must contain a `thesys` key, whose value is a stringified JSON object.

Inside the `thesys` object, the `c1_artifact_type` property tells C1 what kind of artifact to generate, for example `'slides'` or `'report'`.

```json theme={null}
{
  "c1_artifact_type": "slides", // or 'report' for generating a report
  "id": "unique-id-for-the-artifact"
}
```

### Full Example: Generating Slides

This example brings the concepts together to generate a slide deck from a prompt. The `artifact` variable in the response will contain the C1 DSL string, which is ready to be sent to your frontend for rendering.

<CodeGroup dropdown>
  ```typescript src/app/api/generate-slides/route.ts theme={null}
  import { NextRequest, NextResponse } from "next/server";
  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> {
    const artifact = await client.chat.completions.create({
      model: "c1/artifact/v-20251030", // Specify the model
      messages: [
        {
          role: 'system',
          content: 'system prompt here: it can include high-level instructions or context for the generation.',
        },
        {
          role: 'user',
          content: 'Generate a presentation showcasing the top 10 AI tools that can transform business operations, with implementation timelines and ROI calculations.',
        },
      ],
      metadata: {
        thesys: JSON.stringify({
          c1_artifact_type: 'slides',
          id: 'unique-id-for-the-artifact', // this is required for editing the artifact in future
        }),
      }
    });

    // artifact.choices[0].message.content contains the C1 DSL string for the generated artifact
    return { "content": artifact.choices[0].message.content };
  }
  ```

  ```python theme={null}
  import os
  import json
  import openai

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

  @app.post("/generate-slides")
  def generate_slides():
      artifact = client.chat.completions.create(
          model="c1/artifact/v-20251030", # Specify the model
          messages=[{
              "role": "user",
              "content": "Generate a presentation showcasing the top 10 AI tools that can transform business operations, with implementation timelines and ROI calculations.",
          }],
          metadata={
              "thesys": json.dumps({
                  "c1_artifact_type": "slides",
                  "id": "unique-id-for-the-artifact", // this is required for editing the artifact in future
              })
          }
      )

      # artifact.choices[0].message.content contains the C1 DSL string for the generated artifact
      return { "content": artifact.choices[0].message.content }
  ```
</CodeGroup>
