Skip to content

Bug: API keys in .env file not loaded reliably at runtime #317

@mikejmorgan-ai

Description

@mikejmorgan-ai

Description

API keys stored in .env files are not reliably loaded by Cortex at runtime. Users must manually export environment variables for Cortex to detect them.

Expected Behavior

  • Cortex should automatically load .env file from project root or home directory
  • API keys in .env should be available without manual export

Actual Behavior

  • .env file is present with correct API key
  • Cortex does not detect the key
  • Only works after running export OPENAI_API_KEY=... manually

Steps to Reproduce

  1. Create .env file with OPENAI_API_KEY=sk-...
  2. Run cortex install nginx --dry-run
  3. Observe API key not detected
  4. Run export OPENAI_API_KEY=sk-...
  5. Run command again — now works

Suggested Fix

Ensure python-dotenv is called early in the application startup:

from dotenv import load_dotenv
load_dotenv()  # Must be called before accessing os.environ

Also check for .env in multiple locations:

  • Current directory
  • ~/.cortex/.env
  • /etc/cortex/.env

Environment

  • Cortex v0.1.0
  • Ubuntu (Effiti team testing)

Reporter

Effiti team via Discord

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions