The Deska blog
Prompt Caching Discounts Across Providers
Learn how to leverage prompt caching discounts across major AI providers to reduce API costs and improve performance for long context developer workflows.
10 min read
Managing API costs is a critical skill for developers building with Large Language Models. As context windows expand to millions of tokens, prompt caching discounts have emerged as the primary mechanism for balancing deep context awareness with sustainable margins. This technique allows the model provider to store frequently used prefixes in their memory layers, offering a significantly lower rate for those tokens when they are reused in subsequent requests. Understanding how these tiers work across different providers is essential for building efficient systemic architectures.
The mechanics of prompt caching
Prompt caching works by identifying exact matches in the initial segments of a prompt. When a developer sends a request that shares a prefix with a previous request, the provider bypasses the need to recompute the attention mechanisms for those early tokens. This process reduces latency because the computation is already done, and it reduces cost because the provider passes the operational savings to the user.
Most current implementations require a minimum threshold for caching to be effective. For example, some providers require the first 1024 tokens to remain static before the cache benefits apply. The cache is typically TTL based, meaning it expires after a period of inactivity. This creates a strategic challenge for developers: how to structure prompts so that the most static elements, like system instructions, documentation, or large codebase chunks, remain at the beginning of the message.
Comparing major provider implementations
Different providers approach caching with varying levels of transparency and pricing structures. While the general concept remains the same, the specific logic for cache hits and misses can change how you architect your agentic workflows.
| Provider | Minimum Cache Size | Cache Expiry (TTL) | Pricing Advantage |
|---|---|---|---|
| Anthropic | 1024 tokens | 5 to 10 minutes | Up to 90 percent discount |
| OpenAI | 1024 tokens | Automatic | Up to 50 percent discount |
| DeepSeek | 64 tokens | Automatic | Up to 90 percent discount |
| Google Gemini | 32k tokens | User defined | Monthly/Hourly fee model |
Anthropic uses a manual control method where developers must explicitly flag segments of the prompt for caching. This gives precise control but requires more logic on the client side. OpenAI, conversely, uses an automatic system that caches the most recent prefixes without requiring specific header flags. DeepSeek has gained popularity by offering extremely granular caching, starting as low as 64 tokens, which is ideal for short, repetitive task sequences.
Practical applications in development environments
In a development setting, the most common use for prompt caching is maintaining the state of a project. When you are using specialized tools to write code, you often send the entire file structure or specific documentation files with every message to ensure the model has context. Without caching, this would be prohibitively expensive.
For developers who use Ask Deska to manage their workspace, caching plays a vital role. Deska allows you to run multiple panels like terminals and code editors side by side. When the integrated assistant reads your current session to help debug a CLI error, it often includes the history of your terminal output. By leveraging caching, the repeated parts of that terminal log become significantly cheaper to process during a long debugging session.
Effective caching strategy often involves:
- Placing system prompts and high level instructions at the very top of the call.
- Including large, static library definitions or API schemas next.
- Keeping volatile information, like the user current question or recent timestamps, at the very end of the prompt.
- Reusing the same conversation thread structure to maximize prefix overlap.
Local first workflows and cost control
While cloud providers offer discounts through caching, the ultimate cost optimization strategy is local execution. Using a local-first approach ensures that sensitive data stays on your machine, but it also allows you to integrate with cloud LLMs more selectively.
For example, when using coding agents within an infinite canvas environment, you might have hundreds of files open. A sophisticated tool will only send the relevant snippets to the cloud, utilizing provider caching for the project index while keeping the specific logic changes local. This hybrid approach balances the high reasoning capabilities of frontier models with the cost efficiency of local processing.
Deska facilitates this through its BYOK model. Users can provide their own API keys, allowing them to benefit directly from the prompt caching discounts offered by their chosen providers. Because Deska runs locally on Mac, Windows, and Linux, your project data is not being stored on a third party server; only the necessary tokens are sent to the LLM API, where the caching logic takes over.
Optimizing for performance and speed
Cost is not the only factor. Prompt caching significantly improves Time To First Token (TTFT). When a cache hit occurs, the model can start generating its response almost instantly, as it does not need to "read" the entire large context from scratch.
This is particularly noticeable when using voice commands to drive your workspace. When you ask your assistant to open a new panel or run a command, you expect an immediate response. If the context of your current workspaces is already cached in the provider network, the latency is minimized. The experience becomes seamless, moving from a slow request-response cycle to a fluid interaction.
Common pitfalls in caching logic
- Changing a single character in the prefix: Most caches are exact match strings. If you add a space or change a version number in your system prompt at the top, the entire cache for every subsequent token is invalidated.
- Inconsistent document ordering: If you include five documentation files but change their order in different requests, the cache will fail. Developers should implement a deterministic sorting algorithm for their context assembly.
- Ignoring TTL: If your development sessions have long gaps, the cache may expire. Some workflows benefit from "keep alive" pings, though this must be weighed against the cost of the ping itself.
FAQ
How can I check if my prompt caching is working?
Most providers include specific fields in their API response headers or body under usage statistics. Look for terms like cached_tokens or cache_read_input_tokens. If this number is increasing across similar requests, your caching logic is successful.
Does caching affect the quality of the model output?
No. Prompt caching is a performance and cost optimization that does not change the mathematical output of the model. The model processed the tokens exactly as if they were read for the first time, just faster and cheaper.
Can I use caching with open source models?
Yes, if you are hosting them through services that support it like vLLM or llama.cpp. However, the discounts refer specifically to the pricing models of commercial API providers. If you are running models locally through Deska panels, you are using your own hardware, so the concept of "discounts" applies to your local compute time rather than a balance in dollars.
Get started with efficient development
Optimizing your context is the first step toward building more powerful AI integrations. By combining provider discounts with a robust local development environment, you can scale your productivity without scaling your cloud bill.
You can explore these capabilities by downloading the app for your preferred platform. Visit our download page to get started with the free desktop application and begin building your cached workflows today.