Napcar

Quickstart

Detect Napcar, check availability, and generate text locally in a few lines.

This example detects Napcar, checks that local chat is available, and prints a single local generation. It does nothing in a non-Napcar browser.

<script type="module">
  async function main() {
    if (!navigator.napcar?.ai) {
      console.log("Napcar local AI is not available in this browser.");
      return;
    }

    const availability = await navigator.napcar.ai.availability({
      task: "chat",
      localOnly: true,
    });

    if (availability.status !== "available") {
      console.log("Local AI status:", availability);
      return;
    }

    const session = await navigator.napcar.ai.requestSession({
      task: "chat",
      localOnly: true,
    });

    const result = await session.generate({
      input: "Explain what Napcar does in one sentence.",
    });

    document.body.textContent = result.text;
  }

  main();
</script>

With the SDK

The SDK adds detection, typed errors, and a polyfill fallback:

import { createClient, isNapcar } from "@napcar/sdk";

const client = createClient(); // native in Napcar, polyfill elsewhere

const availability = await client.availability({ task: "chat", localOnly: true });
if (availability.status === "available") {
  const session = await client.requestSession({ task: "chat", localOnly: true });
  const { text } = await session.generate({ input: "Hello, local model." });
  console.log(text, "native:", client.isNative);
}

On this page