Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

How does Spring AI let you switch between model providers such as OpenAI, Anthropic, Ollama and Amazon Bedrock? What changes in code and configuration, and what does not stay the same?

Each provider has its own Spring Boot starter that auto-configures a ChatModel from spring.ai.<provider>.* properties, and our code talks to ChatClient, advisors and tools, which sit on top of whatever ChatModel is injected. So switching is mostly a dependency and configuration change. What does not stay the same is the model's behaviour and capabilities: model names, token limits, option ranges, tool calling, structured output, multimodal input and price all differ, and prompts usually need tuning, so a switch compiles easily but still needs testing.

Why this question is asked

Few teams stay with their first model provider. Prices drop, a new model does better on a task, a customer requires data to stay in a particular cloud, or developers want to run models locally. Spring AI is designed so that this does not mean rewriting the application. Interviewers ask this question to check that we know both halves of the truth: the code really is portable, and the behaviour really is not. In this answer, we will look at the layers Spring AI uses, what changes when we switch from OpenAI to Anthropic, Ollama or Bedrock, what differs between providers even when the code is the same, and why prompts need retuning.

1The Layers That Make Switching Possible

Spring AI separates the code we write from the code that talks to a provider. At the bottom, each provider module implements the ChatModel interface: one class turns a Prompt into an HTTP request for OpenAI, another for Anthropic, another for Ollama. Above it, ChatClient gives us the fluent API we use every day, and advisors and tools plug into ChatClient. Our services only see ChatClient, so they never mention a provider.

Step throughWhat our code sees and what changes
  1. Our servicesChatClient calls, prompts, tools: unchanged
  2. ChatClient, advisors, toolsSpring AI common API: unchanged
  3. ChatModel beanOpenAI, Anthropic, Ollama or Bedrock implementation
  4. Starter and propertiesthe part we edit to switch
  5. Provider APIdifferent models, limits and prices

5 layers, from the top down. Step through them one at a time.

Spring Boot connects the layers. Each provider has a starter, a dependency that brings the provider module and its auto-configuration. When the application starts, the auto-configuration reads properties under spring.ai.<provider>, such as spring.ai.openai.api-key, and creates the ChatModel bean. The ChatClient.Builder we inject is then built on that ChatModel.

2What Changes in the Build and the Configuration

Switching from OpenAI to Anthropic means replacing one starter with another and moving the properties. The starter names were changed at the 1.0 release, for example from spring-ai-openai-spring-boot-starter to spring-ai-starter-model-openai, so check the names for your version, and use the spring-ai-bom to keep all Spring AI modules on the same version.

XML
<!-- before -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-openai</artifactId>
</dependency>
<!-- after -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-anthropic</artifactId>
</dependency>
# before
spring.ai.openai.api-key=${OPENAI_API_KEY}
spring.ai.openai.chat.options.model=<openai model name>
# after
spring.ai.anthropic.api-key=${ANTHROPIC_API_KEY}
spring.ai.anthropic.chat.options.model=<anthropic model name>
spring.ai.anthropic.chat.options.max-tokens=1024

The service code does not change at all.

3What Stays the Same in Code

Here is a typical service. It does not import anything provider-specific, so it runs unchanged on any of the four providers.

Java
@Service
class FaqService {
private final ChatClient chatClient;
FaqService(ChatClient.Builder builder) {
this.chatClient = builder.defaultSystem("You answer questions about our return policy.").build();
}
String answer(String question) {
return chatClient.prompt().user(question).call().content();
}
}
// OpenAI: "You can return items within 30 days..."
// Anthropic: "Items can be returned within 30 days of delivery..." <- same code, different wording

Notice the comment on the last line. The code is the same, but the answer is not identical. That is the first hint that switching is not free.

4What Does Not Stay the Same

The common API covers what all providers share. Everything else is still different underneath, and some of it shows up in production. Model names are provider-specific and live in configuration. Token limits differ: context windows, maximum output tokens, and whether max-tokens is required (Anthropic's API requires it on every request). Option ranges differ, for example the allowed temperature range. Tool calling and structured output are supported by most current models but not all, and native JSON schema modes differ in what they accept. Multimodal input such as images is available only on some models, with different size limits. And prices per input and output token can differ by ten times or more between models.

Provider-specific options are available through classes such as OpenAiChatOptions or AnthropicChatOptions. Each time we use one, we tie that piece of code to a provider again, so we keep such options in configuration where we can.

Same code, different providers
AspectWhat differs
Model namesprovider-specific, set in properties
Limitscontext window, max output tokens, required max-tokens
Optionstemperature range, provider-only options classes
Featurestool calling, JSON schema mode, image input
OperationsAPI keys vs cloud identity, regions, rate limits
Priceper input and output token, can differ 10x or more

5Ollama and the Cloud Platforms

Ollama runs open-weight models on our own machine or server. With the Ollama starter, spring.ai.ollama.base-url points at it (http://localhost:11434 by default) and we choose a model that has been pulled locally. It is popular for development without API keys, for tests, and for private deployments where data must not leave our network. The models are usually smaller, so quality and speed differ from the hosted frontier models.

Amazon Bedrock and Azure OpenAI offer models inside a cloud platform. The difference there is mostly operational: authentication uses the cloud's identity (IAM roles on AWS, Entra ID or keys on Azure), we pick a region, and the data stays under the cloud contract the company already has. For many enterprises those controls are the reason to use them, even when the same model family is available directly.

6Why Prompts Need Tuning After a Switch

Models are trained differently, so they react differently to the same instructions. One model follows a long system prompt closely, another needs the key rule repeated near the question. One returns valid JSON with a short instruction, another needs an example. A prompt tuned over months for one model will often score lower on another until it is adjusted. So we treat a provider switch like any other behaviour change: we keep an evaluation set of real questions with expected answers, run it on the new provider, tune the prompts, and only then switch traffic.

7Follow-up questions

What would you test before switching providers in production?

Run our evaluation set on the new model and compare scores with the current one, then test the specific features we depend on: structured output on all our entity types, tool calling with our tools, long inputs near the context limit, streaming, and error handling such as rate limit responses. Measure latency and cost on realistic traffic. Finally, move a small share of real traffic first, compare metrics and user feedback, and keep the old provider configured for a quick rollback.

Can I have two providers in the same application?

Yes. Add both starters and inject the specific ChatModel beans, building a ChatClient for each. Because two ChatModel beans exist, the single auto-configured ChatClient.Builder may become ambiguous, so we usually disable it and build clients explicitly.

Do embeddings move with the chat model?

No. The EmbeddingModel is configured separately, and switching embedding models means re-embedding all stored documents, because vectors from different models are not comparable.

8Conclusion

In this answer, we saw that Spring AI makes switching providers mostly a build and configuration change: each provider's starter auto-configures a ChatModel from spring.ai.<provider> properties, and ChatClient, advisors and tools stay the same in code. What changes is behaviour and capability: model names, limits, options, tool and structured output support, multimodal input, operations and price. Ollama gives local open-weight models, Bedrock and Azure add cloud identity and regional control, and prompts need retuning and testing after any switch.

What to say in the interviewAbout 70 seconds aloud

Open with

Spring AI separates our code from the provider. Each provider has a starter, like spring-ai-starter-model-openai or spring-ai-starter-model-anthropic since 1.0, which auto-configures a ChatModel from spring.ai.<provider> properties: API key, model name, options.

Then, if they want more

My code uses ChatClient, advisors and tools on top of whatever ChatModel is injected, so to switch I change the starter and the properties, and the service code compiles and runs unchanged. What does not stay the same is the model.

Model names, context windows and output limits differ, Anthropic needs max-tokens, temperature ranges differ, tool calling and native structured output are supported differently, image input is only on some models, and prices can differ by ten times. Provider-specific options classes tie code to a provider again, so I keep those in configuration.

Ollama is great for running open-weight models locally or privately, and Bedrock or Azure OpenAI add cloud identity, regions and the existing cloud contract. The big hidden cost is prompts: they are tuned for one model, so before switching I run our evaluation set, test structured output and tools, compare latency and cost, and move traffic gradually.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring AI reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How does Spring AI let you switch between model providers such as OpenAI, Anthropic...": https://scrivio-interview-library.netlify.app/spring-boot/spring-ai/2c2bc7ba03/