Integrating Tencent HunYuan with Spring AI 1.0.0 Using a Custom Starter

Background and Compatibility

Users relying on the 1.0.0-M6 milestone release from Maven Central have reported various runtime exceptions and compatibility mismatches. To address this, the community starter spring-ai-hunyuan has been refactored to align with the official Spring AI 1.0.0 stable release. The updated source code is available here: spring-ai-hunyuan GitHub Repository.

The current build supports the following capabilities:

  • Chat Client: Includes streaming responses and multimodal input (image understanding).
  • Embeddings: Generation of text vectors for semantic search or RAG implementations.

Prerequisites

  • Java Development Kit (JDK) 17 or higher
  • Apache Maven 3.8+
  • Tencent Cloud Account with valid API credentials (SecretId and SecretKey)

Project Configuration

Add the following dependency to your pom.xml to include the HunYuan starter in your Spring Boot application:


<dependency>
    <groupId>io.github.studiousxiaoyu</groupId>
    <artifactId>spring-ai-starter-model-hunyuan</artifactId>
    <version>1.0.0</version>
</dependency>

Application Properties

Configure the authentication and model settings in application.yml (or application.properties):


spring:
  ai:
    hunyuan:
      secret-id: "YOUR_TENCENT_SECRET_ID"
      secret-key: "YOUR_TENCENT_SECRET_KEY"
      chat:
        options:
          model: "hunyuan-pro"
      embedding:
        options:
          model: "hunyuan-embedding"
          dimensions: 1024

Implementation Examples

Below is a service class implementation that utilizes the ChatClient to interact with the model:


@Service
public class AiAssistantService {

    private final ChatClient conversationalClient;

    public AiAssistantService(ChatModel model) {
        this.conversationalClient = ChatClient.create(model);
    }

    public String generateResponse(String userInput) {
        return conversationalClient.prompt()
                .user(userInput)
                .call()
                .content();
    }
}

Here is a REST contrloler to expose the AI functionality via an HTTP endpoint:


@RestController
@RequestMapping("/api/v1/assistant")
public class AssistantController {

    private final AiAssistantService assistantService;

    public AssistantController(AiAssistantService assistantService) {
        this.assistantService = assistantService;
    }

    @GetMapping("/reply")
    public String getReply(@RequestParam("query") String query) {
        return assistantService.generateResponse(query);
    }
}

Verificcation

After launching the Spring Boot application, you can test the integration using a browser or curl:

http://localhost:8080/api/v1/assistant/reply?query=Hello

You should receive a response generated by the HunYuan Pro model.

To switch models, simply modify the spring.ai.hunyuan.chat.options.model property in your configuration file.

Tags: Spring AI Spring Boot Tencent HunYuan java Maven

Posted on Thu, 18 Jun 2026 18:03:22 +0000 by Gho