Sapling Logo
AI detector quickstart

JavaScript AI Detector

Analyze text from a JavaScript application and receive document- and sentence-level AI detection scores.

  • HTTPS POST
  • SDK + HTTP
  • API key required
POST JavaScript logo JavaScript /api/v1/aidetect

JavaScript AI detector quickstart

Send at least 150 characters for a more reliable signal. The response score ranges from 0 (more likely human-written) to 1 (more likely AI-generated); use it as evidence, not proof.

Sapling provides an SDK for this stack. The direct HTTP example below remains useful for server-side integrations; see the SDK overview for the higher-level client.
JavaScript /api/v1/aidetect

Node.js 18+ includes fetch. Keep the API key in an environment variable rather than browser code.

async function detectAi(text) {
  const apiKey = process.env.SAPLING_API_KEY;
  if (!apiKey) {
    throw new Error('Set SAPLING_API_KEY before running this example.');
  }

  const response = await fetch('https://api.sapling.ai/api/v1/aidetect', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${apiKey}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({text, sent_scores: true}),
  });

  if (!response.ok) {
    throw new Error(`Sapling API error ${response.status}: ${await response.text()}`);
  }

  return response.json();
}

detectAi(
  'I am an artificial intelligence system designed to help people solve complex problems. ' +
  'My capabilities include natural language processing, machine learning, and predictive analytics.',
)
  .then((result) => console.log(JSON.stringify(result, null, 2)))
  .catch(console.error);
Example response application/json
{
  "score": 0.9989,
  "sentence_scores": [
    {
      "score": 0.9764,
      "sentence": "I am an artificial intelligence system designed to help people solve complex problems."
    },
    {
      "score": 0.9812,
      "sentence": "My capabilities include natural language processing, machine learning, and predictive analytics."
    }
  ],
  "text": "I am an artificial intelligence system designed to help people solve complex problems. My capabilities include natural language processing, machine learning, and predictive analytics."
}

The overall score and sentence scores use different methods and may not match exactly. Choose thresholds based on the false-positive and false-negative costs of your use case.

About JavaScript

JavaScript is a scripting language used in browsers to provide client-side dynamic application behavior. Almost all websites use it. Additionally, JavaScript is also used in server-side applications through environments like Node.js. Cross-platform and desktop applications can be developed using the Electron framework.