Prompt Caching Not Applied When Schema Changes

Welcome to the community @dyeoman2

This a very good question.

From the docs:

What can be cached

  • Structured outputs: The structured output schema serves as a prefix to the system message and can be cached.

This means that changing the structured output schema which itself serves as a prefix to the system message would result in a cache miss because the cached prefix is changed.

Structuring Prompts

Cache hits are only possible for exact prefix matches within a prompt. To realize caching benefits, place static content like instructions and examples at the beginning of your prompt, and put variable content, such as user-specific information, at the end. This also applies to images and tools, which must be identical between requests.

5 Likes