Tutorial: enable and verify prompt caching
In this tutorial, you will enable manual prompt caching on a model deployment, send two chat completion requests that share a long prefix, and confirm from the response that the second request hit the cache. By the end, you will know how to mark a cache breakpoint and how to read cached-token counts from the response usage. This tutorial is for developers who can already call the Unified API; for the concepts behind caching, read How prompt caching works first.
Prerequisites
- A running DIAL deployment and its base URL, referred to below as
<DIAL_URL>. - A DIAL API key, referred to below as
<YOUR_DIAL_API_KEY>. - A
chatmodel deployment in DIAL whose provider supports prompt caching, referred to below as<DEPLOYMENT_NAME>. Confirm caching support with your provider before starting. - Edit access to the DIAL Core
config.json(dynamic settings). curlandjqinstalled.
What you'll do
- Turn on manual caching for the deployment with the
cacheSupportedflag. - Send a first request with a
cache_breakpointafter a long shared prefix and store the cache entry. - Send a second request that shares the same prefix and observe a cache hit in the response usage.
Project structure
By the end of this tutorial, your working directory will look like this:
dial-prompt-caching/