Brinpage

Brinpage Platform — Quick Start (Node.js)

Minimal server-side Node.js integration calling Brinpage Platform directly via HTTP. No SDK, no special tooling — just env vars + a tiny client.

Requirements

  • Node 18+ (native fetch)
  • A Brinpage Platform account + license key

1) Add environment variables

Set these in your hosting environment (or your framework’s .env system).

.env
# Required (server-side only)
BRINPAGE_LICENSE_KEY="bp_xxxx"

# Optional
BRINPAGE_API_BASE="https://platform.brinpage.com"
BRINPAGE_TIMEOUT_MS=30000

Don’t have access yet? Create a Platform account and generate your license key.

Get your license key

Important: never expose BRINPAGE_LICENSE_KEY in browser code. Keep it server-side (Node backend only).

2) Add a tiny Brinpage HTTP client

Create a reusable client (framework-agnostic). Example below assumes a file like brinpage.mjs (ESM).

javascript
// brinpage.mjs (Node 18+)
const BASE_URL = (process.env.BRINPAGE_API_BASE || "https://platform.brinpage.com").replace(/\/$/, "");
const LICENSE = process.env.BRINPAGE_LICENSE_KEY || "";
const TIMEOUT_MS = Number(process.env.BRINPAGE_TIMEOUT_MS || 30000);

if (!LICENSE) throw new Error("Missing BRINPAGE_LICENSE_KEY");

export async function ask(question, options = {}) {
  const q = String(question || "").trim();
  if (!q) throw new Error("Missing 'question'");

  const controller = new AbortController();
  const t = setTimeout(() => controller.abort(), TIMEOUT_MS);

  try {
    const res = await fetch(`${BASE_URL}/api/sdk/ask`, {
      method: "POST",
      headers: {
        "Authorization": `Bearer ${LICENSE}`,
        "Content-Type": "application/json",
        "Accept": "application/json",
      },
      body: JSON.stringify({
        question: q,
        stream: false, // simple JSON response by default
        ...options,
      }),
      signal: controller.signal,
    });

    const text = await res.text();
    let data;
    try { data = JSON.parse(text); } catch { data = { error: text.slice(0, 500) }; }

    if (!res.ok) {
      throw new Error(data?.error || `ask failed (${res.status})`);
    }

    return data;
  } finally {
    clearTimeout(t);
  }
}

export function pickAnswer(res) {
  for (const k of ["answer", "text", "message", "output"]) {
    const v = res?.[k];
    if (typeof v === "string" && v.trim()) return v;
  }
  return "";
}

3) Create your own server endpoint

This keeps your license key private and gives your frontend a safe URL to call. Below is a minimal Express example: POST /api/chat.

bash
npm i express
javascript
// server.mjs
import express from "express";
import { ask, pickAnswer } from "./brinpage.mjs";

const app = express();
app.use(express.json());

app.post("/api/chat", async (req, res) => {
  try {
    const { question, tags } = req.body || {};
    const result = await ask(question, {
      tags: Array.isArray(tags) ? tags : [],
      k: 6,
      minScore: 0.18,
      debugEcho: false,
      // provider/model overrides (optional):
      // provider: "openai",
      // model: "gpt-4.1-mini",
    });

    res.json({ ok: true, answer: pickAnswer(result), raw: result });
  } catch (e) {
    res.status(500).json({ ok: false, error: e?.message || "unknown_error" });
  }
});

app.listen(3000, () => console.log("Listening on http://localhost:3000"));

Run it:

bash
node server.mjs

4) Test end-to-end

Once your endpoint is reachable, test it with curl:

bash
curl -X POST http://localhost:3000/api/chat \
  -H "Content-Type: application/json" \
  -d '{"question":"Hello from Node.js","tags":["docs"]}'

Common /ask options you’ll actually use

  • history: array of chat messages ({ role, content })
  • tags: reduce retrieval scope to specific doc tags
  • k / minScore: retrieval tuning knobs
  • debugEcho: include debug object (retrieval + routing info)
  • provider / model: overrides (optional)
  • stream: SSE mode (advanced; implement when you need token streaming)

Want to switch language/framework? Go back to Installation:

Back to Installation