Skip to content
kitn AI/UI

Image artifact

kai-image-artifact

Bare base64 cannot say what it is, so the media type is required.

  • Shadow DOM
  • Base64 or Uint8Array
  • Skeleton while it resolves
  • Media type required
<kai-image-artifact media-type="image/png" alt="A generated chart"></kai-image-artifact>
<script type="module">
import '@kitn.ai/ui/web-components';
const el = document.querySelector('kai-image-artifact');
// a base64 payload (a string attribute or property):
el.data = '<...base64 encoded image data...>';
// or raw bytes, as a property:
// el.data = new Uint8Array([...]);
</script>
  • data is the payload: a string (BARE base64, the shape the providers hand back) or a Uint8Array (set as a property). It is never a URL: for a data: URI or an https address, use Image’s src.
  • media-type is required: a base64 payload does not describe itself, so a guessed image/png labels a JPEG wrong. Everything downstream that trusts the label (your API, a file written to disk, the wire) is told the wrong type.
  • alt describes the image. Pass a real sentence; it is what a screen reader announces in place of the picture.

The SDK hands generated images back as one object that carries both representations (GeneratedFile):

const { image } = await generateImage({ model, prompt });
// image: { base64, uint8Array, mediaType } — pick the one you have
el.data = image.base64; // or image.uint8Array
el.mediaType = image.mediaType;

One line each, and deliberately not the SDK’s object: data plus mediaType describes the thing, so a change in how the SDK packages it never reaches your markup.

Swap data and media-type per artifact; nothing else changes.

Every artifact needs its own sentence, not a shared “generated image”.

PropertyTypeDefaultNotes
theme'auto'Color mode (`auto` follows prefers-color-scheme).
data—The image PAYLOAD: BARE base64 (never a URI) or raw bytes. Attribute `data` for base64; JS property for `Uint8Array`.
mediaType—The payload's MIME type, e.g. `image/png`. Attribute `media-type`. REQUIRED.
alt''Alt text. Attribute `alt`. Always give meaningful text: an empty alt marks the image as decorative.
class—Extra classes for the `<img>` (and for the skeleton while nothing resolves).

This element wraps these SolidJS components — reach for them directly when you need finer control than the props expose.

ImageArtifact