Skip to content

Using Authorization header to specify Openai API key on a per-request basis instead of config.yaml #58

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
Matteo-Frattaroli opened this issue Apr 1, 2025 · 1 comment

Comments

@Matteo-Frattaroli
Copy link

Hello,

first of all kudos: I recently started using memobase, it seems very well designed and it works really well.

For a project of mine, which uses the OSS version of your api server, I was wondering if you have in roadmap a support for specifying OpenAI api keys on a per-request basis.

Exploring the source code i noticed that you (rightly) instantiate a global openai client once and use it only when flushing the memory buffer (but correct me if I'm wrong). I'm just spitballing here, becuase maybe I'm missing somethig, but I was thinking that if, and only if, an Authorization header is specified, a new AsyncOpenAI instance could be created with the specified api key attribute and destroyed in the lifecycle of a single flush request otherwise falling back on the existing global instance.

To avoid excessive dependency injection, as i saw there is a pretty deep chain to go down to the actual request, maybe a context var can be used to store the actual instance to be used for a specific request without major impacts on the code base, performances or on the current functionalities.

If you find this proposal interesting I would be glad to contribute. Let me know what you think!

@gusye1234
Copy link
Contributor

hmmm, can you elaborate more in which case you will need a per-request OpenAI API key? I guess you might have a lot of OpenAI Keys, and you want to rotate them for use?

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

No branches or pull requests

2 participants