-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add RestClient timeout support via spring-ai-autoconfigure-http-client module #2808
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
base: main
Are you sure you want to change the base?
Add RestClient timeout support via spring-ai-autoconfigure-http-client module #2808
Conversation
0dd110e
to
f828a35
Compare
Super thanks. I've been prototyping some things in this direction. Will take a closer look. |
206238b
to
50bab6f
Compare
@markpollack Thanks for the feedback! I’ve added the new spring-ai-autoconfigure-http-client module to the relevant starter pom.xml files where RestClient.Builder is actually used. This ensures that the timeout auto-configuration is available only where it's needed. Please take a look when you have a moment |
Thanks, trying to continue prototyping, you work is super useful, will get back to you asap. |
35f36e9
to
b97f94d
Compare
We are going to be circling back to this now that GA is over! plesae be patient. |
d0fb065
to
c58b1c7
Compare
Hey @markpollack @drow724 . Would this PR solve connection timeout issues? Currently using GRPC as the transport. I have a chat client which kicks off, based on the output of this response, I send this to another chat client. Chat client 1 uses Gemini 2.0 flash. This executes well. Chat client 2 uses Gemini 2.5 pro. Once I enter this chat client, I get a If there is a workaround for this, please let me know. The quality in responses when using Gemini 2.5 pro for my agent is night and day compared to both chat clients using 2.0 flash. |
…ending Boot 3.5+ Signed-off-by: drow724 <[email protected]>
ed022b7
to
a812986
Compare
Hey @RyanHowell30 This PR addresses connection timeout configuration only for HTTP clients that use Spring's RestClient (e.g., OpenAI, Mistral, Ollama, etc.). Since Vertex AI uses gRPC-based transport under the hood via PredictionServiceClient (which in turn uses Netty), the timeout issue you're experiencing (io.netty.handler.timeout.ReadTimeoutException) would need to be addressed through gRPC channel settings, not through this PR. Hope this helps clarify! |
Hi team,
This PR adds support for configuring
RestClient
timeouts via the newspring.ai.http.client.connection-timeout
andspring.ai.http.client.read-timeout
properties.I understand that some of the previous timeout-related contributions were declined with the reasoning that
RestClientCustomizer
is the recommended way to control low-level HTTP behavior. However, I’d like to offer a slightly different perspective based on real-world usage and Spring Boot developer experience.Spring AI clients such as
OpenAiChatModel
internally constructRestClient
usingRestClient.builder()
, which makes it difficult for users to apply timeout settings without defining custom beans. For many users who just want to quickly call ChatGPT or OpenAI endpoints, defining aRestClientCustomizer
bean solely to apply timeout settings is unexpected ceremony.This PR follows the Spring Boot philosophy of externalized configuration with reasonable defaults, enabling users to declare timeout values in
application.yml
without writing additional Java code.A new auto-configuration module (
spring-ai-autoconfigure-http-client
) is introduced to configureRestClientBuilder
viaRestClientCustomizer
. The customizer is registered only if no otherRestClientCustomizer
is defined, using@ConditionalOnMissingBean
, so it’s fully overridable. The timeout values are backed by a simple@ConfigurationProperties
class (SpringAiHttpClientProperties
) to keep things clean and idiomatic.While
WebClient
timeout support would be useful as well, we chose not to include it yet because the most elegant and standardized way to configure timeouts (viaClientHttpConnectorSettings
) is only available in Spring Boot 3.5+. Once Spring AI upgrades its baseline, we plan to extend this same configuration model to supportWebClient
as well.This PR is designed to:
RestClient
implicitly via Spring AI modelsRestClientCustomizer
) without overriding user-defined beansLooking forward to your feedback.