# Self-host the server

Run Alim on your own server with Docker or OpenShip. Back up `/pb/pb_data`, which holds your workspace data.

| Path           | Best for                                  | Go to                                               |
| -------------- | ----------------------------------------- | --------------------------------------------------- |
| Local binary   | Development on Linux or macOS             | [Run locally](#run-locally)                         |
| Docker         | Any server with Docker                    | [Run with Docker](#run-with-docker)                 |
| Docker Compose | Docker plus the private email redactor    | [Private email redaction](#private-email-redaction) |
| OpenShip       | A managed deploy with domains and secrets | [Deploy with OpenShip](#deploy-with-openship)       |

## Environment variables

Put these in a `.env` file at the repo root or in your deploy secrets. Run `chmod 600 .env` and never commit it. `.env.required` lists the required, provider and mail keys. Provider keys are under [Providers](#providers) and everything else under [Optional settings](#optional-settings).

| Variable                    | Value                                                                                                                        |
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `PUBLIC_URL`                | Public origin without a trailing slash, like `https://alim.example.com`. Used for OAuth, pairing, MCP and docs links         |
| `OPENSCRIBE_ADMIN_EMAIL`    | Comma-separated admin emails. Admins can sign in and change AI providers, models and agents. Empty means no admin            |
| `PB_ADMIN_PASSWORD`         | PocketBase superuser password, 10 or more characters                                                                         |
| `PB_ENCRYPTION_KEY`         | Exactly 32 characters. Encrypts PocketBase settings                                                                          |
| `ALIM_TOKEN_ENCRYPTION_KEY` | 32 bytes as 64 hex characters or base64. Encrypts stored provider tokens. Any other value is hashed into a key, not rejected |

Generate both keys for a new installation:

```bash
openssl rand -hex 16   # PB_ENCRYPTION_KEY
openssl rand -hex 32   # ALIM_TOKEN_ENCRYPTION_KEY
```

> [!NOTE]
> Upgrading? Move your existing `OPENSCRIBE_TOKEN_ENCRYPTION_KEY` value to `ALIM_TOKEN_ENCRYPTION_KEY` unchanged so stored tokens stay readable. The server falls back to the old name while the new one is empty.

> [!WARNING]
> Back up both keys with the data volume. Without them a restored database cannot decrypt its settings or calendar tokens. Without an explicit token key, the server derives one from `GOOGLE_CLIENT_SECRET` and `OPENSCRIBE_ADMIN_EMAIL`, so changing either one breaks every connected calendar.

## Run locally

Build the web app first, because the server serves `apps/web/dist`. The build also renders these docs.

```bash
cd apps/web && npm ci && PUBLIC_URL=http://127.0.0.1:8090 npm run build && cd ../..
cd apps/server && go build -o openscribe .
./openscribe prepare --dev=false --dir=./pb_data --encryptionEnv=PB_ENCRYPTION_KEY
./openscribe serve --dev=false --http=127.0.0.1:8090 --dir=./pb_data --encryptionEnv=PB_ENCRYPTION_KEY
```

`prepare` runs migrations, applies OAuth settings and creates the superuser.

> [!CAUTION]
> Always pass `--dev=false`. Dev mode logs SQL statements that can contain secrets.

## Run with Docker

```bash
docker build -t openscribe .
docker volume create openscribe-data
docker run -d --name openscribe --restart unless-stopped \
  -p 127.0.0.1:8090:8090 --env-file .env \
  -v openscribe-data:/pb/pb_data openscribe
```

The container applies migrations at startup. [Check the deployment](#check-the-deployment) when it comes up.

## Deploy with OpenShip

[OpenShip](https://openship.io) reads `openship.json`, which builds the `Dockerfile`, exposes port `8090` and mounts the `openscribe-data` volume at `/pb/pb_data`. Replace its domain with yours, then:

1. Check the config and create a project:

    ```bash
    openship --json config validate
    openship project create --name openscribe
    openship init --force --project your_project_id
    ```

2. Set plain values, then secrets. Add provider keys the same way.

    ```bash
    openship project env set your_project_id \
      --set PUBLIC_URL=https://alim.example.com \
      --set OPENSCRIBE_ADMIN_EMAIL=you@example.com
    openship project env set your_project_id --secret \
      --set PB_ADMIN_PASSWORD="$PB_ADMIN_PASSWORD" \
      --set PB_ENCRYPTION_KEY="$PB_ENCRYPTION_KEY" \
      --set ALIM_TOKEN_ENCRYPTION_KEY="$ALIM_TOKEN_ENCRYPTION_KEY" \
      --set GOOGLE_CLIENT_ID="$GOOGLE_CLIENT_ID" \
      --set GOOGLE_CLIENT_SECRET="$GOOGLE_CLIENT_SECRET"
    ```

3. Point DNS at your OpenShip host and attach the domain:

    ```bash
    openship domain add alim.example.com --project your_project_id
    openship domain verify your_domain_id
    ```

4. Deploy and follow the build:

    ```bash
    openship deploy --watch
    ```

## Check the deployment

| Check             | Command                                          | Expect                                   |
| ----------------- | ------------------------------------------------ | ---------------------------------------- |
| Server is up      | `curl -s https://alim.example.com/api/config`    | JSON with the configured sign-in methods |
| Docs are public   | `curl -sI https://alim.example.com/docs/`        | `200`                                    |
| Privacy is public | `curl -sI https://alim.example.com/privacy/`     | `200`                                    |
| Unknown docs path | `curl -sI https://alim.example.com/docs/missing` | `404`                                    |
| MCP asks for auth | `curl -si -X POST https://alim.example.com/mcp`  | `401` with `WWW-Authenticate`            |

The config response lists which providers have keys. Signed-in accounts also see their own Drive settings.

### Check live transcription

This check sends a fixed synthetic phrase, requires recognized words with word timestamps, then closes the provider session. It creates no meeting.

1. As a PocketBase superuser, issue a token for the dedicated record in `transcription_probes`.
2. Store it as `ALIM_QA_TOKEN` in encrypted CI secrets or your ignored local `.env`, never in a browser bundle.
3. Run the check with Node 22:

    ```bash
    node --env-file=.env .agents/qa/transcription.mjs
    ```

The token works only on `POST /api/transcription/check`. It cannot read meetings or use admin routes, and normal app sessions cannot call that endpoint.

The check covers ElevenLabs today. Any other active provider fails with an explicit unsupported-check message. It also fails on missing or expired probe authorization, rejected credentials, quota errors, absent speech, absent timestamps and unclosed sessions.

## Connect the Mac app

On the sign-in screen, click **Use Another Workspace…**. To switch later, go to **Settings → Workspace → Change Workspace…** while you’re between meetings. Enter your server address and click **Connect**, then sign in on the page Alim opens.

![Alim sign-in screen with Use Another Workspace](/docs/assets/alim-mac-workspace.png)

Use HTTPS for a remote server. Use a loopback address when running the server locally over HTTP.

## Back up

Back up the volume together with `PB_ENCRYPTION_KEY` and `ALIM_TOKEN_ENCRYPTION_KEY`.

| Path                                        | Contents                                                                                         |
| ------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| `/pb/pb_data/data.db` (with `-wal`, `-shm`) | Users, calendars, meetings, transcripts, notes, people, projects, tasks, AI settings, MCP grants |
| `/pb/pb_data/auxiliary.db`                  | PocketBase logs                                                                                  |
| `/pb/pb_data/storage/`                      | Uploaded files and screenshots                                                                   |

## Providers

Provider keys stay on the server. Clients never receive them.

| Variable                                                              | Enables                                                                                                                                                                                                                    |
| --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ELEVENLABS_API_KEY`                                                  | Live transcription with ElevenLabs Scribe v3, the default                                                                                                                                                                  |
| `OPENAI_API_KEY`                                                      | OpenAI transcription, relayed through the server, and OpenAI models                                                                                                                                                        |
| `ANTHROPIC_API_KEY`                                                   | Claude models for Q&A and summaries                                                                                                                                                                                        |
| `GOOGLE_API_KEY`                                                      | Gemini transcription and Gemini models                                                                                                                                                                                     |
| `OPENSCRIBE_LOCAL_STT_BASE_URL`                                       | Your own OpenAI-compatible `/v1/audio/transcriptions` server, like `http://127.0.0.1:8080/v1`                                                                                                                              |
| `OPENSCRIBE_LOCAL_STT_API_KEY`                                        | Bearer token for that server, if it needs one                                                                                                                                                                              |
| `OPENSCRIBE_TRANSCRIPTION_PROVIDER`, `OPENSCRIBE_TRANSCRIPTION_MODEL` | Default transcription provider and model until an admin picks one                                                                                                                                                          |
| `TYPESAFE_API_KEY`                                                    | Better search suggestions, and duplicate and series checks when the `decisions` workload uses `typesafe`. Spoken-reference checks send the surrounding excerpt and candidate descriptions. Local matching works without it |

Admins set workspace models in **AI models**. For speech, use the `OPENSCRIBE_TRANSCRIPTION_*` variables or `PUT /api/admin/transcription`.

| Job                              | Default model                                                                    |
| -------------------------------- | -------------------------------------------------------------------------------- |
| Transcription                    | ElevenLabs `scribe_v3_live`                                                      |
| Tags, People & projects          | OpenAI `gpt-6-luna`                                                              |
| Topic matching, Duplicate checks | Google `gemini-decision-1` (falls back to TypeSafe `jev-1.14.0` when configured) |
| Questions, Summaries             | Anthropic `claude-sonnet-5-5`                                                    |
| Tasks                            | Google `gemini-3.8-flash`                                                        |

### Use your own provider key

1. Open **AI models → Your keys and models** and enter your provider key.
2. Choose a model for the work you want billed to that key. For new recordings, choose an ElevenLabs, OpenAI or Gemini model under **Speech to text**.
3. Choose **Save my settings**.

> [!NOTE]
> A saved key pays only for the selections assigned to it. **Workspace default** uses workspace billing.

To remove a key, first switch its selections to **Workspace default** or another provider, then remove the key and save. Removing or replacing an OpenAI key closes its active personal speech connections.

Personal keys require `ALIM_TOKEN_ENCRYPTION_KEY` (or the configured Google client secret). A personal Google key needs paid access to Gemini 4 Argon for the [billing check](/privacy.md#personal-provider-keys).

### Your own speech recognition

Both options need an endpoint that accepts multipart WAV uploads at `/v1/audio/transcriptions`. Word times are used when the endpoint returns them.

| Where audio goes             | Set                                                                                                                                                                          |
| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Directly from the Mac        | On the Mac, `OPENSCRIBE_TRANSCRIPTION_PROVIDER=openai_compatible`, `OPENSCRIBE_LOCAL_STT_URL` for the loopback service and `OPENSCRIBE_TRANSCRIPTION_MODEL` for its model ID |
| Through the workspace server | `OPENSCRIBE_LOCAL_STT_BASE_URL` on the server                                                                                                                                |

Teams browser captions always come from Microsoft.

## Optional settings

| Variable                           | Default                                              | Effect                                                                                                                                           |
| ---------------------------------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `PORT`                             | `8090`                                               | Listen port for the container and for `serve` without `--http`. Keep `8090` in Docker, because the health check probes it                        |
| `PB_DATA_DIR`                      | `/pb/pb_data`                                        | Data directory in the container                                                                                                                  |
| `OPENSCRIBE_WEB_DIST`              | `../web/dist`, `./apps/web/dist`, then `./pb_public` | Built web app and docs to serve. Tried first when set                                                                                            |
| `PB_ADMIN_EMAIL`                   | First `OPENSCRIBE_ADMIN_EMAIL`                       | PocketBase superuser email at `/_/`                                                                                                              |
| `OPENSCRIBE_USER_EMAIL`            | none                                                 | Comma-separated emails that can sign in to a normal workspace without admin settings. Admins can always sign in                                  |
| `OPENSCRIBE_EMAIL_SIGN_IN`         | `false`                                              | `true` enables [email and password sign-in](#sign-in-without-google) for verified accounts on either allowlist                                   |
| `OPENSCRIBE_PII_URL`               | none                                                 | [Private redaction service](#private-email-redaction) URL                                                                                        |
| `OPENSCRIBE_GMAIL`                 | `on`                                                 | `off` limits new Gmail connections and sync to reviewers                                                                                         |
| `OPENSCRIBE_GMAIL_REVIEWERS`       | empty                                                | Comma-separated verified Alim emails that may use Gmail while it is off                                                                          |
| `OPENSCRIBE_DRIVE_SEARCH`          | `off`                                                | `on` offers Drive search (`drive.readonly`) to every user                                                                                        |
| `OPENSCRIBE_DRIVE_REVIEWERS`       | empty                                                | Comma-separated verified Alim emails that may search Drive while it is off                                                                       |
| `OPENSCRIBE_TELEMETRY`             | `on`                                                 | `off` stops anonymous usage events. `debug` validates them without recording. See [privacy](/privacy.md#product-usage-analytics)                  |
| `OPENSCRIBE_TRUSTED_PROXY_HEADERS` | none                                                 | Header holding the visitor IP behind a reverse proxy, like `X-Forwarded-For`. Leave it unset without a proxy, or clients can spoof their address |
| `SMTP_URL`                         | none                                                 | Outgoing mail server                                                                                                                             |
| `MAIL_FROM`                        | `noreply@akyonlabs.com`                              | Sender address                                                                                                                                   |

OAuth client variables are listed with their callbacks in [Set up connectors](#set-up-connectors).

## Set up connectors

Register each callback as `PUBLIC_URL` plus the path below, store the credentials in `.env` or deploy secrets, and restart Alim. Each guide is in [Connectors](/docs/connectors.md).

| Connector                                                                     | Credentials                                                                                                                                    | Callback path                                                                    |
| ----------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| [Google](/docs/connectors.md#google) sign-in, Calendar, Meet links, Gmail and Drive | `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET`. The Drive Picker also needs `GOOGLE_PICKER_API_KEY` and `GOOGLE_CLOUD_PROJECT_NUMBER`              | `/api/oauth2-redirect` for sign-in, `/api/oauth/google/callback` for the rest    |
| [Microsoft](/docs/connectors.md#microsoft-entra) sign-in, Outlook Calendar and Mail | `MICROSOFT_CLIENT_ID`, `MICROSOFT_CLIENT_SECRET`                                                                                               | `/api/oauth2-redirect` for sign-in, `/api/oauth/microsoft/callback` for the rest |
| GitHub sign-in                                                                | `GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET` from a GitHub OAuth App                                                                             | `/api/oauth2-redirect`                                                           |
| Apple sign-in                                                                 | `APPLE_CLIENT_ID` (a Services ID) with `APPLE_CLIENT_SECRET`, or `APPLE_TEAM_ID`, `APPLE_KEY_ID` and `APPLE_PRIVATE_KEY` to sign ES256 secrets | `/api/oauth2-redirect`                                                           |
| ChatGPT sign-in                                                               | `CHATGPT_CLIENT_ID`, `CHATGPT_CLIENT_SECRET`, or `OPENAI_OAUTH_CLIENT_ID`, `OPENAI_OAUTH_CLIENT_SECRET`                                        | `/api/oauth2-redirect`                                                           |
| [Zoom](/docs/connectors.md#zoom) links and calendar                                 | `ZOOM_CLIENT_ID`, `ZOOM_CLIENT_SECRET` from a user-managed General app                                                                         | `/api/oauth/zoom/callback`                                                       |
| [Tactiq and tldv imports](/docs/connectors.md#meeting-imports)                      | Chrome extension or tldv API key                                                                                                               | none                                                                             |

## Sign in without Google

Email sign-in uses the instance's own PocketBase accounts and needs no Google OAuth or SMTP.

1. Set `OPENSCRIBE_EMAIL_SIGN_IN=true` and put the account email in `OPENSCRIBE_USER_EMAIL` or `OPENSCRIBE_ADMIN_EMAIL`. Restart Alim.
2. In the PocketBase dashboard at `/_/`, create or edit the account in the **users** collection. Set its password and mark the email **Verified** after confirming who owns it.
3. [Connect the Mac app](#connect-the-mac-app) and sign in with that email and password.

## Private email redaction

Gmail and Outlook project matching is optional and needs `OPENSCRIBE_PII_URL`, the full URL of a private CPU redaction service such as `http://pii:8092/redact`. The same service redacts linked Drive and uploaded entity file text, up to `32,000` characters, and fails closed.

Tactiq import screening and the on-demand quality tool require a configured Decisions provider (Google for the default Gemini agent) and the `caption_v1` profile from the matching `services/pii` release. Rebuild the private image when upgrading it. A server running an older redactor declines the assessment before sending that batch to Decisions.

Run it beside the app with the optional `compose.yaml`. Create the root `.env` first.

```sh
docker compose up --build -d
```

- The app listens on `127.0.0.1:8091`. Put your HTTPS reverse proxy in front and set `PUBLIC_URL` to its public origin.
- The redactor has no published port and uses an internal Docker network. Its model downloads during the image build and serves offline.

For an existing single-container OpenShip install:

1. Build `services/pii/Dockerfile` with `services/pii` as its build context.
2. Run it on the app's private Docker network with the alias `pii`, without a published port or access to the PocketBase volume.
3. Set `OPENSCRIBE_PII_URL=http://pii:8092/redact` on the app.
4. From the app container, `GET http://pii:8092/health` returns `{"ready": true}` once the model loads.

| Topic     | Behavior                                                                                                                                                         |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Model     | `fastino/gliner2-privacy-filter-PII-multi`, pinned by the service build. Its published training languages do not include Turkish                                 |
| Resources | At least 4 GiB RAM. Start with two CPU threads (`PII_THREADS=2`)                                                                                                 |
| Masked    | Financial details such as bank accounts, IBANs, Luhn-valid payment cards, tax IDs and salary or compensation lines, plus credentials, secrets and government IDs |
| Kept      | Person names and normal discussion, for project matching and focused task and deadline resolution (`task_resolution`)                                            |
| Limits    | Detection can miss sensitive details and does not guarantee complete removal                                                                                     |
| When down | Project classification and redacted-email task resolution wait. Original email text is never sent to a model provider instead                                    |
| Network   | Keep the endpoint on a trusted private network, because requests contain unredacted text                                                                         |

Mailbox sync and local person matching need no AI provider or webhook. Each process sends one redaction request at a time, so `/health` can still answer. On restart, project matching resumes from saved checkpoints. See [sync and classification retries](/docs/api.md#sync-a-mailbox).

## Connect AI clients over MCP

The OAuth 2.1 protected endpoint is `/mcp`, with discovery at `/.well-known/oauth-protected-resource/mcp` and `/.well-known/oauth-authorization-server` and OAuth routes under `/oauth/*`. See [Connect AI clients over MCP](/docs/mcp.md) for client setup and [API reference](/docs/api.md#mcp-and-oauth) for the contracts.

## Maintenance commands

Run these as the user that owns the data directory.

### Repair confirmed duplicate captures

Combine older captures only after you verify that they belong to one calendar occurrence. Back up the volume first.

```sh
openscribe repair-capture-meetings --file /tmp/repair.json --migration-name 20261116_confirmed_capture_repair --dir /pb/pb_data
```

The input names one owner, the meeting to keep, the source meetings and the verified occurrence:

```json
{
    "owner_id": "OWNER_ID",
    "canonical_id": "MEETING_TO_KEEP",
    "source_ids": ["SOURCE_MEETING_ID"],
    "occurrence": {
        "account_id": "CALENDAR_ACCOUNT_ID",
        "calendar_id": "primary",
        "event_id": "OCCURRENCE_EVENT_ID",
        "recurring_event_id": "SERIES_EVENT_ID"
    }
}
```

- The command records an application migration named after the input digest, so repeating an input adds nothing.
- Old links resolve to the combined meeting.
- It rejects active captures and queued or running extraction jobs.
- It never discovers or guesses which meetings belong together.

### Resolve tasks

The read-only `task_resolution` agent checks open tasks against strictly later ended meetings and `OPENSCRIBE_PII_URL`-redacted email threads. It runs `anthropic` `claude-haiku-5-5` by default with the `list_later_timeline`, `search_evidence_passages`, `read_transcript_window` and `read_email_thread` tools. Trigger a sweep by hand:

```sh
openscribe resolve-tasks --owner OWNER_ID --scope all --limit 500 --workers 4 --dir /pb/pb_data
```

### Mind pipeline storage

Startup migrations add everything Mind needs to the existing volume and backups. There is no new environment variable, service or training job.

- **Agents**: the `entity_resolution`, `knowledge_compaction`, `task_resolution`, `topic_matching`, and `email_classification` built-ins are seeded on existing installs. The local `meeting_source_matching` agent runs `meeting_source_match@v1` before extraction, records the version and rule on the source and any review suggestion, and resumes pending work after a restart. An unmodified extraction contract gets the default pipeline. Edited contracts stay intact.
- **Fields**: pipeline JSON on `ai_agents`, resolution watermark and lease fields on `knowledge_tasks` and `knowledge_details`, link/exclusion lists on `meetings` and `email_threads`, and `agent_trace` on suggestions, details, tasks and entity revisions.
- **Tools**: versioned as `@v1`. Matching uses `entity_rule_match`, `shortlist_candidates`, `hybrid_rrf_shortlist`, `decide_predicates`, `source_link_entity`, and `source_unlink_entity`. Compaction uses `detail_supersede`, `task_consolidate` and `entity_merge`. Observability uses `rollouts_stats` and `trajectories_export`. The registry enforces enabled tools and read-only access, and admin pipeline edits appear as immutable Markdown diffs.
- **Defaults**: entity resolution shortlists five candidates, proposes at 0.5 and matches at 0.85. `topic_matching` and `email_classification` use `hybrid_rrf_shortlist` (Top-15) and `google/gemini-decision-1` with automatic workspace fallback to `typesafe/jev-1.14.0`.
- **Collections**: `workspace_ontologies` holds each owner's persona and overrides. `ai_rollouts` and `training_trajectories` hold scrubbed AI calls, explicit feedback, implicit edit/link trajectories, outputs, rewards and traces. Clients cannot change any of them directly.
