Rust 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.
Rust
/api/v1/tone
This example uses reqwest with its blocking and json features.
use reqwest::blocking::Client;
use serde_json::json;
use std::{env, error::Error};
fn main() -> Result<(), Box<dyn Error>> {
let api_key = env::var("SAPLING_API_KEY")?;
let response = Client::new()
.post("https://api.sapling.ai/api/v1/tone")
.bearer_auth(api_key)
.json(&json!({
"text": "Really stoked about this! Will it be ready by next week?"
}))
.send()?
.error_for_status()?
.text()?;
println!("{response}");
Ok(())
}
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 Rust
Rust is a programming language designed with comparable performance to C or C++, but with additional emphasis on code safety. Rust compilers do additional object reference and thread safety checks to prevent references to invalid memory or concurrency issues.