Back to feed
Dev.to
Dev.to
8/4/2026
Spring AI Prompt Caching and Chat Memory: Where the Tokens Go — LLM Cost Control 2/4

Spring AI Prompt Caching and Chat Memory: Where the Tokens Go — LLM Cost Control 2/4

Short summary

Part 2 of a Spring AI cost-control series covering output token costs, conversation history billing, and repeated static content. Output tokens cost 5-8x more than input tokens across OpenAI and Anthropic, and reasoning models generate hidden thinking tokens billed at output rates. The article shows how to cap completions with ChatOptions, control reasoning effort per provider, and warns that Ollama models like qwen3 and deepseek-r1 use reasoning by default — a cost trap when moving to billed providers.

  • Output tokens cost 5-8x more than input tokens; reasoning tokens are billed at output rates and can multiply costs 11x
  • Spring AI ChatOptions.maxTokens() caps completions; reasoning-effort settings are provider-specific
  • Ollama models like qwen3 and deepseek-r1 enable reasoning by default — disable locally to predict production costs

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Comments

Failed to load comments. Please try again.

Explore more