If your Spring AI stream responses are stopping or timing out at exactly 60 seconds, the issue is almost always a configuration conflict between Spring AI and Spring Boot versions. This guide shows you how to diagnose and fix the timeout by verifying your dependencies and updating the correct configuration property. You need a Spring AI project using streaming chat responses.
What You'll Need
- A Spring Boot project with Spring AI dependencies (e.g.,
spring-ai-openai-spring-boot-starter). - Access to your project's
pom.xml(Maven) orbuild.gradle(Gradle) file. - Your IDE or a terminal to run commands and check versions.
Step-by-Step
- Identify Your Spring AI and Spring Boot Versions. Open your project's build file. For Maven, check the
<parent>tag for the Spring Boot version (e.g.,<version>3.2.5</version>). Then find the Spring AI starter dependency version. For Gradle, check thepluginsblock orextset for Spring Boot and the version number on the AI dependency line. Write these two numbers down. - Check Version Compatibility. The 60-second timeout is a known issue in specific version combinations, often when an older Spring AI version is used with a newer Spring Boot version. Visit the official Spring AI project page or your AI provider's (OpenAI, Azure OpenAI, etc.) Spring AI documentation. Look for a compatibility matrix that lists which Spring AI version is designed for your Spring Boot version. If your versions are mismatched, proceed to the next step.
- Update Your Dependencies. Based on the compatibility chart, update your Spring AI dependency version in your build file to the correct one for your Spring Boot version. For example, you might change
<version>0.8.1</version>to<version>0.8.2</version>. Save the file and refresh your project's dependencies (in IDE, use Maven/Gradle reload; in terminal, runmvn clean compileorgradle build --refresh-dependencies). - Configure the Correct Timeout Property. After ensuring compatible versions, you must set the right timeout property in your
application.propertiesorapplication.ymlfile. The property changed between early and later versions of Spring AI. For Spring AI versions 0.8.1 and later, use:spring.ai.openai.chat.options.timeout=60s(or a longer duration like120s). For versions before 0.8.1, the property was:spring.ai.openai.chat.timeout=60s. Using the wrong property name will have no effect. - Test the Stream. Run your application and trigger a stream chat request that you expect to take longer than 60 seconds to complete (e.g., a complex query requesting a long-form response). Monitor the response. If correctly configured, the stream should continue beyond the 60-second mark until the AI model finishes its response or until your new, longer timeout value is reached.
- Verify Network and Provider Timeouts (If Issue Persists). If the stream still stops, the issue might be upstream. Check your AI provider's own timeout settings. For instance, OpenAI has its own server-side timeout. Also, ensure your network proxy or firewall isn't terminating long-lived connections. Review any logging for connection reset or read timeout errors that originate from the HTTP client, not the Spring AI layer.
Common Mistakes
Using an incorrect or outdated property name for the timeout is the most frequent error. Developers often find the old property online and copy it into a new project without realizing the property key changed. Another common mistake is updating the Spring Boot version without updating the Spring AI version to match, which introduces hidden incompatibilities. Finally, setting the timeout in the wrong place—it should be in the global application.properties or in the ChatOptions builder when creating a request—can also cause the setting to be ignored.
Tips
Always consult the official Spring AI reference documentation for your specific version, as APIs and properties evolve rapidly. Use your IDE's property autocomplete feature to see valid property names, which helps avoid typos. When increasing the timeout, consider your application's scalability and user experience; very long timeouts can hold up server resources. For debugging, enable debug logging for the HTTP client (logging.level.org.springframework.web.client=DEBUG) to see the raw request and response timing details.
Troubleshooting
If the stream still cuts off at 60 seconds after following the steps above, work through this checklist. First, double-check that your property change was applied by printing all properties at startup or checking the /actuator/env endpoint if you have Actuator enabled. Second, ensure you are not setting the timeout in both code and properties, where a code configuration might be overriding your property file. Third, examine the full stack trace of any error. If you see a SocketTimeoutException or ReadTimeoutException from the underlying HTTP client (like the Java HttpClient or Apache HttpClient), it confirms the timeout is happening at the network layer, validating that your property is being used but might need a higher value. Fourth, try isolating the issue by creating a minimal test project with just the AI dependency and a simple streaming controller to rule out other project-specific configurations. Fifth, if you are behind a corporate proxy or load balancer, these often have their own idle connection timeouts (commonly 60 seconds) that can interrupt streams; you may need to involve your network team.
Frequently Asked Questions
Why does the timeout happen at exactly 60 seconds?
This is typically the default read timeout set by the underlying HTTP client used by Spring AI. If you do not explicitly configure a longer timeout, the client will close the connection after 60 seconds of inactivity on the stream.
Can I set the timeout to be unlimited?
Technically, you can set a very high value like 3600s (one hour), but it is not advisable. Setting an extremely long timeout can tie up server threads indefinitely, leading to resource exhaustion. It's better to design your application to handle reasonable timeouts and implement a retry or chunking strategy for very long tasks.
I'm using Azure OpenAI or another provider. Is the property the same?
The property structure is similar but uses a different prefix. For Azure OpenAI, the property would be spring.ai.azure.openai.chat.options.timeout. Always check the provider-specific configuration properties in the Spring AI documentation.
Do I need to configure both connect timeout and read timeout?
For streaming, the read timeout is the critical one, as it governs how long the client waits for new data on an established connection. The connect timeout (for establishing the initial connection) is separate and usually much shorter. Spring AI's timeout property in chat options typically sets the read timeout.
Will this fix work for non-streaming (regular) API calls?
Yes, the same timeout property applies to both streaming and non-streaming calls. A non-streaming call that takes longer than the timeout will simply throw a timeout exception.
I updated the version, but now I get compilation errors.
This indicates a breaking API change between Spring AI versions. You must also update your code to match the new API. Refer to the migration guide or release notes for the specific Spring AI version you upgraded to for instructions on updating deprecated classes or method calls.