feat(ai): restore promptCaching support for Anthropic and OpenAI caching stats#1855
Merged
Conversation
Agent-Logs-Url: https://github.com/OpenAF/openaf/sessions/62a5d58d-75bd-4f94-a820-746c4b047a40 Co-authored-by: nmaguiar <11761746+nmaguiar@users.noreply.github.com>
Agent-Logs-Url: https://github.com/OpenAF/openaf/sessions/62a5d58d-75bd-4f94-a820-746c4b047a40 Co-authored-by: nmaguiar <11761746+nmaguiar@users.noreply.github.com>
Agent-Logs-Url: https://github.com/OpenAF/openaf/sessions/62a5d58d-75bd-4f94-a820-746c4b047a40 Co-authored-by: nmaguiar <11761746+nmaguiar@users.noreply.github.com>
Agent-Logs-Url: https://github.com/OpenAF/openaf/sessions/62a5d58d-75bd-4f94-a820-746c4b047a40 Co-authored-by: nmaguiar <11761746+nmaguiar@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
promptCachingoption for the Anthropic provider inow.ai.gpt, enabling Anthropic's prompt caching beta (anthropic-beta: prompt-caching-2024-07-31) withcache_controlmarkers on system prompts and the last user messageprompt_tokens_details.cached_tokens,audio_tokens, andcompletion_tokens_details.reasoning_tokenstestAIOpenAIStatsCaptureIncludesCachedAndReasoning,testAIAnthropicPromptCachingHeaders,testAIAnthropicPromptCachingBodyAndStatsThis feature was originally added via PR #1841 and reverted in PR #1843. It has been live in the
t8branch (via PR #1844) and this PR cherry-picks the same 4 implementation commits onto master.Test plan
tests/autoTestAll.AI.js— all 3 new tests should passow.ai.gpt("anthropic", { promptCaching: true })addsanthropic-betaheader to requestsgetLastStats()returnstokens.cacheCreationandtokens.cacheReadfor Anthropic responses🤖 Generated with Claude Code