Skip to content

fix: address cache_control/beta-header passthrough review issues#124

Open
Milo0821 wants to merge 3 commits into
aws-samples:mainfrom
Milo0821:fix/pr123-review-issues
Open

fix: address cache_control/beta-header passthrough review issues#124
Milo0821 wants to merge 3 commits into
aws-samples:mainfrom
Milo0821:fix/pr123-review-issues

Conversation

@Milo0821
Copy link
Copy Markdown
Contributor

@Milo0821 Milo0821 commented May 13, 2026

Summary

  • anthropic-beta header passthrough from client → Bedrock, filtered against a compile-time BEDROCK_BETA_BLOCKLIST of unsupported headers
  • cache_controlcachePoint translation for user message blocks, tool definitions, and system blocks
  • Model-specific beta feature auto-injection via Set (deduplication)

🤖 Generated with Claude Code

Milo0821 and others added 3 commits May 13, 2026 10:59
Clients using the Anthropic SDK can annotate messages, system blocks,
and tool definitions with cache_control: { type: "ephemeral" } to enable
prompt caching. These markers were previously silently dropped.

This change maps them to Bedrock cachePoint: { type: "default" } blocks
at all three locations: system blocks, user message content, and tool
definitions. The existing config-based promptCache approach is preserved
as a fallback for backward compatibility.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…ude Code compatibility

Add BEDROCK_BETA_BLOCKLIST constant to strip Anthropic-specific beta headers
that Bedrock does not support (files-api, computer-use, prompt-caching-scope,
redact-thinking, advisor-tool). Pass the client's anthropic-beta header through
both complete() and chat() entry points into toPayload(), merging with
auto-injected model-specific features while filtering blocklisted values.
Deduplication is handled by switching from array to Set<string>.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Four correctness and quality issues identified in code review:

1. Double-system-content bug (provider.ts): when body.system is an
   array, the old code pushed a flattened role:'system' message into
   messages[] AND set system_blocks, causing fragile dual-path routing.
   Now only the string case pushes to messages[]; array form is handled
   exclusively via system_blocks.

2. Mutation of shared messages array (bedrock_converse.ts): the user-
   message loop mutated message.content in place, corrupting the original
   chatRequest on retries. Fixed by computing into newContent and pushing
   a shallow clone { ...message, content: newContent }.

3. cache_control leaked to Bedrock (bedrock_converse.ts): the fallthrough
   return in convertConverseSingleType forwarded cache_control on unknown
   content types, risking ValidationException. Now strips it via
   destructuring before returning.

4. Import order violation (bedrock_converse.ts): BEDROCK_BETA_BLOCKLIST
   const was declared between two import statements, violating ESLint
   import/first. Moved to after all imports.

Also adds a typed system_blocks field to the ChatRequest interface
(chat_request.ts) so TypeScript catches typos at compile time.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

1 participant