HTML 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.
HTML
/api/v1/tone
Keep the Sapling API key in your backend. This browser example calls an application-owned /api/tone route that proxies the request to Sapling.
<form id="tone-form">
<label for="content-editor">Text to analyze</label>
<textarea id="content-editor" sapling-ignore="true">
Really stoked about this! Will it be ready by next week?
</textarea>
<button type="submit">Check tone</button>
</form>
<pre id="results" aria-live="polite"></pre>
<script>
const form = document.getElementById('tone-form');
form.addEventListener('submit', async (event) => {
event.preventDefault();
const text = document.getElementById('content-editor').value;
const response = await fetch('/api/tone', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({text}),
});
if (!response.ok) {
throw new Error(`Tone request failed: ${response.status}`);
}
const data = await response.json();
document.getElementById('results').textContent = JSON.stringify(data, null, 2);
});
</script>
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 HTML
HTML, the HyperText Markup Language is used to design web pages to be rendered in browsers. Typically it is combined with CSS for styling and presentation and JavaScript for dynamic functionality.