Skip to content

Resolve OpenAI ApiKey for every request #3364

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

Closed

Conversation

filiphr
Copy link
Contributor

@filiphr filiphr commented May 28, 2025

I am working on adding some dynamic support for using the OpenAiApi from Spring AI. Reading the ApiKey javadoc, it looks like a great fit for us, since we want to support dynamic resolving of it.

However, I realized that it's value is not resolved on every request, but only once in the constructor when the headers are set.

While adding this to the OpenAiApi I realized that the rest of the Open AI API classes were also not resolving it so I added it there as well.

I did apply the spring format, but I am not sure that the imports are correct. Please let me know if I need to adjust something

@markpollack
Copy link
Member

This is a super important fix! We had some internal users at vmware that were supposed to have an implementation with rotating keys ,but that never materialized in time. Sorry for the oversight and we will get this bug fixed asap.

@ilayaperumalg
Copy link
Member

@filiphr Thanks for the PR! Rebased and merged as 3a527ee

@ilayaperumalg
Copy link
Member

Also, back-ported the changes into 1.0.x via be79b89

@filiphr filiphr deleted the open-ai-dynamic-api-key branch May 30, 2025 09:30
@filiphr
Copy link
Contributor Author

filiphr commented May 30, 2025

Thanks a lot @ilayaperumalg

@ilayaperumalg
Copy link
Member

ilayaperumalg commented May 30, 2025

@filiphr Sorry, I had to revert the changes as the support for setting the http header via OpenAI chat option is broken with this change.

While your PR introduced the right approach to set the API keys for the client requests, we need to investigate and decide how to proceed to support the issue of supporting case which can be replicated via OpenAiChatModelAdditionalHttpHeadersIT#additionalApiKeyHeader

@filiphr filiphr restored the open-ai-dynamic-api-key branch May 30, 2025 12:04
@filiphr
Copy link
Contributor Author

filiphr commented May 30, 2025

Thanks for letting me know @ilayaperumalg. Thanks for letting me know @ilayaperumalg. Those IT tests are a bit tricky to run without an API Key. In any case. I have provided #3398, which should solve that problem as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants