A Spring Boot application demonstrating integration with multiple AI models through OpenRouter API using Spring AI framework.
This project showcases how to build a simple chat application that can:
- Connect to various AI models via OpenRouter
- Process and handle multimedia files in prompts
- Provide a RESTful API endpoint for interacting with AI models
- Java 21
- Spring Boot 3.4.4
- Spring AI 1.0.0-M6
- OpenRouter API (providing access to models like Meta Llama 4 Maverick and Google Gemini 2.5 Pro)
└── src
├── main
│ ├── java
│ │ └── vn/cloud/spring_ai_openrouter_demo
│ │ ├── ChatClientConfiguration.java - Configures the ChatClient bean
│ │ ├── ChatController.java - REST API endpoint for chat interactions
│ │ ├── JacksonConfiguration.java - Jackson JSON parser configuration
│ │ └── SpringAiOpenrouterDemoApplication.java - Main application class
│ └── resources
│ └── application.yml - Application configuration properties
└── test
└── java
└── vn/cloud/spring_ai_openrouter_demo
└── SpringAiOpenrouterDemoApplicationTests.java - Basic context load test
- REST API Endpoint: Send questions and files to AI models via a POST request
- Multi-Model Support: Configure different AI models through application.yml
- Multimedia Support: Upload and process files alongside text prompts
- High File Size Limits: Configured to handle files up to 20MB
- Java 21 or higher
- Gradle 8.x
- OpenRouter API key
- Open
src/main/resources/application.yml - Replace
{ OPEN_ROUTER_API_KEY }with your actual OpenRouter API key - Optionally change the model configuration:
model: google/gemini-2.5-pro-exp-03-25:free # or uncomment to use: # model: meta-llama/llama-4-maverick:free
./gradlew clean build./gradlew bootRunOr after building:
java -jar build/libs/spring-ai-openrouter-demo-0.0.1-SNAPSHOT.jarSend a POST request to /chat with:
question: The text prompt to send to the AI modelfiles: Optional files to include with the prompt (supports multiple files)
curl -X POST http://localhost:8080/chat \
-F "question=Describe what you see in this image" \
-F "files=@/path/to/your/image.jpg"- Set request type to POST
- URL: http://localhost:8080/chat
- Body: form-data
- Key: question, Value: "Describe what you see in this image"
- Key: files, Value: [select file], Type: File
This project uses standard Spring Boot development practices. You can import it into any IDE that supports Gradle projects.
This project is open source and available under the MIT License.