All projects

AI & data

Chatbot API · Spring Boot + OpenAI

A Spring Boot REST API that connects OpenAI’s GPT-4o-mini to a Java backend, without ever exposing the API key in the browser.

  • Individual project
API keys exposed to the browser
0
endpoints: chat and health
2

01Starting point

Context & mission

The problem

Calling an LLM straight from the browser exposes the API key. The right place for that integration is the backend.

The mission

Expose a clean chat endpoint in Java that relays the message to the model and returns a structured reply.

My role

Designed and built on my own.

02Execution

What I did

  1. Chat endpoint

    POST /api/chat receives a message and returns the generated reply as structured JSON.

  2. OpenAI integration

    The service calls GPT-4o-mini through RestTemplate; the key stays server-side.

  3. Layered code

    Separate controller, service, request and response DTOs, and configuration.

  4. Front-end ready

    Health-check endpoint and CORS configuration to plug in a web interface.

03Design

Architecture

The controller receives the request, the service calls the OpenAI API, then builds the response DTO returned to the client.

The path of a message
  1. ClientPOST /api/chat
  2. ChatController
  3. ChatServiceRestTemplate
  4. OpenAIGPT-4o-mini
  5. ChatResponseJSON DTO

04Impact

Results

  • An LLM cleanly integrated into a Java backend.
  • An API ready to serve any front end.

05Wrap-up

Takeaways

What this project proves

That I integrate an LLM in the right place: server-side, behind a clear REST contract.

06Technology

Full stack

  • Java 17
  • Spring Boot 3.4
  • Spring Web
  • RestTemplate
  • Maven
  • OpenAI API
  • GPT-4o-mini