Sapling Logo
Tone API quickstart

C Tone Checker

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

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

C tone checker quickstart

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

No language-specific SDK is required. The example uses a standard or commonly used HTTP client to call Sapling's JSON API.
C /api/v1/tone

C has no standard HTTP client, so this example uses libcurl.

#include <curl/curl.h>
#include <stdio.h>
#include <stdlib.h>

int main(void) {
  const char *api_key = getenv("SAPLING_API_KEY");
  if (api_key == NULL) {
    fputs("Set SAPLING_API_KEY first.\n", stderr);
    return 1;
  }

  CURL *curl = curl_easy_init();
  if (curl == NULL) {
    return 1;
  }

  char authorization[512];
  snprintf(authorization, sizeof(authorization), "Authorization: Bearer %s", api_key);

  struct curl_slist *headers = NULL;
  headers = curl_slist_append(headers, authorization);
  headers = curl_slist_append(headers, "Content-Type: application/json");

  const char *payload =
      "{\"text\":\"Really stoked about this! Will it be ready by next week?\"}";

  curl_easy_setopt(curl, CURLOPT_URL, "https://api.sapling.ai/api/v1/tone");
  curl_easy_setopt(curl, CURLOPT_POST, 1L);
  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payload);

  CURLcode result = curl_easy_perform(curl);
  long status = 0;
  curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status);

  curl_slist_free_all(headers);
  curl_easy_cleanup(curl);

  if (result != CURLE_OK || status < 200 || status >= 300) {
    fprintf(stderr, "Request failed: %s (HTTP %ld)\n", curl_easy_strerror(result), status);
    return 1;
  }
  return 0;
}
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 C

The programming language C is well known for its performance and widespread usage across all platforms and systems for multiple decades.