# Configuration

## Settings

`Config.from_env` reads these environment variables. Each can also be passed as a keyword, as in `Config.from_env(app="myapp", slow_ms=5000)`. In Node, pass the camelCase option to `createTelltale`.

| Variable | Default | Meaning |
|---|---|---|
| `TELLTALE_DB_URL` | none | Database URL: `postgresql://...`, `mysql://...` or `sqlite:////absolute/path.db`. Without it, telltale is off. |
| `TELLTALE_ENABLED` | `true` | `false` turns telltale off. |
| `TELLTALE_READ_KEY` | none | Key that can call any GET on the API. At least 16 characters. |
| `TELLTALE_ADMIN_KEY` | none | Key that can call everything. At least 16 characters. |
| `TELLTALE_SECRET` | random at each start | Key for hashing user ids and addresses. Set it so hashes match across processes and restarts. |
| `TELLTALE_SCHEMA` | `telltale` | Postgres schema for telltale's tables. On MySQL and SQLite the tables are named `telltale_*`. |
| `TELLTALE_REPO` | none | The app's GitHub repo, as `owner/name`. |
| `TELLTALE_REPO_PRIVATE` | `false` | The repo is private. |
| `TELLTALE_PRIVATE_DATA` | `false` | The app holds private data. Error and dead-end messages are not stored. |
| `TELLTALE_ENV` | `local` | Label stored with each record. |
| `TELLTALE_RELEASE` | none | Label stored with each record. |
| `TELLTALE_SLOW_MS` | `3000` | Requests at least this slow are recorded as slow. |
| `TELLTALE_RETENTION_DAYS` | `90` | Events, counts and untouched groups older than this are deleted daily. Feedback is kept. |
| `TELLTALE_PROXY_HOPS` | `0` | Number of trusted reverse proxies in front of the app. |
| `TELLTALE_TRUST_CF` | `false` | Read the caller's address from `CF-Connecting-IP`. Safe only when the origin accepts connections from Cloudflare alone. |
| `TELLTALE_OWN_CLIENTS` | empty | Comma-separated User-Agent prefixes of your own tools. Their requests are filed as `own_client`. |
| `TELLTALE_ALLOWED_ORIGINS` | empty | Comma-separated origins of your own web pages. |
| `TELLTALE_ANON_CONTACT` | `true` | `false` drops any contact a signed-out sender types with feedback. |
| `TELLTALE_EXTRA_SCRUB_PATTERNS` | empty | Extra regexes to scrub, separated by `;;`. A match becomes `[id]`. |
| `TELLTALE_MCP_PATH` | `/mcp` | Requests under this path are filed under the `mcp` surface. |
| `TELLTALE_TRUSTED_ISSUER` | none | URL of a service whose signed calls get admin access with no stored key. Python only. |

Without `TELLTALE_PROXY_HOPS` behind a proxy, every caller has the proxy's address, so the per-sender feedback limits stop working and one caller sending bad keys locks everyone out of the API.

## Hooks

Hooks are functions you set on `tt`. Each gets a read-only view of the request with `.headers` (lowercased), `.method`, `.path`, `.scope` and `.state` (the request state, as a dict). `authorize` gets the real request.

### `tt.classify_hook(request) -> ClientInfo | None`

Names the client, as in `ClientInfo("agent", "api-key")`. Runs on every request before your app's sign-in, so it must read headers only. `None` falls through to telltale's own rules.

### `tt.actor_hook(request) -> str | None`

The signed-in user's id. It is hashed before it is stored. A request counts as signed in only when this returns an id.

### `tt.sender_hook(request) -> str | None`

The contact stored with a signed-in user's feedback, usually `"Name <email>"`. It wins over anything typed in the dialog. Only an admin signed in as a person sees it.

### `tt.authorize(request) -> "admin" | "read" | None`

Lets your app's own sign-in open the telltale API and console. An exception counts as no access. A bearer token that equals a telltale key is used as that key and never reaches this hook. With this hook set, the API mounts even when no key is set.

### `tt.entity_resolver(entity_type, entity_id) -> str | None`

Turns an `(entity_type, entity_id)` pair into a readable label. The API adds these labels to a group's detail.

In Node, the hooks are options to `createTelltale`: `classifyHook`, `userId`, `authorize` and `entityResolver`.

## Feedback limits

Each sender may send 10 notes an hour, each address 60, and each app 200. The limits apply to the HTTP route and the MCP tool alike. A note may be up to 4000 characters.

The [Python README](https://github.com/databio/telltale/blob/main/python/README.md) and [Node README](https://github.com/databio/telltale/blob/main/node/README.md) cover the rarer settings.
