Ruby SDK
santati is the official Ruby client for the Santati audit-log API, published on RubyGems. Requires Ruby 3.2+.
Install
gem install santati
or, in a Gemfile:
gem "santati"
Create a client
require "santati"
client = Santati::Client.new(api_key: ENV.fetch("SANTATI_API_KEY"), trail: "billing")
| option | default | meaning |
|---|---|---|
api_key | required, non-empty | team API key (sat_sk_…) |
base_url | https://api.santati.io | trailing / removed; may carry a path prefix |
trail | none | default trail for emits; never applied to reads |
timeout_ms | 10000 | per attempt |
max_retries | 2 | retries after the first attempt |
initial_backoff_ms | 250 | backoff base |
max_backoff_ms | 8000 | backoff cap |
headers | none | extra headers on every request |
trail is the default trail for emits and is never applied to reads. Construction fails with a Santati::ValidationError (with status nil) for an empty key or an Authorization header in headers. Redirects are never followed, so the key is never replayed to another host.
Emit an event
result = client.events.emit(
event: "invoice.voided",
organization_id: "org_acme",
actor: {type: "user", id: "usr_123", name: "Valentine Michael Smith"},
targets: [{type: "invoice", id: "inv_555"}]
)
puts "#{result.event.id} #{result.duplicate}"
Without an idempotency_key one is generated — a UUIDv4 — and duplicate is true when the server replayed an earlier request. See Idempotency and Event envelope.
Emit a batch
batch = client.events.emit_batch([
{event: "invoice.voided", organization_id: "org_acme"},
{event: "invoice.paid", organization_id: "org_acme"}
])
puts batch.accepted
puts batch.rejected
A 202 and a 207 both return a result with per-item status (accepted, duplicate or rejected) in batch.results, and the server enforces 500 events / 1 MiB — a 413 arrives as a validation error. See Batching.
List and iterate
page = client.events.list(trail: "billing", event_prefix: "invoice.", limit: 50)
page.results.each { |event| puts "#{event.id} #{event.event}" }
p page.next_cursor
client.events.iterate(trail: "billing").each { |event| puts event.id }
list accepts 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 an Enumerator that walks every page lazily. See Searching events.
Errors and retries
Every failure raises a Santati::Error subclass:
| kind | when |
|---|---|
Santati::ValidationError | local validation (status is nil), or HTTP 400, 413, 422 |
Santati::AuthError | HTTP 401, 403 |
Santati::NotFoundError | HTTP 404 |
Santati::RateLimitedError | HTTP 429 |
Santati::ServerError | HTTP 5xx |
Santati::TransportError | no response: refused, DNS, TLS, timeout (status is nil) |
Santati::ApiError | any other status, an unexpected 2xx, or an undecodable body |
Each carries status, code, field, retry_after and message.
begin
client.events.emit(event: "invoice.voided", organization_id: "org_acme")
rescue Santati::RateLimitedError => e
sleep(e.retry_after) if e.retry_after
retry
rescue Santati::Error => e
warn e.message
end
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 max_backoff_ms, in which case the error is raised immediately. Redirects are never followed. See Errors and Rate limits.