PHP SDK
santati/santati-php is the official PHP client for the Santati audit-log API, published on Packagist. Requires PHP 8.2+ (Guzzle).
Install
composer require santati/santati-php
Create a client
require 'vendor/autoload.php';
use Santati\Client;
$client = new Client(apiKey: getenv('SANTATI_API_KEY'), trail: 'billing');
| option | default | meaning |
|---|---|---|
apiKey | required, non-empty | team API key (sat_sk_…) |
baseUrl | https://api.santati.io | a trailing slash is dropped; a path prefix is kept |
trail | none | default trail for emits, never applied to reads |
timeoutMs | 10000 | per attempt |
maxRetries | 2 | retries after the first attempt |
initialBackoffMs | 250 | backoff base |
maxBackoffMs | 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 ValidationException for an empty key or an Authorization header in headers.
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']],
]);
printf("%s (duplicate: %s)\n", $result->event->getId(), $result->duplicate ? 'yes' : 'no');
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
$batch = $client->events->emitBatch([
['event' => 'invoice.voided', 'idempotency_key' => 'void-1', 'organization_id' => 'org_acme'],
['event' => 'invoice.paid', 'organization_id' => 'org_acme'],
]);
printf("%d accepted, %d rejected\n", $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 = $client->events->list(['trail' => 'billing', 'limit' => 50]);
foreach ($page->results as $event) {
printf("%s %s\n", $event->getId(), $event->getEvent());
}
foreach ($client->events->iterate(['trail' => 'billing', 'limit' => 200]) as $event) {
printf("%s %s\n", $event->getId(), $event->getEvent());
}
list() accepts trail, event, event_prefix, organization_id, actor_id, actor_type, target_type, target_id, created_after, created_before, q, sort, limit and cursor as [$name => $value]; unknown names raise a ValidationException. iterate() returns a \Generator and walks every page lazily. See Searching events.
Errors and retries
Every failure is a Santati\Exception\SantatiException with getStatus(), getErrorCode(), getField() and getRetryAfter():
| kind | when |
|---|---|
ValidationException | local validation (getStatus() is null), or HTTP 400, 413, 422 |
AuthException | HTTP 401, 403 |
NotFoundException | HTTP 404 |
RateLimitedException | HTTP 429 |
ServerException | HTTP 5xx |
TransportException | no response: refused, DNS, TLS, timeout (getStatus() is null) |
ApiException | any other status, an unexpected 2xx, or an undecodable body |
use Santati\Exception\RateLimitedException;
try {
$client->events->emit(['event' => 'invoice.voided', 'organization_id' => 'org_acme']);
} catch (RateLimitedException $e) {
echo $e->getRetryAfter(); // seconds, from the Retry-After header — or null
}
An emit, a batch and a list retry transport failures, 500/502/503/504 and 429 (unless the code is quota_exceeded) up to maxRetries times, re-sending the identical request with the same idempotency keys. A Retry-After header is honoured unless it exceeds maxBackoffMs, in which case the error is raised immediately. Redirects are never followed. See Errors and Rate limits.