This project demonstrates how to easily integrate OpenRouter with Spring AI for simple chat-based interactions using a REST API.
- Minimal Spring Boot setup using
spring-ai-openai-spring-boot-starter
- Preconfigured for use with OpenRouter-compatible models (e.g.
deepseek-chat-v3
) - Just plug in your API key and start interacting
- REST endpoint ready for testing or integration
- Java 17+
- Maven (but you can easily use Gradle instead)
- An OpenRouter API key
Insert your OpenRouter API key:
Open src/main/resources/application.yml and replace {Api-Key} with your actual API key:
spring:
ai:
openai:
api-key: your-api-key-here
base-url: https://openrouter.ai/api
chat:
options:
model: deepseek/deepseek-chat-v3-0324:free
Main.java
– Spring Boot application entry pointConfig.java
– Configures the Spring AIChatClient
Controller.java
– REST controller that handles prompt requestsTextFromUser.java
– Simple DTO for user inputapplication.yml
– Configuration file for connecting to OpenRouter