Skip to content

fix(docker): forward OPENROUTER_API_KEY into the self-host container - #152

Merged
bensenescu merged 2 commits into
every-app:mainfrom
Nordalux:fix/docker-openrouter-key-passthrough
Jul 30, 2026
Merged

fix(docker): forward OPENROUTER_API_KEY into the self-host container#152
bensenescu merged 2 commits into
every-app:mainfrom
Nordalux:fix/docker-openrouter-key-passthrough

Conversation

@Nordalux

Copy link
Copy Markdown
Contributor

Problem

OPENROUTER_API_KEY is documented as the key that unlocks the AI features on a self-hosted install:

  • .env.example: "Optional in self-hosted modes. Required if you want AI features like SAM, the in-app SEO agent."
  • src/routes/_app/help/openrouter-api-key.tsx — a whole in-app help page for obtaining and setting it.
  • src/client/features/sam/SamSetupGate.tsx — tells the user to set the OPENROUTER_API_KEY environment variable and restart.

Under Docker none of that has any effect. Compose only forwards the keys listed under environment: in compose.yaml, and this one was not listed. SamChatAgent.ts:110 calls getEnvValueSync(this.env, "OPENROUTER_API_KEY"), gets nothing, and throws OPENROUTER_API_KEY is required for the SAM agent — so the user follows the in-app instructions, restarts, and SAM stays broken with no indication why.

Change

Add the passthrough next to the existing optional Google Search Console keys, using the same ${VAR:-} form so it stays optional.

Verification

With a .env containing OPENROUTER_API_KEY=sk-or-test123:

# main
$ docker compose -f compose.yaml config | grep OPENROUTER
(no output)

# this branch
$ docker compose config | grep OPENROUTER
      OPENROUTER_API_KEY: sk-or-test123

pnpm ci:check passes.

Docs

SELF_HOSTING_DOCKER.md said Compose "passes .env values into the container", which reads as though any key in .env arrives in the container — the assumption that makes this bug easy to miss. Corrected to say it forwards the keys compose.yaml lists, and added OPENROUTER_API_KEY to the optional env values list.

Note

#115 adds CHAT_BASE_URL for local/OpenAI-compatible chat models. If that lands, it will need the same passthrough line to work under Docker — happy to add it here or leave it to that PR, whichever the maintainers prefer.

`.env.example` documents `OPENROUTER_API_KEY` as "Required if you want AI
features like SAM", the in-app help page walks through creating one, and
`SamSetupGate` tells the user to set the environment variable and restart.
None of that works under Docker: Compose only forwards the keys listed under
`environment:` in `compose.yaml`, and this one was missing, so
`getEnvValueSync(this.env, "OPENROUTER_API_KEY")` in SamChatAgent never saw a
value no matter what the user put in `.env`.

Add the passthrough alongside the existing optional GSC keys.

Verified with `docker compose config` against a `.env` containing the key:
it is absent from the rendered config on main and present after this change.

Also correct the sentence in SELF_HOSTING_DOCKER.md that says Compose "passes
`.env` values into the container" — it only passes the ones `compose.yaml`
lists, which is what made this easy to miss — and add the key to the optional
env values list.

@sorcerai sorcerai left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact current diff. OPENROUTER_API_KEY is forwarded without logging or changing defaults, and the Docker documentation now matches Compose behavior.

@sorcerai

Copy link
Copy Markdown

Integration note: #52 and this PR both touch compose.yaml and docs/SELF_HOSTING_DOCKER.md; merging either second conflicts. Safest order is #52 first, then rebase this small PR. While rebasing, please take up your offer from the PR body and add CHAT_BASE_URL passthrough for #115 so local/OpenAI-compatible chat also works under Docker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants