Skip to content

Hello world: Rust

Ready — installs from the CloakAPI downloads page. Tested end to end on Linux x86-64.

Runs today on Linux x86-64. On macOS, Windows and ARM the on-device engine is not available yet; the SDK uses basic detection and shows a warning.

1. Get an API key

Create a key at app.cloakapi.io/api-keys. It starts with cloak_. Verify your email to unlock your trial balance.

2. Install

Set up the on-device engine and pin: Engine setup.

Terminal window
cargo new hello && cd hello
curl -fsSLO https://app.cloakapi.io/downloads/sdks/rust/cloakapi-rust-1.2.0-src.zip && unzip -q cloakapi-rust-1.2.0-src.zip
cargo add cloakapi --path ./rust && cargo add tokio --features macros,rt-multi-thread

3. Set your key

Terminal window
export CLOAKAPI_API_KEY="cloak_your_key_here"

4. Run hello world

hello.rs
use std::io::{self, Write};
use cloakapi::{Client, ClientConfig, Message, MessagesRequest};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
if std::env::var("CLOAKAPI_API_KEY").unwrap_or_default().is_empty() {
eprintln!("CLOAKAPI_API_KEY is not set. Create a key at https://app.cloakapi.io/api-keys");
std::process::exit(1);
}
let client = Client::new("", ClientConfig::default());
let reviewed = client.messages().review(MessagesRequest {
model: "claude-sonnet-4-6".into(),
messages: vec![Message {
role: "user".into(),
content: "Say hello to jane.doe@example.com in one short sentence.".into(),
}],
..Default::default()
})?;
println!("This exact request will leave your machine:\n\n{:#?}", reviewed.preview());
print!("\nSend it? [y/N] ");
io::stdout().flush()?;
let mut answer = String::new();
io::stdin().read_line(&mut answer)?;
if !answer.trim().eq_ignore_ascii_case("y") {
println!("Not sent. You declined the request.");
return Ok(());
}
let reply = client.messages().create(reviewed.approve()?).await?;
println!(
"\nReply (restored on your device):\n{}",
reply.first_text().unwrap_or("")
);
Ok(())
}
Terminal window
cp path/to/examples/hello.rs examples/hello.rs
cargo run --example hello

5. What you should see

You’ll see the exact request before it is sent. Your email address is replaced with a token like <<CLOAK:CONTACT_EM:3f9a1c>>. Type y. The reply comes back with the real address restored on your device. The reply text varies.

If something goes wrong

See the Rust SDK README for common messages and fixes.

What this does and does not do
  • Detection is best-effort. Emails, phone numbers, cards and similar are matched by rules; names use an on-device list and an optional on-device model, and may be missed.
  • You see the exact request before it is sent.
  • CloakAPI does not refuse a request because of what it contains. Errors come from your key, balance, usage limits, request format or size, or the model provider.
  • The gateway does not run detection on your content. It checks the request proof, then relays it to the model provider.

Last updated: