1

I have a working Spring AI project, but when I add dependencies for Spring Cloud (such as Eureka or Config Client), I get the following error when invoking the chat client.

Dependencies:

Spring Cloud Dependencies

<spring-ai.version>1.0.0-M6</spring-ai.version>
<spring-cloud.version>4.2.1</spring-cloud.version>

    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    <version>${spring-cloud.version}</version>
</dependency>

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-client</artifactId>
    <version>${spring-cloud.version}</version>
</dependency>

Spring AI Dependency

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>

Version Management

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-bom</artifactId>
            <version>${spring-ai.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Error Log

2025-03-31T20:28:19.393+02:00 ERROR 53666 --- [nio-8084-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.web.client.RestClientException: Error while extracting response for type [org.springframework.ai.openai.api.OpenAiApi$ChatCompletion] and content type [application/json]] with root cause

    com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Object (start marker at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 1])
     at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 2]

Expected Behavior

The chat client should work correctly and return a response from OpenAI, even with Spring Cloud dependencies present.

Troubleshooting Done

The project works fine when Spring Cloud dependencies are removed.

The issue occurs when adding either spring-cloud-starter-netflix-eureka-client or spring-cloud-config-client.

The error suggests a JSON parsing issue, possibly due to an incomplete or malformed response.

Questions

Has anyone encountered compatibility issues between Spring AI 1.0.0-M6 and Spring Cloud 4.2.1?

Could Spring Cloud be interfering with the HTTP client used by Spring AI?

Are there any known fixes or workarounds?

Any help or suggestions would be greatly appreciated! Thanks in advance.

4
  • 1
    Have you checked that the raw response (REDACTED) of the AI actually contains JSON? These AI models are known to sometimes not follow the requested JSON schema and answer with plain text or invalid JSON. Maybe it's a coincidence that this happened when you added a Spring Cloud library. Commented Mar 31 at 19:36
  • Hi, thanks for the suggestion. I can confirm that the issue only occurs when both Spring Cloud and Spring AI libraries are present. I've run several tests, and I can confidently say that the malfunction is caused by the simultaneous presence of the two libraries. Commented Apr 5 at 17:20
  • I'm facing the same issue, it seems to be really a dependency incompatibility issue. Commented Oct 12 at 17:24
  • I tried several versions, but it only works when I remove spring-cloud-starter-netflix-eureka-client. Commented Oct 12 at 17:32

1 Answer 1

1

I got around the problem in the following way:

@Bean
public OpenAiApi openAiApi() {
    HttpClient httpClient = HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).build();
    JdkClientHttpRequestFactory jdkClientHttpRequestFactory = new JdkClientHttpRequestFactory(httpClient);

    return OpenAiApi.builder()
      .apiKey(this.apiKey)
      .baseUrl(this.baseUrl)
      .restClientBuilder(
        RestClient.builder()
          .requestFactory(jdkClientHttpRequestFactory)
      ).build();
};

Credits to: https://github.com/spring-projects/spring-ai/issues/2653#issuecomment-2783528029

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.