> ## Documentation Index
> Fetch the complete documentation index at: https://docs.auditrails.io/llms.txt
> Use this file to discover all available pages before exploring further.

# AuditRails SDK Overview — Client Libraries & Packages

> Official AuditRails SDKs for Node.js, Python, Go, Java, and PHP. Automatic batching, exponential-backoff retries, and graceful shutdown built in.

AuditRails provides first-party client libraries for every major backend language. Each SDK shares the same core design: a fire-and-forget `log()` method that never throws, automatic batching and background flushing, exponential-backoff retries on server errors, and a graceful shutdown path that ensures no events are lost when your process exits. Pick your language below to get started in minutes.

## Available SDKs

<CardGroup cols={2}>
  <Card title="Node.js / TypeScript" icon="node-js" href="/sdks/node">
    Install via npm. Requires Node 18+ for native `fetch`. Zero runtime dependencies.
  </Card>

  <Card title="Python" icon="python" href="/sdks/python">
    Install via pip. Sync client uses `urllib` (zero deps); async client adds `httpx`.
  </Card>

  <Card title="Go" icon="golang" href="/sdks/go">
    Install via `go get`. Uses only the standard `net/http` package. Zero dependencies.
  </Card>

  <Card title="Java" icon="java" href="/sdks/java">
    Available on Maven Central. Uses `HttpURLConnection`. Zero dependencies.
  </Card>

  <Card title="PHP" icon="php" href="/sdks/php">
    Install via Composer. PSR-18 compatible — works with Guzzle or any PSR-18 HTTP client.
  </Card>
</CardGroup>

## Package references

| Language             | Package                         | Install command                              | Repository                                                                                 |
| -------------------- | ------------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------ |
| Node.js / TypeScript | `@auditrails/node`              | `npm install @auditrails/node`               | [github.com/auditrails/auditrails-node](https://github.com/auditrails/auditrails-node)     |
| Python               | `auditrails`                    | `pip install auditrails`                     | [github.com/auditrails/auditrails-python](https://github.com/auditrails/auditrails-python) |
| Go                   | `auditrails-go`                 | `go get github.com/auditrails/auditrails-go` | [github.com/auditrails/auditrails-go](https://github.com/auditrails/auditrails-go)         |
| Java                 | `io.auditrails:auditrails-java` | Maven / Gradle (see Java docs)               | [github.com/auditrails/auditrails-java](https://github.com/auditrails/auditrails-java)     |
| PHP                  | `auditrails/auditrails-php`     | `composer require auditrails/auditrails-php` | [github.com/auditrails/auditrails-php](https://github.com/auditrails/auditrails-php)       |

## Shared behavior

All SDKs implement the same reliability guarantees regardless of language.

| Behavior                        | Detail                                                                                                                                                                                                                                                        |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Non-throwing `log()`**        | The buffered `log()` method never throws or raises an exception. Errors are handled internally and, if a logger is configured, emitted there instead.                                                                                                         |
| **Automatic batching**          | Events are buffered in memory and sent in batches of up to 100. The buffer is flushed automatically every second.                                                                                                                                             |
| **Exponential-backoff retries** | On any `5xx` response the SDK retries up to 3 times with delays of 200 ms → 400 ms → 800 ms before discarding the batch.                                                                                                                                      |
| **Graceful shutdown**           | Each SDK registers a process-exit hook (`beforeExit`/`SIGTERM` in Node, `atexit` in Python, `defer client.Close()` in Go, `AutoCloseable` in Java, `register_shutdown_function` in PHP) to flush any remaining buffered events before the process terminates. |
| **Minimal dependencies**        | Node uses native `fetch`, Python uses `urllib`, Go uses `net/http`, Java uses `HttpURLConnection`, and PHP requires a PSR-18 HTTP client (e.g. Guzzle).                                                                                                       |

## Configuration options

Every SDK accepts the same set of configuration options, mapped to the naming convention of each language.

| Option          | Default                     | Description                                                                           |
| --------------- | --------------------------- | ------------------------------------------------------------------------------------- |
| `apiKey`        | *(required)*                | Your AuditRails API key. Obtain this from the [dashboard](https://app.auditrails.io). |
| `baseUrl`       | `https://api.auditrails.io` | Override the API endpoint (useful for proxies or private deployments).                |
| `batchSize`     | `100`                       | Maximum number of events to include in a single HTTP request.                         |
| `flushInterval` | `1 second`                  | How often the internal buffer is flushed to the API.                                  |
| `maxRetries`    | `3`                         | Number of retry attempts on `5xx` errors before a batch is discarded.                 |
| `timeout`       | `10 seconds`                | Per-request HTTP timeout.                                                             |

## Available methods

All SDKs expose the same four core methods.

| Method                   | Behavior                                                                                                                                           |
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `log(event)`             | Adds an event to the in-memory buffer. Returns immediately. **Never throws.** The event is sent in the background as part of the next batch flush. |
| `logDirect(event)`       | Sends a single event immediately, bypassing the buffer. Returns the API response (including the `logId`). **Throws on error.**                     |
| `logBatchDirect(events)` | Sends an array of events immediately in a single request, bypassing the buffer. **Throws on error.**                                               |
| `flush()`                | Manually triggers a flush of all currently buffered events. Useful before a planned shutdown or at the end of a request lifecycle.                 |
| `close()`                | Flushes all buffered events and shuts down background workers. Call this during application teardown.                                              |
