Sapling Logo
Tone API quickstart

Python Tone Checker

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

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

Python 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.
Python /api/v1/tone
import os
from pprint import pprint

import requests

api_key = os.environ.get("SAPLING_API_KEY")
if not api_key:
    raise RuntimeError("Set SAPLING_API_KEY first.")

response = requests.post(
    "https://api.sapling.ai/api/v1/tone",
    headers={"Authorization": f"Bearer {api_key}"},
    json={
        "text": "Really stoked about this! Will it be ready by next week?",
    },
    timeout=30,
)
response.raise_for_status()
pprint(response.json())
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 Python

Python is a high-level interpreted general-purpose scripting language that ranks as one of the most popular programming languages. It is designed to be readable and uses indentation as part of its syntax. The reference implementation, CPython is written in both C and Python, which provides the performance characteristics of C for computationally expensive number-crunching tasks.