Dart 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.
Add the http package to pubspec.yaml before running this example.
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
Future<void> main() async {
final apiKey = Platform.environment['SAPLING_API_KEY'];
if (apiKey == null || apiKey.isEmpty) {
throw StateError('Set SAPLING_API_KEY first.');
}
final response = await http.post(
Uri.parse('https://api.sapling.ai/api/v1/aidetect'),
headers: {
HttpHeaders.authorizationHeader: 'Bearer $apiKey',
HttpHeaders.contentTypeHeader: 'application/json',
},
body: jsonEncode({
'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,
}),
);
if (response.statusCode < 200 || response.statusCode >= 300) {
throw HttpException(
'Sapling API error ${response.statusCode}: ${response.body}',
);
}
print(const JsonEncoder.withIndent(' ').convert(jsonDecode(response.body)));
}
{
"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 Dart
Dart is a programing language developed by Google. Applications in Dart are compiled to native code or JavaScript for cross-platform use on server, web, desktop and mobile applications. This is the language used by the cross-platform application framework Flutter.