[Feature Request]: Leverage prompt caching by swapping instructions & content #1699
Replies: 2 comments
|
We implemented this — PR #1873. All 4 extraction prompts in If you want to try it before it's merged: pip install git+https://github.com/hafezparast/crawl4ai.git@fix/prompt-caching-order-1699To verify caching is working, check your provider's dashboard for cached token counts after running a batch extraction across multiple pages with the same Would be great to hear if you see the expected cost reduction in practice — especially the actual cache hit rate across a real crawl session. |
|
Strong idea. For crawler-style extraction, the prompt structure is often more important than the model choice: keep stable instructions/cacheable schema separate from changing page content, then measure cost per extracted page rather than per request. I am testing an OpenAI-compatible multi-model API layer around official Chinese models, and prompt-caching plus model routing is exactly where these workloads can get much cheaper without changing the app architecture. |
Uh oh!
There was an error while loading. Please reload this page.
What needs to be done?
We should first give the instructions in the prompt, then give the URL & Content : https://github.com/unclecode/crawl4ai/blob/main/crawl4ai/prompts.py
What problem does this solve?
We could leverage prompt caching. Depending on the provider, the cached tokens for input can ben up to 90% cheaper than normal input tokens. In my use-case, I'm crawling a lot of different pages with the same instructions set.
If we change the prompt to be :
We could also leverage on prompt caching for the HTML content which is quite the same (for example common body structure).
Target users/beneficiaries
Everyone using LLM Extraction. It would be cheaper at the end. For example with OpenAI : https://platform.openai.com/docs/pricing
Current alternatives/workarounds
No response
Proposed approach
No response
All reactions