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);
}

Local in Napcar, your cloud provider elsewhere

Pass a cloud provider and the SDK keeps one call site: it runs the local model in Napcar and routes to your chosen cloud provider (OpenAI by default, or any OpenAI-compatible API) in every other browser. The one-shot prompt() helper makes this a single call:

import { prompt } from "@napcar/sdk";

// In Napcar -> local model. Anywhere else -> OpenAI with your key.
const answer = await prompt("In one sentence, what is a napcar?", {
  cloud: { provider: "openai", apiKey: process.env.OPENAI_API_KEY },
});

Supported presets: openai, openrouter, groq, together, mistral, deepseek, ollama (local, no key), and custom (baseUrl + model). Each is just an OpenAI-compatible endpoint, so streaming, structured output, and embeddings all work unchanged. The cloud config is ignored inside Napcar — generation stays local there.