
Baeldung · 5 min readBuilding with LLMs
Using the Official OpenAI Java SDK With Spring AI
Learn how to integrate the official OpenAI Java SDK with Spring AI 2.0, configure credentials, and use ChatClient to summarize support requests. The guide also shows switching to Gemini’s OpenAI‑compatible endpoint and migrating from the deprecated SDK module, helping developers upgrade with minimal code changes.
- Add spring-ai-starter-model-openai dependency and configure API key in application.yml
- Create a ChatClient.Builder service that sets a default system prompt for summarization
- Swap the provider by changing base‑url, model, and reasoning‑effort to use Gemini without code changes