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 |
More Related questions...