Skip to main content

Elixir SDK

santati is the official Elixir client for the Santati audit-log API, published on Hex. Requires Elixir 1.18+.

Install​

{:santati, "~> 0.1"}

Add it to deps/0 in mix.exs, then run mix deps.get.

Create a client​

{:ok, client} =
Santati.new(
api_key: System.fetch_env!("SANTATI_API_KEY"),
trail: "billing"
)
optiondefaultmeaning
api_keyrequired, non-emptyteam API key (sat_sk_…)
base_urlhttps://api.santati.iotrailing / removed; may carry a path prefix
trailnonedefault trail for emits; never applied to reads
timeout_ms10000per attempt
max_retries2retries after the first attempt
initial_backoff_ms250backoff base
max_backoff_ms8000backoff cap
headersnoneextra headers on every request

trail is the default trail for emits and is never applied to reads. Santati.new/1 answers {:error, %Santati.ValidationError{}} for an empty key (field api_key) or an authorization header in headers (field headers).

Emit an event​

{:ok, result} =
Santati.Events.emit(client, %{
event: "invoice.voided",
organization_id: "org_acme",
actor: %{type: "user", id: "usr_123", name: "Valentine Michael Smith"},
targets: [%{type: "invoice", id: "inv_555"}]
})

IO.puts("#{result.event.id} #{result.duplicate}")

Without an idempotency_key one is generated — a UUIDv4 — reused verbatim by every retry, so a retry can never index the event twice. A replay answers with duplicate: true. See Idempotency and Event envelope.

Emit a batch​

{:ok, batch} =
Santati.Events.emit_batch(client, [
%{event: "invoice.voided", organization_id: "org_acme"},
%{event: "invoice.paid", organization_id: "org_acme"}
])

IO.puts("#{batch.accepted} #{batch.rejected}")
IO.inspect(batch.results)

A 202 and a 207 both answer {:ok, batch} 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​

{:ok, page} =
Santati.Events.list(client,
trail: "billing",
created_after: "2026-09-01T00:00:00+00:00",
limit: 50
)

IO.inspect(page.results)
IO.inspect(page.next_cursor)

client
|> Santati.Events.stream(trail: "billing", limit: 500)
|> Stream.map(& &1.event)
|> Enum.take(10)
|> IO.inspect()

list/2 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. stream/2 walks every page lazily and raises the failing page's error. See Searching events.

Errors and retries​

Santati.new/1, Santati.Events.emit/2, emit_batch/2 and list/2 answer {:ok, result} or {:error, exception}:

kindwhen
Santati.ValidationErrorlocal validation (status is nil), or HTTP 400, 413, 422
Santati.AuthErrorHTTP 401, 403
Santati.NotFoundErrorHTTP 404
Santati.RateLimitedErrorHTTP 429
Santati.ServerErrorHTTP 5xx
Santati.TransportErrorno response: refused, DNS, TLS, timeout (status is nil)
Santati.ApiErrorany other status, an unexpected 2xx, or an undecodable 2xx body

Each carries status, code, field, retry_after and message.

case Santati.Events.emit(client, %{event: "invoice.voided", organization_id: "org_acme"}) do
{:ok, result} -> result.event.id
{:error, %Santati.ValidationError{field: field}} -> {:invalid, field}
{:error, %Santati.AuthError{}} -> :unauthorized
{:error, %Santati.RateLimitedError{retry_after: seconds}} -> {:wait, seconds}
{:error, error} -> {:failed, Exception.message(error)}
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.