Anthropic Claude vs OpenAI vs Gemini in Spring AI 2.0: Switching Providers and Comparing Cost
You built a feature on one AI provider. Then someone asks the questions every team asks sooner or later: could we try a different one, what would it cost, and what happens when the one we use has a bad afternoon? In Spring AI the answer to the first question is “mostly yes, it is a configuration change”. The word mostly is where the surprises live. This article takes one small application and runs it on OpenAI, Anthropic Claude and Google Gemini through the three real Spring AI model classes. It looks at what each one sends over the wire, which options carry over and which silently do not, how prompt caching differs, what a batch of requests costs on each price sheet, and how to fail over from one provider to the next without multiplying your retries by accident. The depth is in expandable sections, so you can read straight through or open only what you need. Versions, and an honest limit. Spring Boot 4.1.1, Spring AI 2.0.1 and Java 25. The code is the providers module of asmhatre/spring-ai, and every console block below is quoted from a file under its output/ directory. I did not call any vendor’s API; there are no keys in my build environment. The real OpenAiChatModel, AnthropicChatModel and GoogleGenAiChatModel talk to a local server that answers in the three wire formats, so what each client sends and how it reacts to a reply or an error is real. Three things are simulated, and the article says so wherever they matter: token counts are characters divided by four, the answer is a fixed string, and cache hits follow the rules the vendors document (thresholds, prefix matching), applied to the request that actually arrived. So the cost table is a worked example of the published price sheets, not a bill, and I did not measure latency or answer quality at all. Prices and cache rules are as I read them on 9 October 2026; they change often.