Spring Boot middleware service that acts as a bridge between the user and a Large Language Model (LLM) via OpenRouter. Supports personalities, session-based conversation memory, retry logic, and structured error handling.
- Java 25
- Maven (or use the included
./mvnwwrapper) - An OpenRouter API key (free account works)
- Go to openrouter.ai and sign up
- Navigate to Keys in the menu
- Create a new key and copy it
-
Clone the repository:
git clone https://github.com/viktorlindell12/ai-spring-middleware.git cd ai-spring-middleware -
Set your API key as an environment variable:
macOS/Linux:
export OPENROUTER_API_KEY=your-key-hereWindows (PowerShell):
$env:OPENROUTER_API_KEY="your-key-here"
Windows (CMD):
set OPENROUTER_API_KEY=your-key-here
-
Start the application:
./mvnw spring-boot:run
The application starts on http://localhost:8080.
Send a message to the LLM using one of the available personalities.
Request body:
{
"personality": "coder",
"message": "How do I write a for-loop in Java?",
"sessionId": "user-123-abc"
}| Field | Type | Required | Description |
|---|---|---|---|
| personality | String | Yes | helper, coder, or pirate |
| message | String | Yes | The user's message |
| sessionId | String | No | Reuse to continue a conversation |
Example response:
{
"response": "A for-loop in Java looks like this: for (int i = 0; i < 10; i++) { ... }"
}A simple chat interface is available at http://localhost:8080. Select a personality and start chatting directly in the browser.
Interactive API documentation is available at http://localhost:8080/swagger-ui.html.
./mvnw testIncludes WireMock integration tests that verify successful requests, retry behaviour on 429, and error handling on 500.