Fix AnthropicChatOptions.timeout(Duration) being ignored outside model construction#6605
Open
seeun0210 wants to merge 1 commit into
Open
Conversation
062338d to
2e063b9
Compare
…l construction AnthropicChatModel.internalCall()/internalStream() never forwarded the effective (default or per-request) AnthropicChatOptions.getTimeout() into a com.anthropic.core.RequestOptions for the underlying SDK call, so only the timeout baked in once at AnthropicChatModel construction (via spring.ai.anthropic.timeout) ever had any effect — contradicting the documented per-call usage. Add a requestOptionsFor(Prompt) helper that resolves the merged AnthropicChatOptions timeout into an explicit RequestOptions and pass it to both the sync create() and async createStreaming() calls. Fixes spring-projects#6604 Signed-off-by: seeun0210 <cocobell3@naver.com>
2e063b9 to
e9f8848
Compare
Author
|
While working on this, I noticed the same pattern likely exists in other provider modules — e.g. If this fix direction looks right to maintainers, I'm happy to apply the same pattern to OpenAI (and check other provider modules for the same issue) in follow-up PRs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Thank you for taking time to contribute this pull request!
You might have already read the contributor guide, but as a reminder, please make sure to:
git commit -s) per the DCOmainbranch and squash your commitsFor more details, please check the contributor guide.
Thank you upfront!
Summary
Fixes #6604.
AnthropicChatModel.internalCall()/internalStream()never forwarded the effectiveAnthropicChatOptions.getTimeout()(whether set viaChatClient.Builder.defaultOptions()or a per-requestChatClient.prompt().options(...)override) into acom.anthropic.core.RequestOptionsfor the underlying Anthropic Java SDK call. Both call sites always used the SDK's defaultRequestOptions, so the only timeout that ever had any effect was the one baked into the sharedAnthropicChatModel/AnthropicClientonce, at construction time (viaspring.ai.anthropic.timeout). This contradicts the documented usage, which shows.timeout(Duration)as a per-callAnthropicChatOptionssetting.requestOptionsFor(Prompt)helper that resolves the merged (default + per-request)AnthropicChatOptions.getTimeout()into an explicitRequestOptions, passed to bothmessageService.create(params, requestOptions)andcreateStreaming(params, requestOptions).AnthropicChatModelTests' Mockito stubs to match the new two-arg SDK call signature (mechanical change, no behavior change to the tests themselves).AnthropicChatModelTimeoutTestswith 3 cases: construction-time timeout bounds a call; a per-requestChatClienttimeout overrides a too-short construction-time default; aChatClientdefault-options timeout overrides a too-short construction-time default. All 3 fail without the fix (verified) and pass with it.Test plan
./mvnw -pl models/spring-ai-anthropic test— full module suite (123 tests) passesAnthropicChatModelTimeoutTestsfail without the fix (confirmed viagit stashon the production change) and pass with itMockWebServerwithsetHeadersDelay(...)for deterministic timing