# SDK configuration

Every option of the Amiril SDK's init and every environment variable it reads, in Python and TypeScript, with its type, its default and what it does.

`init` starts the SDK once per process. Many options can also come from an environment variable, listed below. An `init` argument wins over its variable, and the variable wins over the default. An empty string counts as unset.

In TypeScript, `init` from `@amiril/sdk/node` reads the process's environment variables. The `init` from `@amiril/sdk` is for edge runtimes and reads no variables unless you pass them as `environ`.

Two names here are easy to confuse with an [Amiril environment](/traces/environments-and-keys). `environment` is only a label for where the process runs, and your API key decides the Amiril environment. `env` is a set of your own tags for rules to read.

## Environment variables [#environment-variables]

Several variables label your installation. An **installation** is one service at one deployed version, with its replicas counted as one. **Installations**, next to **Data** in the app's sidebar, lists them.

| Variable | Option | What it does |
| --- | --- | --- |
| `AMIRIL_API_KEY` | `api_key`, `apiKey` | The API key. With an endpoint, the SDK takes its rules from Amiril and sends its decisions there |
| `AMIRIL_ENDPOINT` | `endpoint` | The address the SDK fetches rules from and sends decisions to. In the app, open **Data** in the sidebar and select **Set up a new installation** to copy it. There is no default. A key without an endpoint makes no network request |
| `AMIRIL_RULES_FILE` | `rules_file`, `rulesFile` | A rules file. Without a key, rules come only from this file or the `rules` option. With a key it is the last fallback, used when Amiril has sent no rules and none are cached |
| `AMIRIL_ENVIRONMENT` | `environment` | A label for where this process runs, such as `staging`, shown as **Environment** on the installation's page |
| `AMIRIL_SERVICE` | `service` | The service name the installation is listed under |
| `AMIRIL_VERSION` | `version` | The deployed version, shown as **Deploy version** |
| `AMIRIL_COMMIT` | `commit` | The commit this process was built from |
| `AMIRIL_CACHE_DIR` | `cache_dir`, `cacheDir` | Where the last good rules and unsent decisions are kept on disk |
| `AMIRIL_DURABLE_PATH` | `durable` | A SQLite file that keeps [call history](#call-history) across restarts |

## Python init options [#python-init-options]

`amiril.init(rules=None, **options)` returns a handle with three methods.

- `flush()` sends queued decisions now.
- `report()` returns the mode, the rules in use and the agents and tools each adapter covers.
- `shutdown()` sends what is queued and stops contacting Amiril.

`init` raises `TypeError` for an option it does not know. Without a key, `init` also raises when it cannot read the rules file. The interface types in the table, such as `DecisionSink`, are defined in `amiril.seams`.

| Option | Type | Default | What it does |
| --- | --- | --- | --- |
| `rules` | `dict`, path or `BundleSource` | `None` | A rules document, or a path to one. Pass `rules` or `rules_file`, not both |
| `rules_file` | path | `AMIRIL_RULES_FILE` | A rules file |
| `mode` | `"enforce"`, `"shadow"`, `"off"` | `"enforce"` | `enforce` follows each rule's own mode. A rule starts in Shadow, so only a rule set to Enforce can block a call. `shadow` records what every rule would do and blocks nothing. `off` checks nothing and allows every call |
| `api_key` | `str` | `AMIRIL_API_KEY` | The API key |
| `endpoint` | `str` | `AMIRIL_ENDPOINT` | The SDK endpoint. See `AMIRIL_ENDPOINT` |
| `environment` | `str` | `AMIRIL_ENVIRONMENT` | A label for where this process runs. See `AMIRIL_ENVIRONMENT` |
| `service` | `str` | [Detected](#service-name-and-version) | The service name |
| `version` | `str` | [Detected](#service-name-and-version) | The deployed version |
| `commit` | `str` | [Detected](#service-name-and-version) | The commit |
| `cache_dir` | path | [Cache directory](#cache-directory) | Where the last good rules and unsent decisions are kept |
| `names` | `dict[str, str]` | `{}` | Maps an agent's name in your framework to the display name of the registered agent it belongs to. Rules and decisions keep the framework's name |
| `agent_version` | `str` | `None` | The agent's version, which rules can read |
| `env` | `dict` | `{}` | Your own tags in the run context, which rules can read |
| `predicates` | `dict[str, Callable]` | `None` | Your own functions, for a rules document that calls them by name. The document lists those names under `predicates` |
| `tools` | iterable of `str` | `None` | The tools the agent should call. A call to any other tool gets `unknown_tool_action` |
| `unknown_tool_action` | `"allow"`, `"flag"`, `"block"` | `"flag"` | What a call to a tool missing from `tools` gets |
| `sink` | `DecisionSink`, callable, or a list of them | `None` | Receives every decision |
| `decision_log` | path | `None` | Appends every decision to a JSON Lines file |
| `reporter` | `RegistrationReporter` | The built-in reporter | Receives the agents and tools each adapter covers, which the installation's **Coverage** card lists. Without an API key the SDK keeps them in memory |
| `durable` | path or `DurableStore` | `AMIRIL_DURABLE_PATH` | Keeps call history in a SQLite file across restarts |
| `durable_retention_ms` | `int` | `604800000` (7 days) | How long the file keeps a run no process has touched |
| `history_max_records` | `int` | `20000` | How many calls history keeps at most |
| `history_run_idle_ms` | `int` | `3600000` (1 hour) | A run idle this long is closed |
| `history_session_idle_ms` | `int` | `86400000` (24 hours) | A session idle this long is closed |
| `history_max_result_bytes` | `int` | `65536` | A tool result larger than this is cut short in history |
| `handle_sigterm` | `bool` | `True` | On SIGTERM, sends or saves queued decisions, then lets SIGTERM end the process as it would without the SDK. Only on the main thread, and only when no other handler is set |
| `redact` | callable | `None` | Called with a copy of each object before it leaves your process, as a `dict`. That is a decision record, a coverage report or the attributes `path_c` writes. Return the `dict` to send, or `None` to send nothing. If it changes an id such as `run_id` or `rule`, the SDK drops that object |
| `path_c` | `bool` | `False` | Writes each decision that is not an allow onto your active OpenTelemetry span, so your own traces show it |
| `annotate_allows` | `bool` | `False` | With `path_c`, also writes `amiril.decision = "allow"` on allowed calls |
| `startup_wait_ms` | `int` | `2000` | How long the first call waits for Amiril's first answer. After that it uses the cached rules or the rules file |
| `queue_capacity` | `int` | `10000` | How many decisions wait in memory at most. A full queue drops the oldest |
| `spool_max_bytes` | `int` | `52428800` (50 MiB) | How many bytes of unsent decisions are kept on disk at most |
| `shutdown_budget_ms` | `int` | `2000` | How long shutdown spends sending queued decisions |
| `clock` | callable | `time.time` | For tests |
| `timing` | `Timing` | The SDK's own timings | For tests |

## TypeScript init options [#typescript-init-options]

`init(options)` from `@amiril/sdk/node` returns the same handle as in Python, with `flush()`, `shutdown()` and `report()`. `init` throws `TypeError` for an option it does not know. The types in the table, such as `DecisionSink` and `Platform`, are exported from `@amiril/sdk`.

| Option | Type | Default | What it does |
| --- | --- | --- | --- |
| `rules` | object or `BundleSource` | `null` | A rules document. On an edge runtime, this is how rules arrive without a key |
| `rulesFile` | `string` | `AMIRIL_RULES_FILE` | A rules file |
| `mode` | `"enforce"`, `"shadow"`, `"off"` | `"enforce"` | `enforce` follows each rule's own mode. A rule starts in Shadow, so only a rule set to Enforce can block a call. `shadow` records what every rule would do and blocks nothing. `off` checks nothing and allows every call |
| `apiKey` | `string` | `AMIRIL_API_KEY` | The API key |
| `endpoint` | `string` | `AMIRIL_ENDPOINT` | The SDK endpoint. See `AMIRIL_ENDPOINT` |
| `environment` | `string` | `AMIRIL_ENVIRONMENT` | A label for where this process runs. See `AMIRIL_ENVIRONMENT` |
| `service` | `string` | [Detected](#service-name-and-version) | The service name |
| `version` | `string` | [Detected](#service-name-and-version) | The deployed version |
| `commit` | `string` | [Detected](#service-name-and-version) | The commit |
| `cacheDir` | `string` | [Cache directory](#cache-directory) | Where the last good rules and unsent decisions are kept |
| `names` | `Record<string, string>` | `{}` | Maps an agent's name in your framework to the display name of the registered agent it belongs to. Rules and decisions keep the framework's name |
| `agentVersion` | `string` | `null` | The agent's version, which rules can read |
| `env` | `Record<string, unknown>` | `{}` | Your own tags in the run context, which rules can read |
| `predicates` | `Record<string, PredicateFunction>` or a `Map` | `null` | Your own functions, for a rules document that calls them by name. The document lists those names under `predicates` |
| `tools` | `string[]` | `null` | The tools the agent should call. A call to any other tool gets `unknownToolAction` |
| `unknownToolAction` | `"allow"`, `"flag"`, `"block"` | `"flag"` | What a call to a tool missing from `tools` gets |
| `sink` | `DecisionSink` or an array of them | `null` | Receives every decision |
| `reporter` | `RegistrationReporter` | The built-in reporter | Receives the agents and tools each adapter covers, which the installation's **Coverage** card lists. Without an API key the SDK keeps them in memory |
| `durable` | `string` or `DurableStore` | `AMIRIL_DURABLE_PATH` | Keeps call history in a SQLite file across restarts |
| `history` | `Partial<HistoryLimits>` | As in Python | The `history_*` limits of the Python table as `maxRecords`, `runIdleMs`, `sessionIdleMs` and `maxResultBytes` |
| `redact` | function | `null` | Called with a copy of each object before it leaves your process. That is a decision record, a coverage report or the attributes `pathC` writes. Return the object to send, or `null` to send nothing. If it changes an id such as `run_id` or `rule`, the SDK drops that object |
| `pathC` | `boolean` | `false` | Writes each decision that is not an allow onto your active OpenTelemetry span, so your own traces show it |
| `annotateAllows` | `boolean` | `false` | With `pathC`, also writes `amiril.decision = "allow"` on allowed calls |
| `otel` | the `trace` API of `@opentelemetry/api` | The global one an OpenTelemetry SDK registers | The OpenTelemetry API `pathC` writes through. Without one, `pathC` writes nothing |
| `startupWaitMs` | `number` | `2000` | How long the first call waits for Amiril's first answer. After that it uses the cached rules or the rules file |
| `queueCapacity` | `number` | `10000` | How many decisions wait in memory at most. A full queue drops the oldest |
| `spoolMaxBytes` | `number` | `52428800` (50 MiB) | How many bytes of unsent decisions are kept on disk at most |
| `shutdownBudgetMs` | `number` | `2000` | How long shutdown spends sending queued decisions |
| `environ` | `Record<string, string>` or a function | The process environment | The environment variables to read |
| `platform` | `Platform` | Node's, from `@amiril/sdk/node` | The environment variables, filesystem, host identity and `fetch` the SDK uses. Pass your own only for a runtime that is not Node |
| `log` | `(message: string) => void` | `console.warn` | Where the SDK writes its log lines |
| `clock`, `timers`, `timing` | | | For tests |

TypeScript has no `decision_log`. Pass a `sink` to keep every decision yourself.

A SQLite file opened through `durable` keeps a run no process has touched for 7 days. For another period, pass `new SqliteStore(path, { retentionMs })` from `@amiril/sdk/node`.

## Service name and version [#service-name-and-version]

Without the `service` option, the SDK takes the name and the version from the first row below that has a name. The version comes from that same row, so a row without one leaves the version empty.

| Source | Name | Version |
| --- | --- | --- |
| Amiril | `AMIRIL_SERVICE` | `AMIRIL_VERSION` |
| OpenTelemetry | `OTEL_SERVICE_NAME` | `service.version` in `OTEL_RESOURCE_ATTRIBUTES` |
| Cloud Run | `K_SERVICE` | `K_REVISION` |
| AWS Lambda | `AWS_LAMBDA_FUNCTION_NAME` | `AWS_LAMBDA_FUNCTION_VERSION` |
| Your project | The `name` in the nearest `pyproject.toml` (Python) or `package.json` (TypeScript) | The `version` beside it |
| The folder | The name of the folder your started script is in | None |
| The host | The host name | None |

The SDK looks for the project file in the folder of the script you started, then in each folder above it. Services in different projects get different names this way. Services in one project share its name and become one installation, so give each its own `AMIRIL_SERVICE`.

To change the name people see for an installation that is already listed, open it on the **Installations** page and select **Rename**. The SDK keeps reporting its own name, and the new one shows only in Amiril.

The commit comes from `commit`, then `AMIRIL_COMMIT`, then `vcs.ref.head.revision` in `OTEL_RESOURCE_ATTRIBUTES`.

## Cache directory [#cache-directory]

Without `cache_dir` or `AMIRIL_CACHE_DIR`, the cache directory is `$XDG_CACHE_HOME/amiril`. Without `XDG_CACHE_HOME` it is `amiril-<uid>` in the system's temporary directory.

## Call history [#call-history]

A rule can read earlier calls in the same run or session, such as how many times `issue_payment` ran. The SDK keeps those calls in memory as its call history, so a restart forgets them. Set `durable` or `AMIRIL_DURABLE_PATH` when such a rule must keep working after a restart. The `history_*` options bound how much history the SDK keeps.

## Next steps

- [Check your agent's tool calls with the Amiril SDK](https://docs.amiril.ai/sdk.md): The Amiril SDK runs inside your agent and checks each tool call against your rules before the tool runs. Pick the guide for your framework and language.
- [How rules reach your agent](https://docs.amiril.ai/sdk/rule-sync.md): The SDK keeps your published rules in the agent's process and checks each tool call there. It keeps checking when Amiril is unreachable or the agent restarts.
- [Add Amiril to a Google ADK agent](https://docs.amiril.ai/sdk/google-adk.md): Check every tool call of a Google ADK agent against your rules, in Python or TypeScript. Amiril runs as the first plugin and blocks calls that break a rule.
- [HTTP API](https://docs.amiril.ai/reference/api.md): Call Amiril's HTTP API from your own code with an OAuth access token. Find the base URL, the sign-in steps for a token, the environment header and the errors.

## More detail

- [SDK behaviour in detail](https://docs.amiril.ai/assistant/sdk.md): The Amiril SDK past the setup guides: per-framework gaps, run ids and sessions, hook order and its errors, restarts, shutdown, offline behaviour, model messages, tested versions.
- [Limits and defaults](https://docs.amiril.ai/assistant/limits.md): Every limit and default a customer can hit in Amiril, with its number: plan amounts, ingest sizes and rates, imports, rules, backtests, API and MCP rates, page sizes, retention, name lengths.
- [Troubleshooting](https://docs.amiril.ai/assistant/troubleshooting.md): Symptom, cause, how to confirm and fix for common Amiril problems: missing runs, plan limits, wrong agent or environment, rules that never fire or never block, SDK, key, import and MCP failures.
