Skip to content

Load .env automatically at startup so the API key doesn't depend on the launch shell #3

Description

@Hrt-Htk

Summary

The proxies read the API key from the process environment only
(os.environ.get("LLAMA_API_KEY")), but nothing loads .env. So whether
the server comes up authenticated depends entirely on the shell that launched it
having $env:LLAMA_API_KEY exported.

Observed:

  • .env contains LLAMA_API_KEY, but no code reads it (stdlib + aiohttp only, no
    python-dotenv).
  • No PowerShell profile sets it (none exist), and it is not a persistent
    env var (User/Machine scope both empty).
  • watchdog.ps1 / watchdog-embed.ps1 don't load .env either.

Result: launching from a fresh terminal (or a Task Scheduler context) that didn't
export the key brings the proxy up with auth disabled (the auth_middleware
skips auth when config.api_key is falsy), which is a silent security footgun.

Proposed fix

Load .env at startup in both proxy.py and embed_proxy.py using stdlib only
(no new dependency): parse KEY=VALUE lines from .env next to the script and
os.environ.setdefault(...) each one.

  • Use setdefault so an already-exported env var always wins (no surprise
    overrides; explicit env still takes precedence).
  • Tolerate a missing .env (no-op), comments (#), blank lines, and quoted
    values.
  • Keep it shared (e.g. a small helper) so both proxies behave identically.

Acceptance criteria

  • Launching either proxy from a shell with no LLAMA_API_KEY exported still
    comes up authenticated using the value in .env.
  • An explicitly exported LLAMA_API_KEY overrides the .env value.
  • Missing .env does not crash startup.
  • No new third-party dependencies; .env stays gitignored.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions