Skip to content

[Bug]: OpenAI API key changes not reflected across multiple calls #1828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks done
LennartSchmidtKern opened this issue Mar 20, 2025 · 1 comment
Open
3 tasks done
Labels
backlog We've confirmed some action is needed on this and will plan it enhancement New feature or request

Comments

@LennartSchmidtKern
Copy link

LennartSchmidtKern commented Mar 20, 2025

Do you need to file an issue?

  • I have searched the existing issues and this bug is not already filed.
  • My model is hosted on OpenAI or Azure. If not, please look at the "model providers" issue and don't file a new one here.
  • I believe this is a legitimate bug, not just a question. If this is a question, please use the Discussions area.

Describe the bug

I am using graphrag in a FastAPI backend service where a request can create a new custom index. The OpenAI API keys appear to be cached in memory across requests. Even though configurations are set dynamically from a template each time (with a possible new key), and the correct key is present just before entering build_index function, the requests still use an outdated key. This appears in the following scenario: First, an incorrect api key is used, which results in an 401 error as expected. The next time a correct key is used, which still results in the same error showing an preview of the previous incorrect key. Logging the settings going into build_index shows the intended key.

My configuration explicitly sets caching to "none", but the documentation is unclear on whether this affects the overall caching behavior of the LLM client. Restarting the FastAPI server clears the issue, suggesting that the key is being held in memory rather than being refreshed dynamically. This might also be related to the use of the fnllm library as far as I understand.

Steps to reproduce

No response

Expected Behavior

No response

GraphRAG Config Used

# Paste your config here

Logs and screenshots

No response

Additional Information

  • GraphRAG Version:
  • Operating System:
  • Python Version:
  • Related Issues:
@LennartSchmidtKern LennartSchmidtKern added bug Something isn't working triage Default label assignment, indicates new issue needs reviewed by a maintainer labels Mar 20, 2025
@natoverse
Copy link
Collaborator

This is by design. It's not explicitly a caching issue (your key is not written to the cache), but is related to the cache and to threading. We use a singleton ModelFactory to register model instances so we can manage rate limiting with parallel API calls. The instance name is hard-coded per workflow step ("extract_graph" for example) to ensure the cache instance matches between runs. So this should be a first-one-wins situation, which is validated in your notes. I'll put it in the backlog to investigate a different approach, but we may not be able to get to it for awhile.

@natoverse natoverse added enhancement New feature or request backlog We've confirmed some action is needed on this and will plan it and removed bug Something isn't working triage Default label assignment, indicates new issue needs reviewed by a maintainer labels Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog We've confirmed some action is needed on this and will plan it enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants