Credentials : Use this functionality in threads endpoint #169 #178
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces organization-level API key management by dynamically retrieving the OpenAI API key from the database (credentials table) based on the currently authenticated user's organization. It replaces the use of the global settings.OPENAI_API_KEY, enabling secure and scalable multi-tenant support.
Benefits
Multi-tenancy Ready: Each organization can now use its own OpenAI key, improving data isolation and tenant-specific billing or rate limits.
Security: Eliminates reliance on a single shared API key, reducing the impact of key leakage or misuse.
Flexibility: Supports seamless onboarding of new organizations with custom OpenAI keys without redeploying the service.
Extensibility: The foundation is laid to support multiple providers (e.g., Gemini, Claude) with minimal changes via the existing credential structure.
Ran
fastapi run --reload app/main.pyordocker compose upin the repository root and test.If you've fixed a bug or added code that is tested and has test cases.
Notes
Please add here if any other information is required for the reviewer.