C 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.
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/aidetect
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\":\"I am an artificial intelligence system designed to help people solve complex problems. "
"My capabilities include natural language processing, machine learning, and predictive analytics.\","
"\"sent_scores\":true}";
curl_easy_setopt(curl, CURLOPT_URL, "https://api.sapling.ai/api/v1/aidetect");
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
{
"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 C
The programming language C is well known for its performance and widespread usage across all platforms and systems for multiple decades.