Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.fact0.io/llms.txt

Use this file to discover all available pages before exploring further.

Next.js

Fact0 runs server-side — use @fact0/sdk from App Router route handlers, server actions, or Edge / Node middleware.

Install

npm install @fact0/sdk

Route handler

// app/api/invoice/[id]/approve/route.ts
import { Fact0Client } from "@fact0/sdk";

const lf = new Fact0Client({ apiKey: process.env.FACT0_API_KEY! });

export async function POST(
  req: Request,
  { params }: { params: { id: string } },
) {
  const user = await getSession(req);

  await lf.audit.log({
    actor: { id: user.id, type: "human", email: user.email },
    action: "invoice.approve",
    resource: { id: params.id, type: "invoice" },
    outcome: "success",
  });

  return Response.json({ ok: true });
}

Server action

"use server";
import { Fact0Client } from "@fact0/sdk";

const lf = new Fact0Client({ apiKey: process.env.FACT0_API_KEY! });

export async function deleteDocument(id: string) {
  await lf.audit.log({
    actor: { id: "user_123", type: "human" },
    action: "document.delete",
    resource: { id, type: "document" },
    outcome: "success",
  });
}
Keep FACT0_API_KEY server-only. Use it from route handlers, server actions, middleware, or Vercel Functions — never from React Client Components.