spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

Unable to configure HTTP connect/read timeouts via configuration properties

Open hbsjz-swl opened this issue 10 months ago • 1 comments

Bug description It is currently not possible to configure HTTP connection and read timeouts for interacting with Large Language Models (LLMs) via Spring Boot configuration properties (e.g., in application.properties or application.yml).

Users have to manually define a RestClient or WebClient bean to customize these timeouts, which defeats the purpose of the auto-configuration provided by the Spring AI starters. Relying on the default HTTP client timeouts is often not suitable for production environments where network stability varies.

Environment

Spring AI version: 1.1.2 Java version: 17 OS: Windows / Linux / macOS Starter used: spring-ai-openai-spring-boot-starter Steps to reproduce

Create a Spring Boot project and include spring-ai-openai-spring-boot-starter. Configure the API key in application.yml:

yaml


spring:
  ai:
    openai:
      api-key: sk-...
      # Attempt to set timeouts here 
      chat:
        options:
          connect-timeout: 5s
          read-timeout: 30s

Run a simple chat completion request. Observe that the connection/read timeouts used are the default HTTP client timeouts , not the values intended in the configuration. Expected behavior The Spring AI starters should expose configuration properties to allow users to easily override the default HTTP client timeouts.

Ideally, properties similar to these should be supported:


yaml


spring:
  ai:
    openai: # or anthropic, azure, etc.
      base-url: ...
      api-key: ...
      client:
        connect-timeout: 5s
        read-timeout: 60s

This would allow the auto-configuration to build the underlying RestClient (or WebClient) with the specified timeouts without requiring manual Bean definitions.

hbsjz-swl avatar Feb 04 '26 07:02 hbsjz-swl

Hi @hbsjz-swl, Thanks for reporting! Currently, We expect the HTTP client configuration options provided explicitly via RESTClient and WebClient builders which you can override. There are some discussions related to this in these:

https://github.com/spring-projects/spring-ai/issues/512 https://github.com/spring-projects/spring-ai/pull/4970 https://github.com/spring-projects/spring-ai/pull/2808

Closing this issue for now and we can track from #512

ilayaperumalg avatar Feb 04 '26 08:02 ilayaperumalg