Prompt caching is useful for repeated system prompts, long document context, and fixed agent instructions. TTL, hit rules, and pricing vary by model.
Minimum prefix sizes and TTLs vary by model. Short prompts usually do not benefit much; verify cache hits through usage.cached_tokens before relying on it.
import osfrom openai import OpenAIclient = OpenAI(base_url="https://api.sealink.io/v1",api_key=os.environ["SEALINK_API_KEY"],)# Long, reusable system prompt — cached on the first call.SYSTEM = open("knowledge_base.md").read() # imagine 50KBresp = client.chat.completions.create(model="claude-opus-5-5",messages=[{"role": "system","content": SYSTEM,# Use only with models that support cache_control."cache_control": {"type": "ephemeral"},},{"role": "user", "content": "Question 1"},],)# Subsequent calls may report cached_tokens when the cache is used.print(resp.usage.prompt_tokens_details)# {"cached_tokens": 12500}
How to evaluate caching
Start with one high-volume workflow and compare input_tokens, cached_tokens, latency, and actual cost before and after enabling caching. Caching is most useful when the same long context is reused many times.
Check cached_tokens in usage records. If it stays at 0, the selected model, prompt shape, or call pattern is not producing effective cache hits.