Skip to content

feat(openai): support manually placed prompt cache breakpoints in the Responses API#2171

Open
dgrijalva wants to merge 1 commit into
0xPlaygrounds:mainfrom
dgrijalva:feat/openai-prompt-cache-breakpoints
Open

feat(openai): support manually placed prompt cache breakpoints in the Responses API#2171
dgrijalva wants to merge 1 commit into
0xPlaygrounds:mainfrom
dgrijalva:feat/openai-prompt-cache-breakpoints

Conversation

@dgrijalva

Copy link
Copy Markdown
Contributor

Fixes #2170

Implementation

  • PromptCacheBreakpoint / PromptCacheBreakpointMode::Explicit and PromptCacheOptions / PromptCacheMode wire types; prompt_cache_breakpoint on InputText / InputImage / InputFile (skipped when None, so existing wire output is unchanged); prompt_cache_options on AdditionalParameters (previously silently dropped as an unknown key).
  • Documented pub const OPENAI_PROMPT_CACHE_BREAKPOINT_KEY (with doctest); the marker is extracted from block additional_params in both conversion paths (TryFrom<crate::completion::Message> for Vec<InputItem> and responses_user_content) across all five input-block arms. Invalid payloads fail conversion. Assistant content is not scanned — OpenAI documents breakpoints on input blocks only.

Testing

  • 7 unit tests + doctest: exact placement in a multi-turn history, image/file blocks, both conversion paths, invalid-payload rejection, sibling-param tolerance, request-level options serialization.
  • Cassette test recorded live against gpt-5.6: the marked ~6.7k-token block produced a real cache hit (cached_tokens: 6739 of 6766 in the recorded usage) and the fixture assertion pins the request body (breakpoint on the marked block only; prompt_cache_options / prompt_cache_key at top level). Full OpenAI cassette suite replays green. (One recorder quirk: prompt_cache_key values get redacted as identifiers, so the fixture assertion checks presence, not value.)
  • cargo clippy --all-features --all-targets and cargo fmt -- --check clean.

Note on API design: the additional_params carrier and public key const are our best guess at the rig-native shape (mirroring the Anthropic document title/citations pattern). Happy to rework if you'd prefer a different mechanism.

Related: #2168 (Anthropic counterpart)

… Responses API

OpenAI added explicit prompt-cache breakpoints for GPT-5.6+: a
prompt_cache_breakpoint field on input_text/input_image/input_file
content parts, and a request-level prompt_cache_options object.

A breakpoint is placed at a chosen position in the history by setting
the documented OPENAI_PROMPT_CACHE_BREAKPOINT_KEY in a text, image, or
document block's additional_params; both message conversion paths
extract the marker onto the corresponding content part. Request-level
prompt_cache_options passes through additional_params, which previously
dropped it as an unknown AdditionalParameters field.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: support OpenAI prompt cache breakpoints (Responses API)

1 participant