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

# Create Artifact

Create a new artifact with the specified template and content.

## Request

<ParamField body="template" type="string" required>
  Template type. One of: `markdown`, `chart`, `table`, `pdf`
</ParamField>

<ParamField body="title" type="string">
  Display title for the artifact
</ParamField>

<ParamField body="description" type="string">
  Short description shown below the title
</ParamField>

<ParamField body="content" type="object" required>
  Template-specific content object. See [Templates](/templates/overview) for schema details.
</ParamField>

<ParamField body="expiresIn" type="string">
  Expiration duration. Examples: `1h`, `7d`, `30d`. If not set, artifact doesn't expire.
</ParamField>

<ParamField body="metadata" type="object">
  Custom key-value pairs to store with the artifact
</ParamField>

## Response

<ResponseField name="id" type="string">
  Unique artifact ID (format: `art_xxx`)
</ResponseField>

<ResponseField name="template" type="string">
  The template type used
</ResponseField>

<ResponseField name="title" type="string">
  Display title
</ResponseField>

<ResponseField name="status" type="string">
  Artifact status: `active`, `expired`, `deleted`
</ResponseField>

<ResponseField name="createdAt" type="string">
  ISO 8601 timestamp
</ResponseField>

<ResponseField name="expiresAt" type="string">
  ISO 8601 expiration timestamp (if set)
</ResponseField>

<ResponseExample>
  ```json 201 theme={null}
  {
    "id": "art_abc123",
    "template": "markdown",
    "title": "My Document",
    "status": "active",
    "createdAt": "2024-01-15T12:00:00Z",
    "expiresAt": "2024-01-22T12:00:00Z"
  }
  ```

  ```json 400 theme={null}
  {
    "error": {
      "code": "invalid_template",
      "message": "Template 'invalid' is not supported"
    }
  }
  ```
</ResponseExample>

## Code Examples

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://genui.sh/api/artifacts \
    -H "Authorization: Bearer $GENUI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "template": "markdown",
      "title": "My Document",
      "content": {"text": "# Hello World\n\nThis is my artifact."},
      "expiresIn": "7d"
    }'
  ```

  ```python Python theme={null}
  import requests
  import os

  response = requests.post(
      "https://genui.sh/api/artifacts",
      headers={"Authorization": f"Bearer {os.environ['GENUI_API_KEY']}"},
      json={
          "template": "markdown",
          "title": "My Document",
          "content": {"text": "# Hello World\n\nThis is my artifact."},
          "expiresIn": "7d"
      }
  )
  artifact = response.json()
  print(f"Created artifact: {artifact['id']}")
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://genui.sh/api/artifacts', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.GENUI_API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      template: 'markdown',
      title: 'My Document',
      content: { text: '# Hello World\n\nThis is my artifact.' },
      expiresIn: '7d'
    })
  });
  const artifact = await response.json();
  console.log(`Created artifact: ${artifact.id}`);
  ```

  ```go Go theme={null}
  package main

  import (
      "bytes"
      "encoding/json"
      "fmt"
      "net/http"
      "os"
  )

  func main() {
      payload := map[string]interface{}{
          "template":  "markdown",
          "title":     "My Document",
          "content":   map[string]string{"text": "# Hello World\n\nThis is my artifact."},
          "expiresIn": "7d",
      }
      body, _ := json.Marshal(payload)

      req, _ := http.NewRequest("POST", "https://genui.sh/api/artifacts", bytes.NewBuffer(body))
      req.Header.Set("Authorization", "Bearer "+os.Getenv("GENUI_API_KEY"))
      req.Header.Set("Content-Type", "application/json")

      client := &http.Client{}
      resp, _ := client.Do(req)
      defer resp.Body.Close()

      var result map[string]interface{}
      json.NewDecoder(resp.Body).Decode(&result)
      fmt.Printf("Created artifact: %s\n", result["id"])
  }
  ```

  ```ruby Ruby theme={null}
  require 'net/http'
  require 'json'
  require 'uri'

  uri = URI('https://genui.sh/api/artifacts')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  request = Net::HTTP::Post.new(uri)
  request['Authorization'] = "Bearer #{ENV['GENUI_API_KEY']}"
  request['Content-Type'] = 'application/json'
  request.body = {
    template: 'markdown',
    title: 'My Document',
    content: { text: '# Hello World\n\nThis is my artifact.' },
    expiresIn: '7d'
  }.to_json

  response = http.request(request)
  artifact = JSON.parse(response.body)
  puts "Created artifact: #{artifact['id']}"
  ```

  ```rust Rust theme={null}
  use reqwest::header::{AUTHORIZATION, CONTENT_TYPE};
  use serde_json::json;
  use std::env;

  #[tokio::main]
  async fn main() -> Result<(), Box<dyn std::error::Error>> {
      let api_key = env::var("GENUI_API_KEY")?;
      let client = reqwest::Client::new();

      let response = client
          .post("https://genui.sh/api/artifacts")
          .header(AUTHORIZATION, format!("Bearer {}", api_key))
          .header(CONTENT_TYPE, "application/json")
          .json(&json!({
              "template": "markdown",
              "title": "My Document",
              "content": {"text": "# Hello World\n\nThis is my artifact."},
              "expiresIn": "7d"
          }))
          .send()
          .await?;

      let artifact: serde_json::Value = response.json().await?;
      println!("Created artifact: {}", artifact["id"]);
      Ok(())
  }
  ```

  ```csharp .NET theme={null}
  using System.Net.Http.Json;

  var client = new HttpClient();
  client.DefaultRequestHeaders.Add("Authorization", $"Bearer {Environment.GetEnvironmentVariable("GENUI_API_KEY")}");

  var response = await client.PostAsJsonAsync("https://genui.sh/api/artifacts", new {
      template = "markdown",
      title = "My Document",
      content = new { text = "# Hello World\n\nThis is my artifact." },
      expiresIn = "7d"
  });

  var artifact = await response.Content.ReadFromJsonAsync<JsonElement>();
  Console.WriteLine($"Created artifact: {artifact.GetProperty("id")}");
  ```
</CodeGroup>
