Skip to main content

Rust SDK

santati is the official Rust client for the Santati audit-log API, published on crates.io — async, running on Tokio. Requires Rust 1.85+.

Install​

cargo add santati
cargo add tokio --features macros,rt-multi-thread

Create a client​

let client = Santati::builder(std::env::var("SANTATI_API_KEY").expect("SANTATI_API_KEY is not set"))
.trail("billing")
.build()?;
optiondefaultmeaning
api_keyrequired, non-emptyteam API key (sat_sk_…); sent as Authorization: Api-Key <key>
base_urlhttps://api.santati.iotrailing / removed; may carry a path prefix
trailnonedefault trail for emits; never applied to reads
timeout10sper attempt
max_retries2retries after the first attempt
backoff(initial, max)250ms, 8sexponential backoff bounds
header(name, value)noneextra header on every request

trail is the default trail for emits and is never applied to reads. Building fails with a ValidationError (status None) for an empty api_key (field api_key) or an Authorization header (field headers).

Emit an event​

let result = client
.events()
.emit(EventInput {
event: "invoice.voided".into(),
organization_id: Some("org_acme".into()),
actor: Some(ActorInput {
r#type: "user".into(),
id: Some("usr_123".into()),
name: Some("Valentine Michael Smith".into()),
..Default::default()
}),
targets: Some(vec![TargetInput {
r#type: "invoice".into(),
id: "inv_555".into(),
..Default::default()
}]),
..Default::default()
})
.await?;
println!("{} (duplicate: {})", result.event.id, result.duplicate);

Without an idempotency_key one is generated for you, and duplicate is true when the server replayed an earlier request. See Idempotency and Event envelope.

Emit a batch​

let batch = client
.events()
.emit_batch(vec![
EventInput {
event: "invoice.paid".into(),
organization_id: Some("org_acme".into()),
..Default::default()
},
EventInput {
event: "invoice.voided".into(),
organization_id: Some("org_acme".into()),
..Default::default()
},
])
.await?;
println!("{} accepted, {} rejected", batch.accepted, batch.rejected);

A 202 and a 207 both return a BatchResult whose rejected items carry the server's error — not a failure of the call. The server enforces 500 events / 1 MiB; a 413 arrives as a validation error. See Batching.

List and iterate​

use santati::StreamExt;

let page = client
.events()
.list(ListParams {
trail: Some("billing".into()),
limit: Some(50),
..Default::default()
})
.await?;
println!("{} events, next cursor: {:?}", page.results.len(), page.next_cursor);

let mut all = std::pin::pin!(client.events().iterate(ListParams {
trail: Some("billing".into()),
..Default::default()
}));
while let Some(event) = all.next().await {
println!("{}", event?.event);
}

ListParams fields: trail, event, event_prefix, organization_id, actor_id, actor_type, target_type, target_id, created_after, created_before, q, sort and limit, plus cursor on list only. iterate returns a !Unpin stream — pin it with std::pin::pin! and import santati::StreamExt. See Searching events.

Errors and retries​

One santati::Error enum with seven kinds; error.kind() returns the ErrorKind, and status(), code(), field(), retry_after() and message() carry the details:

kindwhen
ErrorKind::Validationlocal validation (status is None), or HTTP 400, 413, 422
ErrorKind::AuthHTTP 401, 403
ErrorKind::NotFoundHTTP 404
ErrorKind::RateLimitedHTTP 429
ErrorKind::ServerHTTP 5xx
ErrorKind::Transportno response: refused, DNS, TLS, timeout (status is None)
ErrorKind::Apiany other status, an unexpected 2xx, or an undecodable body
use santati::ErrorKind;

match client.events().list(Default::default()).await {
Err(error) if error.kind() == ErrorKind::RateLimited => {
eprintln!("slow down, retry after {:?}s", error.retry_after());
}
Err(error) => eprintln!("{}: {}", error.kind(), error.message()),
Ok(page) => println!("{} events", page.results.len()),
}

An emit, a batch and a list retry transport failures, 500/502/503/504 and 429 (unless the code is quota_exceeded) up to max_retries times, re-sending the identical request with the same idempotency keys. A Retry-After header is honoured unless it exceeds the backoff cap, in which case the error is raised immediately. Redirects are never followed. See Errors and Rate limits.