Skip to content

Getting Started: Node.js

Use Node.js (18+) to call the BetterPrompt API.

javascript
// Node.js quickstart (Node 18+)
const API_KEY = process.env.BETTERPROMPT_API_KEY || "YOUR_API_KEY";
const PROMPT_VERSION_ID =
  process.env.BP_PROMPT_VERSION_ID || "YOUR_PROMPT_VERSION_ID";

async function main() {
  const res = await fetch("https://api.betterprompt.me/v1/runs", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      promptVersionId: PROMPT_VERSION_ID,
      inputs: { textInputs: { yourField: "value" } },
    }),
  });

  const json = await res.json();
  console.log(json);
}

main().catch(console.error);