Napcar

Examples

Common Napcar integration patterns — detection, streaming UI, structured extraction, and embeddings.

Feature-detect and fall back

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

if (!isNapcar()) {
  showInstallBanner(); // degrade gracefully — never crash
}
const client = createClient();

Streaming into the UI

const session = await client.requestSession({ task: "chat", localOnly: true });
const output = document.querySelector("#out");
for await (const chunk of session.generateStreaming({ input: prompt })) {
  output.textContent += chunk;
}

Structured extraction

const { text } = await session.generate({
  input: invoiceText,
  responseFormat: {
    type: "json_schema",
    schema: {
      type: "object",
      properties: { vendor: { type: "string" }, total: { type: "number" } },
      required: ["vendor", "total"],
    },
  },
});
const invoice = JSON.parse(text);
const { embeddings } = await client.embed({ input: docs });
// build a local vector index — nothing leaves the machine

OpenAI-compatible client

const res = await fetch("https://local.napcar.ai/v1/chat/completions", {
  method: "POST",
  headers: { "Content-Type": "application/json", "X-Napcar-LLM-Handoff": "optional" },
  body: JSON.stringify({ model: "napcar-default", messages, stream: true }),
});