Use prompt caching in the Anthropic machinery - #21310
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f085007d02
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| { | ||
| "type": "text", | ||
| "text": prompt, | ||
| "cache_control": {"type": "ephemeral"}, |
There was a problem hiding this comment.
Gate caching for one-off Anthropic requests
When the system prefix meets Anthropic's minimum cacheable length but no identical request follows within the five-minute TTL, this unconditional breakpoint creates a cache write billed at 1.25× the normal input rate without any discounted cache read. Because this payload is used for ordinary editor suggestions and settings validation as well as sequential automatic-translation batches, installations making sporadic requests—or jobs completed in one batch—will pay more despite the changelog's cost-reduction claim; restrict caching to repeated/bulk traffic or make it configurable.
Useful? React with 👍 / 👎.
Fixes #21309
The Anthropic machinery sends the system prompt as a plain string, so Anthropic's prompt caching (which is opt-in per request) never kicks in. The system prompt is identical for every request to a given target language, and with a bigger style guide it is easily a few thousand tokens billed at full input price on every request during automatic translation.
This change sends the system prompt as a content block with cache_control set to ephemeral. Cached reads are billed at roughly 10% of the input price with a 5 minute sliding TTL, which matches back-to-back automatic translation requests well. Below the minimum cacheable prefix (about 1024 tokens) the API silently ignores cache_control, so the change is safe unconditionally.
Includes a test asserting the request payload shape and a changelog entry.