Skip to content

Artifact

Code, images, documents.


Purpose

Display structured content — syntax-highlighted code, AI-generated images, documents, charts.

Use <artifact> when the output should remain inspectable or downloadable rather than being flattened into plain conversational text.


Try it Live

editor.g
12345678910111213141516171819

Edit the Grain document and inspect the rendered preview beside it.

preview

Interactive preview initializes after hydration.

Interactive preview initializes after hydration. Open the docs preview at /grain/; the site is mounted under the project base path.

G-Lang

grain
<artifact type="code" language="javascript" title="hello.js"
  copyable="true" downloadable="true">
  function hello() {
    console.log('Hello, World!');
  }
</artifact>

<artifact type="image" title="Generated Image">
  [base64 data]
</artifact>

Attributes

AttributeTypeDescription
typecode | image | chart | document | file | video | audioContent type
languagestringProgramming language (for code)
titlestringDisplay title
filenamestringDownloadable filename
copyabletrue | falseAllow copy
downloadabletrue | falseAllow download
editabletrue | falseAllow editing
runnabletrue | falseAllow execution

States

LOADING → READY → INTERACTING
   ↓        ↓
ERROR   EXPANDED

         EDITING

Events

EventDescription
artifact.loadLoading started
artifact.readyLoaded successfully
artifact.copyContent copied
artifact.downloadDownload started
artifact.editContent edited

Examples

Code with syntax highlighting

grain
<artifact type="code" language="python" title="factorial.py"
  copyable="true" runnable="true">
  def factorial(n):
      if n <= 1:
          return 1
      return n * factorial(n - 1)
</artifact>

Chart visualization

grain
<artifact type="chart" title="Monthly Revenue">
  {"type": "bar", "data": [120, 150, 180, 220]}
</artifact>

Image artifact

grain
<artifact type="image" title="Generated Art" downloadable="true">
  data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...
</artifact>

Document/PDF

grain
<artifact type="document" title="Report.pdf" filename="report.pdf">
  [PDF content or URL]
</artifact>

Production Guidance

  • Prefer artifacts for durable outputs such as code, reports, or generated files.
  • Keep metadata like title, filename, and language populated so adapters can present the content consistently.
  • Use <tool> for execution state and <artifact> for the resulting object once it is ready to inspect.

Released under the MIT License.