DEV Community

Rohit Srivastava
Rohit Srivastava

Posted on

Spring AI for Skeptical Engineers

Spring AI Is Not an OpenAI Wrapper🚫

Most people meet Spring AI through a five-line demo: add a starter, inject a client, ask a question, get an answer. It looks like a thin convenience layer over a model provider's API.

That reading misses the point, and it leads to bad adoption decisions in both directions: teams that over-trust it and teams that dismiss it.

This article is the foundation for why Spring AI exists, where it came from, what its parts are, how a request flows through it, and where it fits and doesn't.


1. Why it exists

Most enterprise backends run on the JVM, but much of the early generative AI tooling was built Python-first. A Java team that wanted to add an LLM feature faced a few problems:

  • Every provider has its own SDK, request shape, and streaming behavior. Code written against one is expensive to move.
  • AI features need the same plumbing as any other feature: configuration, dependency injection, retries, metrics, tracing, testing. Re-inventing this around a raw HTTP client is wasteful.
  • The real work isn't the model call. It's everything around it: pulling in your own data, turning free-text output into typed objects, letting the model trigger your business logic, and keeping conversation state.
  • Running a separate Python service is a valid answer, but it adds a new runtime, deployment pipeline, and team skill set.

Spring AI's stated goal is to connect enterprise data and APIs with AI models using the conventions Spring developers already know: auto-configuration, starters, portable abstractions, and POJOs.


2. Where it came from

The project's own documentation says it was inspired by Python projects such as LangChain and LlamaIndex, but is not a direct port. The bet is that the next wave of AI applications won't be Python-only.

Period Milestone What it meant
2023 Project starts as an experimental Spring project Early design work, fast-changing, no stability promise
Early 2024 0.8.x public releases First versions teams could try. Core abstractions for chat, embeddings, and vector stores.
Late 2024 to spring 2025 1.0.0 milestones (M1 to M8) and release candidates Heavy iteration. The ChatClient fluent API, Advisors, a reworked tool-calling model, and renamed starter artifacts.
May 2025 1.0.0 GA The first generally available release, and the point where it became reasonable to build on

Why the history matters to you: if you search for Spring AI tutorials, a lot of what you find was written against pre-1.0 versions. Class names, starter artifact names, and tool-calling APIs changed along the way, so old snippets frequently don't compile on current versions. When in doubt, check the version in the tutorial's pom.xml first.


3. What it is: a map of the pieces

Think of it as a set of Spring-style abstractions, not one library. Each has an analogy you probably already know.

Piece What it does Spring analogy
Model abstractions (chat, embedding, image, and others) A common interface over many providers DataSource / JDBC: one API, many vendors
ChatClient Fluent API to build a prompt, call a model, and read the result WebClient / RestClient
Prompt templates Parameterized prompts kept out of business code Template engines
Structured output Map model text into typed Java objects Jackson and message converters
Tool calling Let the model request that your app run a Java method A controller the model can ask to invoke
Advisors Intercept requests and responses to add behavior Servlet filters / AOP interceptors
Chat memory Keep conversation context across calls Session storage
Embeddings + VectorStore Store and search text by meaning Spring Data repositories over many stores
Document ingestion (ETL) Read, split, embed, and load your data A batch pipeline
Observability Metrics and tracing around model calls Micrometer
Auto-configuration and starters Wire it all from properties and dependencies Spring Boot itself

One idea to hold on to: the model never runs anything. In tool calling, it returns a request ("call this method with these arguments"), and your application decides whether to execute it. That detail drives the security discussion in the next post.


4. How one call flows

Conceptually, a single request moves like this:

  1. Your code builds a request through ChatClient: a system instruction, the user's message, and optionally tools and options.
  2. Advisors run in order, each able to read or change the request. Typical jobs: attach memory, retrieve documents, redact data, log.
  3. The request is translated into the chosen provider's format and sent to the model.
  4. The model responds with text, or with a request to call one of your tools.
  5. If a tool is requested, the framework runs your method, sends the result back to the model, and repeats until the model produces a final answer.
  6. The response travels back through the advisors, then is returned as raw text or converted into a typed object.

Spring AI is Spring's answer to a specific problem: putting LLMs inside existing Java services without rewriting everything around one provider's SDK. Like JdbcTemplate or Spring Data, the abstraction is valuable until it leaks. Knowing where it leaks is the skill.

5. Where the abstraction leaks

Every abstraction leaks, and with LLMs the leaks are bigger than with databases.

  • ⚠️Portable API does not mean portable behavior. Swapping a provider is easy in configuration. But the same prompt can produce different quality, different tool-calling reliability, and different structured-output accuracy on different models. Plan to re-test, not just re-configure.
  • ⚠️Model capabilities differ. Not every model supports tool calling, structured output, or streaming equally. The framework can't add a capability the model lacks.
  • ⚠️Provider-specific options still exist. Some useful features live only in one provider's options, and using them reduces your portability.
  • ⚠️Behavior is non-deterministic. No framework can make an LLM predictable. Lower temperature reduces variance but doesn't remove it.
  • ⚠️The framework moves quickly. Even after 1.0, the AI ecosystem changes fast. Expect new features and occasional deprecations, so pin versions and read release notes.
  • ⚠️Defaults aren't policies. Auto-configuration gives you a working setup, not a safe, cost-controlled, or compliant one.

6. Where it fits, and where it doesn't

Option Good when Watch out for
Spring AI You're a Spring shop adding AI features to existing services and want familiar configuration, testing, and observability Younger API surface, and you inherit the abstraction's leaks
Provider's own Java SDK You're committed to one provider and need its newest features immediately Lock-in, and you rebuild glue like memory, tools, and retrieval yourself
LangChain4j You want a mature, Java-native alternative, possibly outside Spring, or prefer its programming model Different abstractions and conventions. Evaluate it against your needs.
A separate Python service Your team already has Python AI expertise, or you need Python-only libraries Extra runtime, deployment, network hop, and ownership split
No framework (plain HTTP) A single, simple call with no tools, memory, or retrieval You'll slowly rebuild a framework as requirements grow

A rule of thumb: if your AI feature is one prompt in and one answer out, a framework may be overkill. If it needs tools, retrieval, memory, observability, and several providers over time, the framework starts paying for itself.


7. Questions to ask before adopting

  1. Which actions should the model be allowed to trigger, and which must never be reachable from it?
  2. What data would leave our network, and does our provider contract allow it?
  3. How will we measure cost and quality over time, not just whether it works today?
  4. What happens when the provider is slow, down, or changes model behavior?
  5. If we had to switch providers, what would we need to re-test?

What's next

The next post moves from concepts to practice, starting with one of the biggest risks in this list: letting a model call your business logic safely.

Corrections welcome. If something here is out of date for the version you're using, tell me in the comments.👇

Top comments (0)