Spring / Spring AI interview questions
What is the difference between ChatModel and ChatClient in Spring AI?
ChatModel and ChatClient exist at different levels of the Spring AI abstraction stack and serve different audiences in the same codebase.
ChatModel is the low-level provider-facing interface. It accepts a Prompt object (a list of Message objects plus optional inference options) and returns a ChatResponse. Every provider integration implements this interface — OpenAI's implementation, Anthropic's implementation, and so on. You would interact with ChatModel directly if you are writing a provider plugin, performing low-level tests, or need granular control over the raw response metadata.
ChatClient is the high-level developer-facing fluent API. It sits on top of ChatModel and adds convenience: system prompts, user messages, advisor chains, streaming, structured output, and function calling — all wired with a readable builder chain. Most application code never touches ChatModel directly.
| Aspect | ChatModel | ChatClient |
|---|---|---|
| Level | Low-level SPI | High-level fluent API |
| Input | Prompt object | .user() / .system() builder methods |
| Output | ChatResponse | .call().content() or .call().entity() |
| Advisors | Not supported directly | Built-in via .defaultAdvisors() |
| Structured output | Parse manually | .call().entity(MyClass.class) |
| Typical use | Provider authoring, low-level tests | All production feature code |
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
