Skip to content

Demonstrates how Spring AI can be easily configured to work with OpenRouter by adding a single starter dependency. No additional code changes are required — just plug in your API key and start interacting with multiple LLMs through a unified OpenAI-compatible interface. Ideal for experimenting with and evaluating different models effortlessly.

License

Notifications You must be signed in to change notification settings

AI-Agent-Java-Fun/spring-ai-openrouter-how-to-use

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring AI + OpenRouter Integration Example

This project demonstrates how to easily integrate OpenRouter with Spring AI for simple chat-based interactions using a REST API.

✨ Features

  • 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

🔧 Requirements

  • Java 17+
  • Maven (but you can easily use Gradle instead)
  • An OpenRouter API key

🚀 Getting Started

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

🧩 Project Structure

  • Main.java – Spring Boot application entry point
  • Config.java – Configures the Spring AI ChatClient
  • Controller.java – REST controller that handles prompt requests
  • TextFromUser.java – Simple DTO for user input
  • application.yml – Configuration file for connecting to OpenRouter

About

Demonstrates how Spring AI can be easily configured to work with OpenRouter by adding a single starter dependency. No additional code changes are required — just plug in your API key and start interacting with multiple LLMs through a unified OpenAI-compatible interface. Ideal for experimenting with and evaluating different models effortlessly.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages