Dart 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.
Dart
/api/v1/tone
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/tone'),
headers: {
HttpHeaders.authorizationHeader: 'Bearer $apiKey',
HttpHeaders.contentTypeHeader: 'application/json',
},
body: jsonEncode({
'text': 'Really stoked about this! Will it be ready by next week?',
}),
);
if (response.statusCode < 200 || response.statusCode >= 300) {
throw HttpException(
'Sapling API error ${response.statusCode}: ${response.body}',
);
}
print(const JsonEncoder.withIndent(' ').convert(jsonDecode(response.body)));
}
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 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.