Sapling Logo
Tone API quickstart

JavaScript Tone Checker

Analyze overall and sentence-level tone from a JavaScript application across 28 fine-grained categories.

  • HTTPS POST
  • JSON HTTP API
  • Bearer API key
POST JavaScript logo JavaScript /api/v1/tone

JavaScript tone checker quickstart

Send text to the tone endpoint. The response ranks overall tones and returns a separate probability breakdown for every sentence.

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/tone

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

async function checkTone(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/tone', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${apiKey}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({text}),
  });

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

  return response.json();
}

checkTone('Really stoked about this! Will it be ready by next week?')
  .then((result) => console.log(JSON.stringify(result, null, 2)))
  .catch(console.error);
Example response application/json
{
  "overall": [
    [0.9247, "curious", "🤓"],
    [0.0455, "excited", "😀"],
    [0.0057, "confused", "😕"]
  ],
  "results": [
    [[0.9937, "excited", "😀"]],
    [[0.5469, "confused", "😕"], [0.3993, "curious", "🤓"]]
  ],
  "sents": [
    "Really stoked about this!",
    "Will it be ready by next week?"
  ]
}

Probabilities are returned in descending order as probability, tone, and emoji tuples. Use sentence results when a message contains mixed tones.

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.