Docs/Chat

User Guide · 2.4.1 Release

How do I improve cache hit rates and lower API costs?

Reuse stable context, estimate costs, and verify savings in Cube

Read Markdown
On this page

What do providers reuse?#

Every turn can carry your assistant prompt, tool definitions, reference materials, and prior messages. When a provider matches a cached prefix at the start of your request, it can reuse the computation for that portion of the input — typically reducing input token costs and helping replies start sooner. The model still generates a fresh answer, and cached input tokens still count toward the context window length.

The official DeepSeek API enables context caching by default, so you can apply the steps below right away. Whether a request hits the cache depends on the model's caching rules, how long the matching prefix is, and whether the cache entry is still alive. DeepSeek Context Caching · OpenAI Prompt Caching · Claude Prompt Caching · Gemini Context Caching

What to do in Cube#

  1. Stay in the same chat for the same task. Use the same provider, model, and assistant on the same source material, keeping your web search, tool, and skill settings steady. Wait for the current reply to finish, then ask related follow-ups in the same conversation to reuse earlier context while the cache is still warm. Start a new conversation when switching to an unrelated project or topic to avoid dragging irrelevant history along.
  2. Put stable rules and shared material first, and per-turn changes last. Store long-term roles, formatting, and rules in Assistants → Edit assistant → Prompt. Provide shared materials once near the start of the chat, then send only new questions and new details afterward — for example, share a contract once, then ask “What risks are in the payment terms?” followed by “How should we revise the termination clause?”. When correcting something said earlier, add the correction in a new message; editing an earlier message shortens the reusable prefix.
  3. Avoid churn at the start of requests. Try not to place minute-by-minute variables like {{current_clock}} in your assistant prompt; put per-turn dates, project IDs, or temporary rules in the current user message instead. Assistant memories keep the system prompt completely static under On-demand reading, and under Auto sync they freeze the first-turn baseline and append new or edited memories at the tail — only deleting a memory or compressing context refreshes the prefix.
  4. Trim long chats down to what the task actually needs. Open Compress context from the top-right More menu of the chat screen, and enter start/end message numbers, pick a preset, or drag the two handles to decide which range becomes a summary. Keeping the original opening messages intact helps continue reusing the prefix cache, though actual hits depend on the provider. For long materials, you can also reference only the relevant sections and let the model read the rest on demand.

The highest hit rates happen when most of the current turn's input is cached history and the new question is short. For quick one-off tasks, just send a short prompt directly — padding extra text only increases token usage.

Which in-chat changes invalidate the cache?#

Within the same conversation, the actions below change the request sent to the model and may cause the next turn to lose part or all of its cache hit:

  • Enabling or disabling tools. For example, toggling file tools or an MCP server in the Tools menu can change the tool list sent to the model.
  • Switching reasoning effort. For example, changing from Default to High, or turning thinking on or off. Some models include reasoning configuration in cache matching.
  • Switching web search mode. For example, turning on Built-in search from off, or switching between built-in search and an external search service. The search tools or prompt injected for the model may change.

The next turn may have to reprocess part or all of the conversation history, temporarily increasing input costs and time to first token. The exact impact depends on the provider and model. When working continuously on a single task, pick your tools, reasoning level, and web search mode before starting; if you need to change them midway, adjust once and continue asking under the new configuration so subsequent turns can warm the cache again. Claude's cache invalidation rules

How do I verify cost savings?#

Test three turns of a real task on your usual model — for instance, send a document with a first question, then ask two follow-ups. After each turn, tap the AI badge in the bottom-right corner of the reply bubble to check the cached token count and hit rate under Input, while noting total input and output usage. When tools trigger multiple model calls, a single reply accumulates usage across all of those requests. Open Session Stats from the chat's top-right More menu to see cumulative usage for the entire conversation. To pinpoint which exact section changed and broke the cache, enable Request debug mode in Settings → Connections & advanced → Diagnostics & Crash Logs, then inspect cross-turn cache-break diagnostics via More → Request details on an assistant message.

A brand-new first turn, a prefix shorter than the model's minimum threshold, or too long a gap between turns can all leave the cache row hidden. Some providers or relays do not return cache metrics at all — check your provider dashboard in that case. Compare total costs across similar tasks before and after tuning, and always treat your provider's actual billing statement as authoritative.