Skip to content

Conversation

@priyanshu6238
Copy link
Contributor

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.py or docker compose up in 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.

@codecov
Copy link

codecov bot commented May 11, 2025

Codecov Report

Attention: Patch coverage is 20.00000% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
backend/app/api/routes/threads.py 11.11% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

@AkhileshNegi
Copy link
Collaborator

cherry picked it here
#179

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.

2 participants