<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom"><title>Simon Willison's Weblog: prompt-caching</title><link href="http://simonwillison.net/" rel="alternate"/><link href="http://simonwillison.net/tags/prompt-caching.atom" rel="self"/><id>http://simonwillison.net/</id><updated>2025-05-09T02:46:52+00:00</updated><author><name>Simon Willison</name></author><entry><title>Gemini 2.5 Models now support implicit caching</title><link href="https://simonwillison.net/2025/May/9/gemini-implicit-caching/#atom-tag" rel="alternate"/><published>2025-05-09T02:46:52+00:00</published><updated>2025-05-09T02:46:52+00:00</updated><id>https://simonwillison.net/2025/May/9/gemini-implicit-caching/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="https://developers.googleblog.com/en/gemini-2-5-models-now-support-implicit-caching/"&gt;Gemini 2.5 Models now support implicit caching&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
I just spotted a &lt;code&gt;cacheTokensDetails&lt;/code&gt; key in the token usage JSON while running a &lt;a href="https://gist.github.com/simonw/1383565aac316d68cc29f289e33b2e51"&gt;long chain of prompts&lt;/a&gt; against Gemini 2.5 Flash - despite not configuring caching myself:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;{"cachedContentTokenCount": 200658, "promptTokensDetails": [{"modality": "TEXT", "tokenCount": 204082}], "cacheTokensDetails": [{"modality": "TEXT", "tokenCount": 200658}], "thoughtsTokenCount": 2326}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;I went searching and it turns out Gemini had a massive upgrade to their prompt caching earlier today:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Implicit caching directly passes cache cost savings to developers without the need to create an explicit cache. Now, when you send a request to one of the Gemini 2.5 models, if the request shares a common prefix as one of previous requests, then it’s eligible for a cache hit. We will dynamically pass cost savings back to you, providing the same 75% token discount. [...]&lt;/p&gt;
&lt;p&gt;To make more requests eligible for cache hits, we reduced the minimum request size for 2.5 Flash to 1024 tokens and 2.5 Pro to 2048 tokens.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Previously you needed to both explicitly configure the cache &lt;em&gt;and&lt;/em&gt; pay a per-hour charge to keep that cache warm.&lt;/p&gt;
&lt;p&gt;This new mechanism is so much more convenient! It imitates how both &lt;a href="https://simonwillison.net/2024/Aug/14/deepseek-context-caching/"&gt;DeepSeek&lt;/a&gt; and &lt;a href="https://simonwillison.net/2024/Oct/2/not-digital-god/#prompt-caching-aka-the-big-price-drop"&gt;OpenAI&lt;/a&gt; implement prompt caching, leaving Anthropic as the remaining large provider who require you to &lt;a href="https://simonwillison.net/2024/Aug/14/prompt-caching-with-claude/"&gt;manually configure prompt caching&lt;/a&gt; to get it to work.&lt;/p&gt;
&lt;p&gt;Gemini's explicit caching mechanism is still available. &lt;a href="https://ai.google.dev/gemini-api/docs/caching"&gt;The documentation&lt;/a&gt; says:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Explicit caching is useful in cases where you want to guarantee cost savings, but with some added developer work.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;With implicit caching the cost savings aren't possible to predict in advance, especially since the cache timeout within which a prefix will be discounted isn't described and presumably varies based on load and other circumstances outside of the developer's control.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: DeepMind's &lt;a href="https://twitter.com/_philschmid/status/1920772470543397281"&gt;Philipp Schmid&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;There is no fixed time, but it's should be a few minutes.&lt;/p&gt;
&lt;/blockquote&gt;


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/ai"&gt;ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/prompt-engineering"&gt;prompt-engineering&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/generative-ai"&gt;generative-ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/llms"&gt;llms&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/gemini"&gt;gemini&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/llm-pricing"&gt;llm-pricing&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/prompt-caching"&gt;prompt-caching&lt;/a&gt;&lt;/p&gt;



</summary><category term="ai"/><category term="prompt-engineering"/><category term="generative-ai"/><category term="llms"/><category term="gemini"/><category term="llm-pricing"/><category term="prompt-caching"/></entry><entry><title>Quoting Alex Albert</title><link href="https://simonwillison.net/2025/Jan/16/alex-albert/#atom-tag" rel="alternate"/><published>2025-01-16T16:14:27+00:00</published><updated>2025-01-16T16:14:27+00:00</updated><id>https://simonwillison.net/2025/Jan/16/alex-albert/#atom-tag</id><summary type="html">
    &lt;blockquote cite="https://twitter.com/alexalbert__/status/1879917906294870196"&gt;&lt;p&gt;We've adjusted &lt;a href="https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching"&gt;prompt caching&lt;/a&gt; so that you now only need to specify cache write points in your prompts - we'll automatically check for cache hits at previous positions. No more manual tracking of read locations needed.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p class="cite"&gt;&amp;mdash; &lt;a href="https://twitter.com/alexalbert__/status/1879917906294870196"&gt;Alex Albert&lt;/a&gt;, Anthropic&lt;/p&gt;

    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/ai"&gt;ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/generative-ai"&gt;generative-ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/llms"&gt;llms&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/anthropic"&gt;anthropic&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/claude"&gt;claude&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/alex-albert"&gt;alex-albert&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/prompt-caching"&gt;prompt-caching&lt;/a&gt;&lt;/p&gt;



</summary><category term="ai"/><category term="generative-ai"/><category term="llms"/><category term="anthropic"/><category term="claude"/><category term="alex-albert"/><category term="prompt-caching"/></entry><entry><title>Anthropic: Message Batches (beta)</title><link href="https://simonwillison.net/2024/Oct/8/anthropic-batch-mode/#atom-tag" rel="alternate"/><published>2024-10-08T18:18:57+00:00</published><updated>2024-10-08T18:18:57+00:00</updated><id>https://simonwillison.net/2024/Oct/8/anthropic-batch-mode/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="https://docs.anthropic.com/en/docs/build-with-claude/message-batches"&gt;Anthropic: Message Batches (beta)&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
Anthropic now have a batch mode, allowing you to send prompts to Claude in batches which will be processed within 24 hours (though probably much faster than that) and come at a 50% price discount.&lt;/p&gt;
&lt;p&gt;This matches the batch models offered &lt;a href="https://platform.openai.com/docs/guides/batch"&gt;by OpenAI&lt;/a&gt; and &lt;a href="https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/batch-prediction-gemini"&gt;by Google Gemini&lt;/a&gt;, both of which also provide a 50% discount.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update 15th October 2024&lt;/strong&gt;: Alex Albert &lt;a href="https://twitter.com/alexalbert__/status/1846265564852809854"&gt;confirms&lt;/a&gt; that Anthropic batching and prompt caching can be combined:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Don't know if folks have realized yet that you can get close to a 95% discount on Claude 3.5 Sonnet tokens when you combine prompt caching with the new Batches API&lt;/p&gt;
&lt;/blockquote&gt;

    &lt;p&gt;&lt;small&gt;&lt;/small&gt;Via &lt;a href="https://twitter.com/alexalbert__/status/1843695956967264661"&gt;@alexalbert__&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/ai"&gt;ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/openai"&gt;openai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/generative-ai"&gt;generative-ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/llms"&gt;llms&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/anthropic"&gt;anthropic&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/claude"&gt;claude&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/gemini"&gt;gemini&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/alex-albert"&gt;alex-albert&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/prompt-caching"&gt;prompt-caching&lt;/a&gt;&lt;/p&gt;



</summary><category term="ai"/><category term="openai"/><category term="generative-ai"/><category term="llms"/><category term="anthropic"/><category term="claude"/><category term="gemini"/><category term="alex-albert"/><category term="prompt-caching"/></entry><entry><title>Gemini 1.5 Flash-8B is now production ready</title><link href="https://simonwillison.net/2024/Oct/3/gemini-15-flash-8b/#atom-tag" rel="alternate"/><published>2024-10-03T20:16:36+00:00</published><updated>2024-10-03T20:16:36+00:00</updated><id>https://simonwillison.net/2024/Oct/3/gemini-15-flash-8b/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="https://developers.googleblog.com/en/gemini-15-flash-8b-is-now-generally-available-for-use/"&gt;Gemini 1.5 Flash-8B is now production ready&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
Gemini 1.5 Flash-8B is "a smaller and faster variant of 1.5 Flash" - and is now released to production, at half the price of the 1.5 Flash model.&lt;/p&gt;
&lt;p&gt;It's really, really cheap:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;$0.0375 per 1 million input tokens on prompts &amp;lt;128K&lt;/li&gt;
&lt;li&gt;$0.15 per 1 million output tokens on prompts &amp;lt;128K&lt;/li&gt;
&lt;li&gt;$0.01 per 1 million input tokens on cached prompts &amp;lt;128K&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Prices are doubled for prompts longer than 128K.&lt;/p&gt;
&lt;p&gt;I believe images are still charged at a flat rate of 258 tokens, which I think means a single non-cached image with Flash should cost 0.00097 cents - a number so tiny I'm doubting if I got the calculation right.&lt;/p&gt;
&lt;p&gt;OpenAI's cheapest model remains GPT-4o mini, at $0.15/1M input - though that drops to half of that for reused prompt prefixes thanks to their new prompt caching feature (or by half if you use batches, though those can’t be combined with OpenAI prompt caching. Gemini also offer half-off for batched requests).&lt;/p&gt;
&lt;p&gt;Anthropic's cheapest model is still Claude 3 Haiku at $0.25/M, though that drops to $0.03/M for cached tokens (if you configure them correctly).&lt;/p&gt;
&lt;p&gt;I've released &lt;a href="https://github.com/simonw/llm-gemini/releases/tag/0.2"&gt;llm-gemini 0.2&lt;/a&gt; with support for the new model:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;llm install -U llm-gemini
llm keys set gemini
# Paste API key here
llm -m gemini-1.5-flash-8b-latest "say hi"
&lt;/code&gt;&lt;/pre&gt;

    &lt;p&gt;&lt;small&gt;&lt;/small&gt;Via &lt;a href="https://twitter.com/OfficialLoganK/status/1841903061360640029"&gt;@OfficialLoganK&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/google"&gt;google&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/ai"&gt;ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/openai"&gt;openai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/generative-ai"&gt;generative-ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/llms"&gt;llms&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/llm"&gt;llm&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/anthropic"&gt;anthropic&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/gemini"&gt;gemini&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/vision-llms"&gt;vision-llms&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/llm-pricing"&gt;llm-pricing&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/prompt-caching"&gt;prompt-caching&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/llm-release"&gt;llm-release&lt;/a&gt;&lt;/p&gt;



</summary><category term="google"/><category term="ai"/><category term="openai"/><category term="generative-ai"/><category term="llms"/><category term="llm"/><category term="anthropic"/><category term="gemini"/><category term="vision-llms"/><category term="llm-pricing"/><category term="prompt-caching"/><category term="llm-release"/></entry><entry><title>OpenAI DevDay: Let’s build developer tools, not digital God</title><link href="https://simonwillison.net/2024/Oct/2/not-digital-god/#atom-tag" rel="alternate"/><published>2024-10-02T22:33:13+00:00</published><updated>2024-10-02T22:33:13+00:00</updated><id>https://simonwillison.net/2024/Oct/2/not-digital-god/#atom-tag</id><summary type="html">
    &lt;p&gt;I had a fun time &lt;a href="https://simonwillison.net/2024/Oct/1/openai-devday-2024-live-blog/"&gt;live blogging OpenAI DevDay yesterday&lt;/a&gt; - I’ve now &lt;a href="https://til.simonwillison.net/django/live-blog"&gt;shared notes&lt;/a&gt; about the live blogging system I threw other in a hurry on the day (with assistance from Claude and GPT-4o). Now that the smoke has settled a little, here are my impressions from the event.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="#compared-to-last-year"&gt;Compared to last year&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="#prompt-caching-aka-the-big-price-drop"&gt;Prompt caching, aka the big price drop&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="#gpt-4o-audio-via-the-new-websocket-realtime-api"&gt;GPT-4o audio via the new WebSocket Realtime API&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="#model-distillation-is-fine-tuning-made-much-easier"&gt;Model distillation is fine-tuning made much easier&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="#let-s-build-developer-tools-not-digital-god"&gt;Let’s build developer tools, not digital God&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id="comared-to-last-year"&gt;Compared to last year&lt;/h4&gt;

&lt;p&gt;Comparison with the first DevDay in November 2023 are unavoidable. That event was much more keynote-driven: just in the keynote OpenAI released GPT-4 vision, and Assistants, and GPTs, and GPT-4 Turbo (with a massive price drop), and their text-to-speech API. It felt more like a launch-focused product event than something explicitly for developers.&lt;/p&gt;
&lt;p&gt;This year was different. Media weren’t invited, there was no livestream, Sam Altman didn’t present the opening keynote (he was interviewed at the end of the day instead) and the new features, while impressive, were not as abundant.&lt;/p&gt;
&lt;p&gt;Several features were released in the last few months that could have been saved for DevDay: GPT-4o mini and the o1 model family are two examples. I’m personally happy that OpenAI are shipping features like that as they become ready rather than holding them back for an event.&lt;/p&gt;
&lt;p&gt;I’m a bit surprised they didn’t talk about &lt;a href="https://simonwillison.net/2024/Oct/1/whisper-large-v3-turbo-model/"&gt;Whisper Turbo&lt;/a&gt; at the conference though, released just the day before - especially since that’s one of the few pieces of technology they release under an open source (MIT) license.&lt;/p&gt;
&lt;p&gt;This was clearly intended as an event by developers, for developers. If you don’t build software on top of OpenAI’s platform there wasn’t much to catch your attention here.&lt;/p&gt;
&lt;p&gt;As someone who &lt;strong&gt;does&lt;/strong&gt; build software on top of OpenAI, there was a ton of valuable and interesting stuff.&lt;/p&gt;
&lt;h4 id="prompt-caching-aka-the-big-price-drop"&gt;Prompt caching, aka the big price drop&lt;/h4&gt;
&lt;p&gt;I was hoping we might see a price drop, seeing as there’s an ongoing pricing war between Gemini, Anthropic and OpenAI. We got one in an interesting shape: a &lt;a href="https://openai.com/index/api-prompt-caching/"&gt;50% discount&lt;/a&gt; on input tokens for prompts with a shared prefix.&lt;/p&gt;
&lt;p&gt;This isn’t a new idea: both Google Gemini and Claude offer a form of prompt caching discount, if you configure them correctly and make smart decisions about when and how the cache should come into effect.&lt;/p&gt;
&lt;p&gt;The difference here is that OpenAI apply the discount automatically:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;API calls to supported models will automatically benefit from Prompt Caching on prompts longer than 1,024 tokens. The API caches the longest prefix of a prompt that has been previously computed, starting at 1,024 tokens and increasing in 128-token increments. If you reuse prompts with common prefixes, we will automatically apply the Prompt Caching discount without requiring you to make any changes to your API integration.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;50% off repeated long prompts is a pretty significant price reduction!&lt;/p&gt;
&lt;p&gt;&lt;a href="https://ai.google.dev/gemini-api/docs/caching"&gt;Anthropic's Claude implementation&lt;/a&gt; saves more money: 90% off rather than 50% - but is significantly more work to put into play.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://ai.google.dev/gemini-api/docs/caching"&gt;Gemini’s caching&lt;/a&gt; requires you to pay per hour to keep your cache warm which makes it extremely difficult to effectively build against in comparison to the other two.&lt;/p&gt;
&lt;p&gt;It's worth noting that OpenAI are not the first company to offer automated caching discounts: &lt;a href="https://platform.deepseek.com/api-docs/news/news0802/"&gt;DeepSeek have offered that&lt;/a&gt; through their API for a few months.&lt;/p&gt;
&lt;h4 id="gpt-4o-audio-via-the-new-websocket-realtime-api"&gt;GPT-4o audio via the new WebSocket Realtime API&lt;/h4&gt;
&lt;p&gt;Absolutely the biggest announcement of the conference: the &lt;a href="https://openai.com/index/introducing-the-realtime-api/"&gt;new Realtime API&lt;/a&gt; is effectively the API version of ChatGPT advanced voice mode, a user-facing feature that finally &lt;a href="https://help.openai.com/en/articles/8400625-voice-mode-faq"&gt;rolled out to everyone&lt;/a&gt; just a week ago.&lt;/p&gt;
&lt;p&gt;This means we can finally tap directly into GPT-4o’s multimodal audio support: we can send audio directly into the model (without first transcribing it to text via something like Whisper), and we can have it directly return speech without needing to run a separate text-to-speech model.&lt;/p&gt;
&lt;p&gt;The way they chose to expose this is interesting: it’s not (yet) part of their existing chat completions API, instead using an entirely new API pattern built around WebSockets.&lt;/p&gt;

&lt;p&gt;&lt;img src="https://static.simonwillison.net/static/2024/websocket-interruptions.jpg" alt="JavaScript code handling WebSocket events" /&gt;&lt;/p&gt;

&lt;p&gt;They designed it like that because they wanted it to be as realtime as possible: the API lets you constantly stream audio and text in both directions, and even supports allowing users to speak over and interrupt the model!&lt;/p&gt;
&lt;p&gt;So far the Realtime API supports text, audio and function call / tool usage - but doesn't (yet) support image input (I've been assured that's coming soon). The combination of audio and function calling is super exciting alone though - several of the demos at DevDay used these to build fun voice-driven interactive web applications.&lt;/p&gt;
&lt;p&gt;I like this WebSocket-focused API design a lot. My only hesitation is that, since an API key is needed to open a WebSocket connection, actually running this in production involves spinning up an authenticating WebSocket proxy. I hope OpenAI can provide a less code-intensive way of solving this in the future.&lt;/p&gt;
&lt;p&gt;Code they showed during the event demonstrated using the native browser &lt;code&gt;WebSocket&lt;/code&gt; class directly, but I can't find those code examples online now. I hope they publish it soon. For the moment the best things to look at are the &lt;a href="https://github.com/openai/openai-realtime-api-beta"&gt;openai-realtime-api-beta&lt;/a&gt; and &lt;a href="https://github.com/openai/openai-realtime-console"&gt;openai-realtime-console&lt;/a&gt; repositories.&lt;/p&gt;
&lt;p&gt;The new &lt;a href="https://platform.openai.com/playground/realtime"&gt;playground/realtime&lt;/a&gt; debugging tool - the OpenAI playground for the Realtime API - is a lot of fun to try out too.&lt;/p&gt;
&lt;h4 id="model-distillation-is-fine-tuning-made-much-easier"&gt;Model distillation is fine-tuning made much easier&lt;/h4&gt;
&lt;p&gt;The other big developer-facing announcements were around &lt;strong&gt;model distillation&lt;/strong&gt;, which to be honest is more of a usability enhancement and minor rebranding of their existing &lt;a href="https://platform.openai.com/docs/guides/fine-tuning"&gt;fine-tuning features&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;OpenAI have offered fine-tuning for a few years now, most recently against their GPT-4o and GPT-4o mini models. They’ve practically been begging people to try it out, offering &lt;a href="https://openai.com/index/gpt-4o-fine-tuning/"&gt;generous free tiers&lt;/a&gt; in previous months:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Today [August 20th 2024] we’re launching fine-tuning for GPT-4o, one of the most requested features from developers. We are also offering 1M training tokens per day for free for every organization through September 23.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That free offer has now been extended. A footnote on &lt;a href="https://openai.com/api/pricing/"&gt;the pricing page&lt;/a&gt; today:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Fine-tuning for GPT-4o and GPT-4o mini is free up to a daily token limit through October 31, 2024. For GPT-4o, each qualifying org gets up to 1M complimentary training tokens daily and any overage will be charged at the normal rate of $25.00/1M tokens. For GPT-4o mini, each qualifying org gets up to 2M complimentary training tokens daily and any overage will be charged at the normal rate of $3.00/1M tokens&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;The problem with fine-tuning is that it’s &lt;em&gt;really&lt;/em&gt; hard to do effectively. I tried it a couple of years ago myself against GPT-3 - just to apply tags to my blog content - and got disappointing results which deterred me from spending more money iterating on the process.&lt;/p&gt;
&lt;p&gt;To fine-tune a model effectively you need to gather a high quality set of examples and you need to construct a robust set of automated evaluations. These are some of the most challenging (and least well understood) problems in the whole nascent field of prompt engineering.&lt;/p&gt;
&lt;p&gt;OpenAI’s solution is a bit of a rebrand. “Model distillation” is a form of fine-tuning where you effectively teach a smaller model how to do a task based on examples generated by a larger model. It’s a very effective technique. Meta &lt;a href="https://ai.meta.com/blog/llama-3-2-connect-2024-vision-edge-mobile-devices/"&gt;recently boasted about&lt;/a&gt; how their impressive Llama 3.2 1B and 3B models were “taught” by their larger models:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;[...] powerful teacher models can be leveraged to create smaller models that have improved performance. We used two methods—pruning and distillation—on the 1B and 3B models, making them the first highly capable lightweight Llama models that can fit on devices efficiently.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Yesterday OpenAI released two new features to help developers implement this pattern.&lt;/p&gt;
&lt;p&gt;The first is &lt;strong&gt;stored completions&lt;/strong&gt;. You can now pass &lt;a href="https://platform.openai.com/docs/api-reference/chat/create#chat-create-store"&gt;a "store": true parameter&lt;/a&gt; to have OpenAI permanently store your prompt and its response in their backend, optionally with your own &lt;a href="https://platform.openai.com/docs/api-reference/chat/create#chat-create-metadata"&gt;additional tags&lt;/a&gt; to help you filter the captured data later.&lt;/p&gt;
&lt;p&gt;You can view your stored completions at &lt;a href="https://platform.openai.com/chat-completions"&gt;platform.openai.com/chat-completions&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I’ve been doing effectively the same thing with my &lt;a href="https://llm.datasette.io/"&gt;LLM command-line tool&lt;/a&gt; logging to &lt;a href="https://llm.datasette.io/en/stable/logging.html"&gt;a SQLite database&lt;/a&gt; for over a year now. It's a really productive pattern.&lt;/p&gt;
&lt;p&gt;OpenAI pitch stored completions as a great way to collect a set of training data from their large models that you can later use to fine-tune (aka distill into) a smaller model.&lt;/p&gt;
&lt;p&gt;The second, even more impactful feature, is &lt;strong&gt;evals&lt;/strong&gt;. You can now define and run comprehensive prompt evaluations directly inside the OpenAI platform.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://static.simonwillison.net/static/2024/eval.jpg" alt="Screenshot of a web interface showing evaluation results for an AI model named 'quick-reply-2-4o'. The interface displays a table with columns for messages, output, and three evaluation metrics: 'repliesToRightPerson', 'repliesToMostPressingIssue', and 'repliesMakeSense'. The table shows 8 rows of data, each representing a different conversation. Overall metrics at the top indicate 95%, 91%, and 97% success rates for the three evaluation criteria respectively. The interface appears to be part of a platform called 'Distillation Test' in a 'DevDay Demo' project." /&gt;&lt;/p&gt;
&lt;p&gt;OpenAI’s &lt;a href="https://platform.openai.com/docs/guides/evals"&gt;new eval tool&lt;/a&gt; competes directly with a bunch of existing startups - I’m quite glad I didn’t invest much effort in this space myself!&lt;/p&gt;
&lt;p&gt;The combination of evals and stored completions certainly seems like it should make the challenge of fine-tuning a custom model far more tractable.&lt;/p&gt;
&lt;p&gt;The other fine-tuning announcement, greeted by applause in the room, was &lt;a href="https://openai.com/index/introducing-vision-to-the-fine-tuning-api/"&gt;fine-tuning for images&lt;/a&gt;. This has always felt like one of the most obviously beneficial fine-tuning use-cases for me, since it’s much harder to get great image recognition results from sophisticated prompting alone.&lt;/p&gt;
&lt;p&gt;From a strategic point of view this makes sense as well: it has become increasingly clear over the last year that many prompts are inherently transferable between models - it’s very easy to take an application with prompts designed for GPT-4o and switch it to Claude or Gemini or Llama with few if any changes required.&lt;/p&gt;
&lt;p&gt;A fine-tuned model on the OpenAI platform is likely to be far more sticky.&lt;/p&gt;
&lt;h4 id="let-s-build-developer-tools-not-digital-god"&gt;Let’s build developer tools, not digital God&lt;/h4&gt;
&lt;p&gt;In the last session of the day I furiously live blogged &lt;a href="https://simonwillison.net/2024/Oct/1/openai-devday-2024-live-blog/#live-update-140"&gt;the Fireside Chat&lt;/a&gt; between Sam Altman and Kevin Weil, trying to capture as much of what they were saying as possible.&lt;/p&gt;
&lt;p&gt;A bunch of the questions were about AGI. I’m personally quite uninterested in AGI: it’s always felt a bit too much like science fiction for me. I want useful AI-driven tools that help me solve the problems I want to solve.&lt;/p&gt;
&lt;p&gt;One point of frustration: Sam referenced OpenAI’s five-level framework a few times. I found several news stories (many paywalled - here's &lt;a href="https://arstechnica.com/information-technology/2024/07/openai-reportedly-nears-breakthrough-with-reasoning-ai-reveals-progress-framework/"&gt;one that isn't&lt;/a&gt;) about it but I can’t find a definitive URL on an OpenAI site that explains what it is! This is why you should always &lt;a href="https://simonwillison.net/2024/Jul/13/give-people-something-to-link-to/"&gt;Give people something to link to so they can talk about your features and ideas&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Both Sam and Kevin seemed to be leaning away from AGI as a term. From my live blog notes (which paraphrase what was said unless I use quotation marks):&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Sam says they're trying to avoid the term now because it has become so over-loaded. Instead they think about their new five steps framework.&lt;/p&gt;
&lt;p&gt;"I feel a little bit less certain on that" with respect to the idea that an AGI will make a new scientific discovery.&lt;/p&gt;
&lt;p&gt;Kevin: "There used to be this idea of AGI as a binary thing [...] I don't think that's how think about it any more".&lt;/p&gt;
&lt;p&gt;Sam: Most people looking back in history won't agree when AGI happened. The turing test wooshed past and nobody cared.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I for one found this very reassuring. The thing I want from OpenAI is more of what we got yesterday: I want platform tools that I can build unique software on top of which I colud not have built previously.&lt;/p&gt;
&lt;p&gt;If the ongoing, well-documented internal turmoil at OpenAI from the last year is a result of the organization reprioritizing towards shipping useful, reliable tools for developers (and consumers) over attempting to build a digital God, then I’m all for it.&lt;/p&gt;
&lt;p&gt;And yet… OpenAI &lt;a href="https://openai.com/index/scale-the-benefits-of-ai/"&gt;just this morning&lt;/a&gt; finalized a raise of another $6.5 billion dollars at a staggering $157 billion post-money valuation. That feels more like a digital God valuation to me than a platform for developers in an increasingly competitive space.&lt;/p&gt;
    
        &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/websockets"&gt;websockets&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/ai"&gt;ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/openai"&gt;openai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/generative-ai"&gt;generative-ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/llms"&gt;llms&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/prompt-caching"&gt;prompt-caching&lt;/a&gt;&lt;/p&gt;
    

</summary><category term="websockets"/><category term="ai"/><category term="openai"/><category term="generative-ai"/><category term="llms"/><category term="prompt-caching"/></entry><entry><title>Introducing Contextual Retrieval</title><link href="https://simonwillison.net/2024/Sep/20/introducing-contextual-retrieval/#atom-tag" rel="alternate"/><published>2024-09-20T01:34:21+00:00</published><updated>2024-09-20T01:34:21+00:00</updated><id>https://simonwillison.net/2024/Sep/20/introducing-contextual-retrieval/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.anthropic.com/news/contextual-retrieval"&gt;Introducing Contextual Retrieval&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
Here's an interesting new embedding/RAG technique, described by Anthropic but it should work for any embedding model against any other LLM.&lt;/p&gt;
&lt;p&gt;One of the big challenges in implementing semantic search against vector embeddings - often used as part of a RAG system - is creating "chunks" of documents that are most likely to semantically match queries from users.&lt;/p&gt;
&lt;p&gt;Anthropic provide this solid example where semantic chunks might let you down:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Imagine you had a collection of financial information (say, U.S. SEC filings) embedded in your knowledge base, and you received the following question: "What was the revenue growth for ACME Corp in Q2 2023?"&lt;/p&gt;
&lt;p&gt;A relevant chunk might contain the text: "The company's revenue grew by 3% over the previous quarter." However, this chunk on its own doesn't specify which company it's referring to or the relevant time period, making it difficult to retrieve the right information or use the information effectively.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Their proposed solution is to take each chunk at indexing time and expand it using an LLM - so the above sentence would become this instead:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This chunk is from an SEC filing on ACME corp's performance in Q2 2023; the previous quarter's revenue was $314 million. The company's revenue grew by 3% over the previous quarter.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This chunk was created by Claude 3 Haiku (their least expensive model) using the following prompt template:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;document&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;code&gt;{{WHOLE_DOCUMENT}}&lt;/code&gt;&lt;br&gt;
&lt;code&gt;&amp;lt;/document&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Here is the chunk we want to situate within the whole document&lt;/code&gt;&lt;br&gt;
&lt;code&gt;&amp;lt;chunk&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;code&gt;{{CHUNK_CONTENT}}&lt;/code&gt;&lt;br&gt;
&lt;code&gt;&amp;lt;/chunk&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Please give a short succinct context to situate this chunk within the overall document for the purposes of improving search retrieval of the chunk. Answer only with the succinct context and nothing else.&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Here's the really clever bit: running the above prompt for every chunk in a document could get really expensive thanks to the inclusion of the entire document in each prompt. Claude &lt;a href="https://simonwillison.net/2024/Aug/14/prompt-caching-with-claude/"&gt;added context caching&lt;/a&gt; last month, which allows you to pay around 1/10th of the cost for tokens cached up to your specified beakpoint.&lt;/p&gt;
&lt;p&gt;By Anthropic's calculations:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Assuming 800 token chunks, 8k token documents, 50 token context instructions, and 100 tokens of context per chunk, the one-time cost to generate contextualized chunks is $1.02 per million document tokens.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Anthropic provide a &lt;a href="https://github.com/anthropics/anthropic-cookbook/blob/main/skills/contextual-embeddings/guide.ipynb"&gt;detailed notebook&lt;/a&gt; demonstrating an implementation of this pattern. Their eventual solution combines cosine similarity and BM25 indexing, uses embeddings from &lt;a href="https://docs.voyageai.com/docs/embeddings"&gt;Voyage AI&lt;/a&gt; and adds a reranking step powered by &lt;a href="https://cohere.com/rerank"&gt;Cohere&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The notebook also includes an evaluation set using JSONL - here's that evaluation data &lt;a href="https://lite.datasette.io/?json=https://github.com/anthropics/anthropic-cookbook/blob/main/skills/contextual-embeddings/data/evaluation_set.jsonl#/data/evaluation_set"&gt;in Datasette Lite&lt;/a&gt;.

    &lt;p&gt;&lt;small&gt;&lt;/small&gt;Via &lt;a href="https://twitter.com/alexalbert__/status/1836854956785352776"&gt;Alex Albert&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/search"&gt;search&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/ai"&gt;ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/prompt-engineering"&gt;prompt-engineering&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/generative-ai"&gt;generative-ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/vector-search"&gt;vector-search&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/llms"&gt;llms&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/embeddings"&gt;embeddings&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/anthropic"&gt;anthropic&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/claude"&gt;claude&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/rag"&gt;rag&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/prompt-caching"&gt;prompt-caching&lt;/a&gt;&lt;/p&gt;



</summary><category term="search"/><category term="ai"/><category term="prompt-engineering"/><category term="generative-ai"/><category term="vector-search"/><category term="llms"/><category term="embeddings"/><category term="anthropic"/><category term="claude"/><category term="rag"/><category term="prompt-caching"/></entry><entry><title>Quoting Alex Albert</title><link href="https://simonwillison.net/2024/Aug/15/alex-albert/#atom-tag" rel="alternate"/><published>2024-08-15T18:09:04+00:00</published><updated>2024-08-15T18:09:04+00:00</updated><id>https://simonwillison.net/2024/Aug/15/alex-albert/#atom-tag</id><summary type="html">
    &lt;blockquote cite="https://twitter.com/alexalbert__/status/1824136151701360756"&gt;&lt;p&gt;Examples are the #1 thing I recommend people use in their prompts because they work so well. The problem is that adding tons of examples increases your API costs and latency. Prompt caching fixes this. You can now add tons of examples to every prompt and create an alternative to a model finetuned on your task with basically zero cost/latency increase. […]&lt;/p&gt;
&lt;p&gt;This works even better with smaller models. You can generate tons of examples (test case + solution) with 3.5 Sonnet and then use those examples to create a few-shot prompt for Haiku.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p class="cite"&gt;&amp;mdash; &lt;a href="https://twitter.com/alexalbert__/status/1824136151701360756"&gt;Alex Albert&lt;/a&gt;&lt;/p&gt;

    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/ai"&gt;ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/prompt-engineering"&gt;prompt-engineering&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/llms"&gt;llms&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/anthropic"&gt;anthropic&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/claude"&gt;claude&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/alex-albert"&gt;alex-albert&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/claude-3-5-sonnet"&gt;claude-3-5-sonnet&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/prompt-caching"&gt;prompt-caching&lt;/a&gt;&lt;/p&gt;



</summary><category term="ai"/><category term="prompt-engineering"/><category term="llms"/><category term="anthropic"/><category term="claude"/><category term="alex-albert"/><category term="claude-3-5-sonnet"/><category term="prompt-caching"/></entry><entry><title>DeepSeek API introduces Context Caching on Disk</title><link href="https://simonwillison.net/2024/Aug/14/deepseek-context-caching/#atom-tag" rel="alternate"/><published>2024-08-14T20:48:32+00:00</published><updated>2024-08-14T20:48:32+00:00</updated><id>https://simonwillison.net/2024/Aug/14/deepseek-context-caching/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="https://platform.deepseek.com/api-docs/news/news0802/"&gt;DeepSeek API introduces Context Caching on Disk&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
I wrote about &lt;a href="https://simonwillison.net/2024/Aug/14/prompt-caching-with-claude/"&gt;Claude prompt caching&lt;/a&gt; this morning. It turns out Chinese LLM lab DeepSeek released their own implementation of context caching a couple of weeks ago, with the simplest possible pricing model: it's just turned on by default for all users.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;When duplicate inputs are detected, the repeated parts are retrieved from the cache, bypassing the need for recomputation. This not only reduces service latency but also significantly cuts down on overall usage costs.&lt;/p&gt;
&lt;p&gt;For cache hits, DeepSeek charges $0.014 per million tokens, slashing API costs by up to 90%.&lt;/p&gt;
&lt;p&gt;[...]&lt;/p&gt;
&lt;p&gt;The disk caching service is now available for all users, requiring no code or interface changes. The cache service runs automatically, and billing is based on actual cache hits.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;DeepSeek currently offer two frontier models, DeepSeek-V2 and DeepSeek-Coder-V2, both of which can be run as open weights models or accessed via their API.

    &lt;p&gt;&lt;small&gt;&lt;/small&gt;Via &lt;a href="https://fosstodon.org/@asb/112961626647803219"&gt;Alex Bradbury&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/ai"&gt;ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/generative-ai"&gt;generative-ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/llms"&gt;llms&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/deepseek"&gt;deepseek&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/prompt-caching"&gt;prompt-caching&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/ai-in-china"&gt;ai-in-china&lt;/a&gt;&lt;/p&gt;



</summary><category term="ai"/><category term="generative-ai"/><category term="llms"/><category term="deepseek"/><category term="prompt-caching"/><category term="ai-in-china"/></entry><entry><title>Prompt caching with Claude</title><link href="https://simonwillison.net/2024/Aug/14/prompt-caching-with-claude/#atom-tag" rel="alternate"/><published>2024-08-14T17:07:35+00:00</published><updated>2024-08-14T17:07:35+00:00</updated><id>https://simonwillison.net/2024/Aug/14/prompt-caching-with-claude/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.anthropic.com/news/prompt-caching"&gt;Prompt caching with Claude&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
The Claude API now supports prompt caching, allowing you to mark reused portions of long prompts (like a large document provided as context). Claude will cache these for up to five minutes, and any prompts within that five minutes that reuse the context will be both significantly faster and will be charged at a significant discount: ~10% of the cost of sending those uncached tokens.&lt;/p&gt;
&lt;p&gt;Writing to the cache costs money. The cache TTL is reset every time it gets a cache hit, so any application running more than one prompt every five minutes should see significant price decreases from this. If you app prompts less than once every five minutes you'll be losing money.&lt;/p&gt;
&lt;p&gt;This is similar to Google Gemini's &lt;a href="https://simonwillison.net/2024/May/14/context-caching-for-google-gemini/"&gt;context caching feature&lt;/a&gt;, but the pricing model works differently. Gemini charge $4.50/million tokens/hour for their caching (that's for Gemini 1.5 Pro - Gemini 1.5 Flash is $1/million/hour), for a quarter price discount on input tokens (see &lt;a href="https://ai.google.dev/pricing"&gt;their pricing&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Claude’s implementation also appears designed to help with ongoing conversations. Using caching during an individual user’s multi-turn conversation - where a full copy of the entire transcript is sent with each new prompt - could help even for very low traffic (or even single user) applications.&lt;/p&gt;
&lt;p&gt;Here's the &lt;a href="https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching#what-can-break-the-cache"&gt;full documentation&lt;/a&gt; for the new Claude caching feature, currently only enabled if you pass &lt;code&gt;"anthropic-beta: prompt-caching-2024-07-31"&lt;/code&gt; as an HTTP header.&lt;/p&gt;
&lt;p&gt;Interesting to note that this caching implementation doesn't save on HTTP overhead: if you have 1MB of context you still need to send a 1MB HTTP request for every call. I guess the overhead of that HTTP traffic is negligible compared to the overhead of processing those tokens once they arrive.&lt;/p&gt;
&lt;p&gt;One minor annoyance in the announcement for this feature:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Detailed instruction sets&lt;/strong&gt;: Share extensive lists of instructions, procedures, and examples to fine-tune Claude's responses. [...]&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I wish Anthropic wouldn't use the term "fine-tune" in this context (they do the same thing in &lt;a href="https://twitter.com/AnthropicAI/status/1823751314444021899"&gt;their tweet&lt;/a&gt;). This feature is unrelated to model fine-tuning (a feature Claude &lt;a href="https://www.anthropic.com/news/fine-tune-claude-3-haiku"&gt;provides via AWS Bedrock&lt;/a&gt;). People find this terminology confusing already, frequently misinterpreting "fine-tuning" as being the same thing as "tweaking your prompt until it works better", and Anthropic's language here doesn't help.

    &lt;p&gt;&lt;small&gt;&lt;/small&gt;Via &lt;a href="https://twitter.com/AnthropicAI/status/1823751314444021899"&gt;@AnthropicAI&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/ai"&gt;ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/prompt-engineering"&gt;prompt-engineering&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/generative-ai"&gt;generative-ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/llms"&gt;llms&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/anthropic"&gt;anthropic&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/claude"&gt;claude&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/gemini"&gt;gemini&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/llm-pricing"&gt;llm-pricing&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/prompt-caching"&gt;prompt-caching&lt;/a&gt;&lt;/p&gt;



</summary><category term="ai"/><category term="prompt-engineering"/><category term="generative-ai"/><category term="llms"/><category term="anthropic"/><category term="claude"/><category term="gemini"/><category term="llm-pricing"/><category term="prompt-caching"/></entry><entry><title>Context caching for Google Gemini</title><link href="https://simonwillison.net/2024/May/14/context-caching-for-google-gemini/#atom-tag" rel="alternate"/><published>2024-05-14T20:42:33+00:00</published><updated>2024-05-14T20:42:33+00:00</updated><id>https://simonwillison.net/2024/May/14/context-caching-for-google-gemini/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="https://ai.google.dev/gemini-api/docs/caching"&gt;Context caching for Google Gemini&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
Another new Gemini feature announced today. Long context models enable answering questions against large chunks of text, but the price of those long prompts can be prohibitive - $3.50/million for Gemini Pro 1.5 up to 128,000 tokens and $7/million beyond that.&lt;/p&gt;
&lt;p&gt;Context caching offers a price optimization, where the long prefix prompt can be reused between requests, halving the cost per prompt but at an additional cost of $4.50 / 1 million tokens per hour to keep that context cache warm.&lt;/p&gt;
&lt;p&gt;Given that hourly extra charge this isn't a default optimization for all cases, but certain high traffic applications might be able to save quite a bit on their longer prompt systems.&lt;/p&gt;
&lt;p&gt;It will be interesting to see if other vendors such as OpenAI and Anthropic offer a similar optimization in the future.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update 14th August 2024:&lt;/strong&gt; Anthropic's Claude now has its own version of &lt;a href="https://simonwillison.net/2024/Aug/14/prompt-caching-with-claude/"&gt;prompt caching&lt;/a&gt;.

    &lt;p&gt;&lt;small&gt;&lt;/small&gt;Via &lt;a href="https://twitter.com/officiallogank/status/1790454105539854648"&gt;@officiallogank&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/google"&gt;google&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/ai"&gt;ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/prompt-engineering"&gt;prompt-engineering&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/generative-ai"&gt;generative-ai&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/llms"&gt;llms&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/gemini"&gt;gemini&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/llm-pricing"&gt;llm-pricing&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/prompt-caching"&gt;prompt-caching&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/long-context"&gt;long-context&lt;/a&gt;&lt;/p&gt;



</summary><category term="google"/><category term="ai"/><category term="prompt-engineering"/><category term="generative-ai"/><category term="llms"/><category term="gemini"/><category term="llm-pricing"/><category term="prompt-caching"/><category term="long-context"/></entry></feed>