{"slug": "how-to-reduce-llm-costs-in-spring-ai-2-0-10-practical-controls", "title": "How to Reduce LLM Costs in Spring AI 2.0: 10 Practical Controls", "summary": "Spring AI 2.0, which reached GA on 12 June 2026, introduces new controls to reduce LLM costs. A developer outlines ten cost drivers, from limiting response length to structuring prompts for provider caching, and shows how per-feature metrics help match models to tasks.", "body_md": "*Spring AI's defaults are built for a fast start; they do not guarantee a low monthly cost. Shipping an LLM feature is easy — making it cost-efficient is not. This series shows the spots where money leaks, along with the control that closes each one.*\n\n[Spring AI 2.0 reached GA on 12 June 2026](https://spring.io/blog/2026/06/12/spring-ai-2-0-0-GA-available-now). It needs [Spring Boot 4](https://docs.spring.io/spring-boot/index.html), moves the tool-calling loop out of the [ ChatModel](https://docs.spring.io/spring-ai/docs/current/api/org/springframework/ai/chat/model/ChatModel.html), adds tool search, and extends structured outputs. Tool search and the extended structured-output controls point in the same direction: they determine how many tokens your application sends and receives.\n\nThe bill grows quietly. A chatbot with a 2,000-token system prompt, run 100,000 times a month, sends 200 million tokens of the same text. At an example rate of $1 per million input tokens, that is $200 a month — before a single user message. Then add conversation history, which is sent in full on every turn. Add retrieved RAG documents and the JSON schema of every registered tool. The input side can grow 10× with no change in traffic at all. Output tokens cost several times more per token than input tokens, and reasoning models bill their hidden \"thinking\" as output too.\n\nThe provider sets the prices. The framework gives you controls that can reduce the number of tokens you pay for.\n\nThis series works through ten cost drivers, numbered #0 to #9. Each one is a place where tokens repeat or grow without anyone deciding they should, and each comes with the Spring AI control that cuts it. They are spread across four parts. Part 1 is live. Parts 2 to 4 follow in August 2026.\n\nProvider dashboards show what you spent, but not which feature spent it. Spring AI's observability closes that gap, and from there you can match each model to its task and stop features from carrying defaults they never needed.\n\nThis part covers limiting response length, bounding how much conversation history you resend, and structuring prompts so that provider caching actually works.\n\nRetrieved documents and tool definitions are added to every request, whether the model needs them or not. This part covers retrieving less, cleaning up what was retrieved, and sending tool schemas only when they are relevant.\n\nA failed response is billed in full, and retrying it resends the entire context. This part covers preventing malformed output at the provider level, then the indexing side: embedding model choice, vector size, batching, and re-embedding only what has changed.\n\nStart with [Part 1](https://dev.to/julia_denysova/spring-ai-token-usage-measure-cost-before-you-pick-a-model-llm-cost-control-14-41fo). Every later driver asks you to trade something — context, memory, response length — and per-feature metrics are what tell you which trade is worth making. Part 1 also covers the cheapest change available: sending routine work to a smaller model, which usually needs no more than a property change.", "url": "https://wpnews.pro/news/how-to-reduce-llm-costs-in-spring-ai-2-0-10-practical-controls", "canonical_source": "https://dev.to/julia_denysova/how-to-reduce-llm-costs-in-spring-ai-20-10-practical-controls-2jj7", "published_at": "2026-07-30 15:26:02+00:00", "updated_at": "2026-07-30 15:33:30.689606+00:00", "lang": "en", "topics": ["large-language-models", "developer-tools", "ai-infrastructure"], "entities": ["Spring AI", "Spring Boot"], "alternates": {"html": "https://wpnews.pro/news/how-to-reduce-llm-costs-in-spring-ai-2-0-10-practical-controls", "markdown": "https://wpnews.pro/news/how-to-reduce-llm-costs-in-spring-ai-2-0-10-practical-controls.md", "text": "https://wpnews.pro/news/how-to-reduce-llm-costs-in-spring-ai-2-0-10-practical-controls.txt", "jsonld": "https://wpnews.pro/news/how-to-reduce-llm-costs-in-spring-ai-2-0-10-practical-controls.jsonld"}}