Add provider-specific prompt caching support in owrap.ai.js (OpenAI + Anthropic)#1844
Merged
Conversation
Update dependencies and enhance documentation for OpenAF
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>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…into replicate-1841-t8
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.
This PR extends GPT provider handling in
js/owrap.ai.jsto properly surface prompt-cache token accounting and enable Anthropic prompt caching controls without changing default behavior. Gemini/Ollama behavior remains unchanged aside from documentation clarity.\n\n- OpenAI: capture cache-aware usage stats\n - Extended_captureStatsto include nested usage fields when present:\n -usage.prompt_tokens_details.cached_tokens→tokens.cached\n -usage.prompt_tokens_details.audio_tokens→tokens.audio\n -usage.completion_tokens_details.reasoning_tokens→tokens.reasoning\n\n- Anthropic: opt-in prompt caching support\n - AddedaOptions.promptCaching(defaultfalse).\n - When enabled, both_requestand_requestStreamsend:\n -anthropic-beta: prompt-caching-2024-07-31\n - Extended_captureStatswith:\n -usage.cache_creation_input_tokens→tokens.cacheCreation\n -usage.cache_read_input_tokens→tokens.cacheRead\n\n- Anthropic: cache boundary hints in payload\n - WhenpromptCachingis enabled:\n -systemis emitted as content blocks withcache_control: { type: \"ephemeral\" }.\n - The last cacheable user message/block is marked withcache_control: { type: \"ephemeral\" }(while avoiding tool_result-only blocks).\n\n- ODoc updates (ow.ai.gpt+ ``)\n - DocumentedpromptCachingoption for Anthropic.\n - Documented that `getLastStats()` now includes OpenAI cached-token accounting and Anthropic cache read/creation token counters.\n - Added note that Gemini may implicitly cache large system instructions.\n\n- Focused AI tests\n - Added tests for:\n - OpenAI cached/audio/reasoning token capture.\n - Anthropic prompt-caching beta header behavior.\n - Anthropic `cache_control` payload shaping and cache stats extraction.\n\njavascript\nif (isMap(aResponse.usage.prompt_tokens_details)) {\n if (isDef(aResponse.usage.prompt_tokens_details.cached_tokens))\n tokens.cached = aResponse.usage.prompt_tokens_details.cached_tokens;\n}\nif (isMap(aResponse.usage.completion_tokens_details)) {\n if (isDef(aResponse.usage.completion_tokens_details.reasoning_tokens))\n tokens.reasoning = aResponse.usage.completion_tokens_details.reasoning_tokens;\n}\n