PHP 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.
PHP
/api/v1/aidetect
This example uses PHP's cURL extension.
<?php
$apiKey = getenv('SAPLING_API_KEY');
if (!$apiKey) {
throw new RuntimeException('Set SAPLING_API_KEY first.');
}
$payload = json_encode([
'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,
], JSON_THROW_ON_ERROR);
$request = curl_init('https://api.sapling.ai/api/v1/aidetect');
curl_setopt_array($request, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
],
CURLOPT_RETURNTRANSFER => true,
]);
$body = curl_exec($request);
if ($body === false) {
throw new RuntimeException(curl_error($request));
}
$status = curl_getinfo($request, CURLINFO_RESPONSE_CODE);
curl_close($request);
if ($status < 200 || $status >= 300) {
throw new RuntimeException("Sapling API error {$status}: {$body}");
}
echo $body;
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 PHP
PHP is a popular scripting language for the web. It is typically processed on a web server as a module, daemon or CGI executable. Many popular web services are written in PHP including well-known websites such as Facebook and frameworks like Wordpress.