Skip to content

fix: use OPENAI_API_KEY env var consistently (not undefined OPENAI_KEY)#67

Open
FBISiri wants to merge 1 commit into
kingjulio8238:mainfrom
FBISiri:fix/openai-api-key-env-var-consistency
Open

fix: use OPENAI_API_KEY env var consistently (not undefined OPENAI_KEY)#67
FBISiri wants to merge 1 commit into
kingjulio8238:mainfrom
FBISiri:fix/openai-api-key-env-var-consistency

Conversation

@FBISiri

@FBISiri FBISiri commented Jun 27, 2026

Copy link
Copy Markdown

Problem

base_agent.py and synonym_expand/synonym.py read the OpenAI API key from the environment variable OPENAI_KEY, but that variable is never defined anywhere in the project. The README's setup instructions and the rest of base_agent.py use OPENAI_API_KEY:

  • README.md (setup): OPENAI_API_KEY="YOUR_API_KEY"
  • base_agent.py:149-150: os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")

But two call sites use the wrong name:

  • src/memary/agent/base_agent.py:153OpenAIMultiModal(..., api_key=os.getenv("OPENAI_KEY"))
  • src/memary/synonym_expand/synonym.py:11OpenAI(openai_api_key=os.getenv("OPENAI_KEY"), ...)

Because OPENAI_KEY is undefined, os.getenv("OPENAI_KEY") returns None, so the vision model (gpt-4-vision-preview) and the synonym-expansion LLM are silently initialized with api_key=None and fail with an authentication error at runtime — even when the user has correctly set OPENAI_API_KEY per the README.

Fix

Align both call sites to OPENAI_API_KEY. Two-line, string-only change, no logic change.

- api_key=os.getenv("OPENAI_KEY"),
+ api_key=os.getenv("OPENAI_API_KEY"),
- llm = OpenAI(openai_api_key=os.getenv("OPENAI_KEY"), temperature=0)
+ llm = OpenAI(openai_api_key=os.getenv("OPENAI_API_KEY"), temperature=0)

Verification

grep -rn "OPENAI_KEY" src/ before this change shows the two offending sites are the only places OPENAI_KEY (without _API_) is referenced in src/; every other reference, and the README, uses OPENAI_API_KEY.

The README and the rest of base_agent.py read the OpenAI key from
OPENAI_API_KEY, but load_vision_model() and custom_synonym_expand_fn()
read from os.getenv("OPENAI_KEY"), which is never defined anywhere in
the project. As a result the OpenAI vision model and the synonym
expansion LLM are silently initialized with api_key=None, causing
auth failures at runtime whenever those code paths are used.

Align both call sites to OPENAI_API_KEY.
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.

1 participant