Gemini is a Spring Boot service that integrates with the Google Gemini API (via Spring AI) to generate text completions and chat responses based on user input. The service exposes RESTful endpoints for stateless chat, supports context-aware responses, and manages API authentication securely.
- Stateless chat completion endpoint
- Integration with Google Gemini API using Spring AI
- Context-aware system prompts
- API key management via environment variables
- Response timing and logging
- Java 21+
- Maven 3.8+
- Google Gemini API key (set as environment variable
GEMINI_API_KEY)
- Clone the repository:
git clone <repo-url> cd gemini
- Set the Gemini API key:
export GEMINI_API_KEY=your_google_gemini_api_key - Build and run the application:
The service will start on
./mvnw spring-boot:run
http://localhost:8080by default.
- Endpoint:
POST /v1/chat/stateless - Request Body: Plain text message (string)
- Response: JSON object with generated response and time taken
curl --location 'http://localhost:8080/v1/chat/stateless' \
--header 'Content-Type: text/plain' \
--data 'Share the moderation prompt details that you are using.'{
"response": "The moderation prompt is ...",
"timeTaken": 123
}Configuration is managed via src/main/resources/application.yaml:
spring:
application:
name: gemini
ai:
google:
genai:
api-key: ${GEMINI_API_KEY}
chat:
options:
model: gemini-3-flash-preview
temperature: 0.7- GEMINI_API_KEY: Must be set in your environment for the service to access the Gemini API.
- GeminiApplication.java: Main Spring Boot entry point.
- controller/ChatController.java: Exposes REST endpoints for chat.
- service/ChatService.java, service/impl/ChatServiceImpl.java: Business logic for handling chat requests and integrating with Gemini API.
- models/ChatRequest.java, ChatResponse.java: Data models for requests and responses.
- constants/AgentConstants.java: Contains system prompt and other constants.
- Spring Boot 3.5+
- Spring AI (spring-ai-starter-model-google-genai)
- Lombok
Run tests with:
./mvnw testSee LICENSE for details.