NetraNetra
Experimental · v0.1 alpha · Vercel AI SDK adapter

Stream AI-generated HTML into live, sandboxed previews.

Netra is a predictive HTML parser and streaming toolkit for the Vercel AI SDK. It balances unfinished documents for instant iframe rendering while keeping the model stream as the source of truth — so generative UI builds up smoothly instead of popping in at the end.

Try the live demo →
netra · streaming live
Experimental

Netra is in an early research phase. The packaged backend helper targets the Vercel AI SDK only for now. A lower-level, provider-agnostic adapter (streamHtmlArtifactFromTextStream) exists for other runtimes, but APIs may still change between alpha releases.

Why HTML

Because the web is already HTML — so render it natively, safely.

Markdown caps you at text and tables. Custom component runtimes ship a renderer and diff every token. HTML needs neither: stream it straight into a sandboxed iframe with safe-render techniques that keep the client light and the main thread free.

The browser is already HTML

Every device ships a world-class HTML/CSS engine. Netra streams straight into it — no bespoke component runtime, no React-over-the-wire, no translation layer between the model and the pixels.

Rendered directly in a safe sandbox

Artifacts mount in a sandboxed iframe with sanitized HTML. Scripts can be enabled for trusted embeds and final-page interactions while the stream still paints safely first.

Safe render-viewing = a lighter client

Each frame is balanced once by the predictive parser and patched into the live iframe in place — no re-mounting React trees per token, no virtual-DOM diffing of streamed markup. Far less main-thread work.

Your frontend never hangs

Parsing is incremental (O(n)), paints are throttled to animation frames, and the iframe is never reloaded mid-stream. The UI builds up smoothly while the main thread stays free to scroll, type, and click.

Server + client

Two short files. That's the whole integration.

Wrap a Vercel AI SDK model on the server, render the stream on the client. The parser, sanitizer, SSE protocol and iframe runtime are all handled for you.

route.ts — server
// app/api/chat/route.ts
import { createGoogleGenerativeAI } from "@ai-sdk/google";
import { generateText, streamText } from "ai";
import { createArtifactStreamResponse } from "netra-artifacts/server";

export const dynamic = "force-dynamic";
const google = createGoogleGenerativeAI();

export async function POST(req: Request) {
  const { messages } = await req.json();
  const model = google("gemini-2.5-flash");

  // Streams markdown OR a sandboxed HTML artifact — automatically.
  return createArtifactStreamResponse({
    messages,
    generateTextStream: (args) =>
      streamText({ model, ...args }).textStream,
    generateText: async (args) =>
      (await generateText({ model, ...args })).text,
    mode: "auto",
  });
}
Chat.tsx — client
// components/Chat.tsx
"use client";
import { useArtifactStream, ArtifactMessage } from "netra-artifacts/client";

export function Chat() {
  const { messages, artifacts, sendMessage } = useArtifactStream({
    endpoint: "/api/chat",
  });

  return (
    <>
      {messages.map((m) => (
        <ArtifactMessage key={m.id} message={m} artifacts={artifacts} />
      ))}
      <button onClick={() => sendMessage("A pricing page for a SaaS")}>
        Generate UI
      </button>
    </>
  );
}

Streaming protocol

Raw deltas for truth. Snapshots for pixels.

artifact_delta carries the exact model output. artifact_snapshot is the parser-balanced, sanitized frame ready for the iframe. artifact_done is the final, authoritative document.

01
mode
02
message_start
03
message_delta
04
artifact_start
05
artifact_delta
06
artifact_snapshot
07
artifact_done
08
done

Built for AI apps that need safe, beautiful visual output.

Predictive HTML parser

Incomplete model output is projected into a valid document by predicting closing tags — the raw stream stays the source of truth.

Markdown or HTML, automatically

An auto classifier streams plain markdown when text suffices, or a rich HTML artifact when the answer deserves a visual.

Sandboxed artifacts

Every artifact renders in a sandboxed iframe. The body and CSS stream first; optional final scripts can enhance trusted embeds and interactions.

O(n) incremental streaming

One persistent parser feeds only new tokens; frame-throttled, in-place iframe patches mean the UI builds smoothly with no reload flash.

Copy, download & PDF

Each artifact card ships copy-HTML, download-HTML and native print-to-PDF — no extra dependencies.

Bring your own key

Google, Anthropic, OpenAI, DeepSeek and OpenRouter all work through the same SSE protocol and provider headers.

See partial HTML become a live UI.

Open the demo →