Go SDK
github.com/jamescarr/santati-sdks/go is the official Go client for the Santati audit-log API. Requires Go 1.25+.
Install
go get github.com/jamescarr/santati-sdks/go
Create a client
client, err := santati.NewClient(os.Getenv("SANTATI_API_KEY"), santati.WithTrail("billing"))
if err != nil {
log.Fatal(err)
}
| option | default | meaning |
|---|---|---|
apiKey (first argument) | required, non-empty | team API key (sat_sk_…) |
WithBaseURL | https://api.santati.io | trailing / removed; may carry a path prefix |
WithTrail | none | default trail for emits; never applied to reads |
WithTimeout | 10s | per attempt |
WithMaxRetries | 2 | retries after the first attempt |
WithBackoff | 250ms, 8s | exponential backoff bounds |
WithHeader | none | extra header on every request |
WithTrail sets the default trail for emits and is never applied to reads. NewClient returns a *santati.Error for an empty API key or an Authorization header passed through WithHeader.
Emit an event
result, err := client.Events.Emit(context.Background(), santati.EventInput{
Event: "invoice.voided",
OrganizationID: "org_acme",
Actor: &santati.ActorInput{Type: "user", ID: "usr_123", Name: "Valentine Michael Smith"},
Targets: []santati.TargetInput{{Type: "invoice", ID: "inv_555"}},
})
if err != nil {
log.Fatal(err)
}
fmt.Println(result.Event.Id, result.Duplicate)
Without an IdempotencyKey one is generated for you, and Duplicate is true when the server replayed an earlier request. See Idempotency and Event envelope.
Emit a batch
batch, err := client.Events.EmitBatch(context.Background(), []santati.EventInput{
{Event: "invoice.paid", OrganizationID: "org_acme"},
{Event: "invoice.voided", OrganizationID: "org_acme"},
})
if err != nil {
log.Fatal(err)
}
fmt.Println(batch.Accepted, 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, err := client.Events.List(context.Background(), santati.ListParams{Trail: "billing", Limit: 50})
if err != nil {
log.Fatal(err)
}
for _, event := range page.Results {
fmt.Println(event.Id, event.Event)
}
for event, err := range client.Events.Iterate(context.Background(), santati.ListParams{Trail: "billing"}) {
if err != nil {
log.Fatal(err)
}
fmt.Println(event.Id)
}
ListParams fields: Trail, Event, EventPrefix, OrganizationID, ActorID, ActorType, TargetType, TargetID, CreatedAfter, CreatedBefore, Q, Sort and Limit, plus Cursor on List only. Iterate returns an iter.Seq2[*AuditEvent, error] you range over. See Searching events.
Errors and retries
Every failure is a *santati.Error with Kind, Status (0 when there was no response), Code, Field, RetryAfter (*int) and Message:
| kind | when |
|---|---|
KindValidation | local validation (Status is 0), or HTTP 400, 413, 422 |
KindAuth | HTTP 401, 403 |
KindNotFound | HTTP 404 |
KindRateLimited | HTTP 429 |
KindServer | HTTP 5xx |
KindTransport | no response: refused, DNS, TLS, timeout (Status is 0) |
KindAPI | any other status, an unexpected 2xx, or an undecodable body |
_, err := client.Events.Emit(context.Background(), santati.EventInput{
Event: "invoice.voided",
OrganizationID: "org_acme",
})
if err != nil {
var apiErr *santati.Error
if errors.As(err, &apiErr) && apiErr.Kind == santati.KindRateLimited && apiErr.RetryAfter != nil {
fmt.Printf("retry after %d seconds\n", *apiErr.RetryAfter)
}
}
An emit, a batch and a list retry transport failures, 500/502/503/504 and 429 (unless the code is quota_exceeded) up to WithMaxRetries times, re-sending the identical request with the same idempotency keys. A Retry-After header is honoured unless it exceeds the WithBackoff cap, in which case the error is raised immediately. Redirects are never followed. See Errors and Rate limits.