Skip to content

anthropic header selection across providers#2182

Merged
akshaydeo merged 2 commits into
mainfrom
03-20-anthropic_header_selection_across_providers
Mar 20, 2026
Merged

anthropic header selection across providers#2182
akshaydeo merged 2 commits into
mainfrom
03-20-anthropic_header_selection_across_providers

Conversation

@akshaydeo
Copy link
Copy Markdown
Contributor

@akshaydeo akshaydeo commented Mar 20, 2026

Summary

Adds comprehensive provider-specific feature validation and tool version management for Anthropic API features across different providers (Anthropic, Vertex AI, Bedrock, Azure). This ensures that unsupported tools are properly rejected or remapped based on each provider's capabilities.

Changes

  • Provider Feature Matrix: Added ProviderFeatureSupport struct and ProviderFeatures map defining which Anthropic features each provider supports (web search, web fetch, code execution, MCP, structured outputs, etc.)
  • Tool Validation: Implemented ValidateToolsForProvider() to reject unsupported tools early in the request pipeline
  • Version-Aware Tool Selection: Enhanced tool conversion logic to select appropriate tool versions based on both model capabilities and provider support (e.g., Vertex gets basic web search instead of dynamic filtering)
  • Provider-Aware Beta Headers: Modified AddMissingBetaHeadersToContext() to only inject beta headers supported by the target provider
  • Raw Body Tool Remapping: Added RemapRawToolVersionsForProvider() to automatically downgrade unsupported tool versions in raw request bodies
  • Computer Use Version Management: Added version-specific beta headers for different computer use tool versions (computer_20251124 vs computer_20250124)
  • Beta Header Filtering: Added FilterBetaHeadersForProvider() to validate beta headers against provider capabilities
  • Comprehensive Test Coverage: Added 1,207 lines of tests covering tool validation, version selection, beta header injection, and end-to-end workflows across all providers

Type of change

  • Feature
  • Refactor

Affected areas

  • Core (Go)
  • Providers/Integrations

How to test

# Run the new comprehensive test suite
go test ./core/internal/llmtests -v -run TestProvider

# Test tool validation across providers
go test ./core/providers/anthropic -v -run TestValidateToolsForProvider

# Test beta header injection per provider
go test ./core/providers/anthropic -v -run TestAddMissingBetaHeadersToContext

# Verify all existing tests still pass
go test ./...

Test different provider configurations:

  • Anthropic: All tools should work with full feature support
  • Vertex AI: Web search works (basic version only), web fetch/code execution rejected
  • Bedrock: Only client-side tools work, server tools rejected
  • Azure: All tools should work like Anthropic with full feature support

Breaking changes

  • Yes
  • No

This is backward compatible - existing requests continue to work, but now get better validation and appropriate tool versions for each provider.

Security considerations

The validation prevents sending unsupported tool requests to providers, reducing potential error exposure and ensuring requests conform to each provider's security model and feature limitations.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 20, 2026

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added provider-specific tool support validation and feature gating for Anthropic, Vertex, Bedrock, and Azure providers
    • Introduced computer use capability support with beta header management
    • Implemented tool version compatibility remapping for seamless cross-provider requests
  • Tests

    • Added comprehensive test suite for provider-specific tool validation, beta header injection, and feature support across all supported providers

Walkthrough

Adds per-provider feature flags, tool validation, raw-tool-version remapping, and provider-aware Anthropic beta-header gating; integrates these checks across Anthropic, Vertex, Bedrock, and Azure request flows and adds comprehensive unit and end-to-end tests.

Changes

Cohort / File(s) Summary
Feature flags & types
core/providers/anthropic/types.go
Introduced ProviderFeatureSupport, ProviderFeatures map, and two Anthropic computer-use beta header constants.
Anthropic utilities
core/providers/anthropic/utils.go, core/providers/anthropic/utils_test.go
Added ValidateToolsForProvider, exported AddMissingBetaHeadersToContext(..., provider), ToolVersionRemap, RemapRawToolVersionsForProvider, FilterBetaHeadersForProvider, and tests covering validation, header building/filtering, and raw remapping.
Anthropic integration
core/providers/anthropic/responses.go, core/providers/anthropic/anthropic.go
Tool conversion now receives provider; tool-variant selection consults ProviderFeatures; ChatCompletion/stream call AddMissingBetaHeadersToContext with provider.
Vertex integration
core/providers/vertex/vertex.go, core/providers/vertex/utils.go
Raw-path raw-tool-version remapping for Vertex; non-raw Params.Tools validation; provider-aware beta header addition, filtering for Vertex, and injection of anthropic_beta into JSON with error propagation.
Azure integration
core/providers/azure/azure.go, core/providers/azure/utils.go
Invoke anthropic.AddMissingBetaHeadersToContext(..., schemas.Azure) when building Anthropic-formatted requests (streaming and non-streaming paths).
Bedrock validation
core/providers/bedrock/responses.go
Validate Params.Tools via anthropic.ValidateToolsForProvider during conversion and abort on unsupported tools.
Tests & coverage
core/internal/llmtests/provider_feature_support_test.go, core/providers/anthropic/utils_test.go
New llmtests and unit tests covering provider feature map consistency, tool support validation, Anthropic conversion/version selection, beta-header injection (including computer-use headers), and raw JSON tool-version remapping.

Sequence Diagram

sequenceDiagram
    participant Client
    participant ProviderHandler as Provider Handler
    participant Validator as Feature Validator
    participant Converter as Tool Converter
    participant HeaderMgr as Beta Header Manager
    participant Context as Bifrost Context

    Client->>ProviderHandler: send request (model, tools, provider)
    ProviderHandler->>Validator: ValidateToolsForProvider(tools, provider)
    Validator-->>ProviderHandler: ok / error

    ProviderHandler->>Converter: convert tools to Anthropic format (provider)
    Converter->>Validator: consult ProviderFeatures[provider]
    Validator-->>Converter: feature flags
    Converter-->>ProviderHandler: converted tools

    ProviderHandler->>HeaderMgr: AddMissingBetaHeadersToContext(ctx, req, provider)
    HeaderMgr->>Validator: consult ProviderFeatures for header decisions
    Validator-->>HeaderMgr: supported features
    HeaderMgr->>Context: inject `anthropic-beta` extras as needed

    ProviderHandler->>ProviderHandler: RemapRawToolVersionsForProvider(jsonBody, provider) (if raw)
    ProviderHandler-->>Client: final request / error
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~60 minutes

🐰 A curious rabbit wrote:
I hopped through flags and remapped old seeds,
Tucked headers where Anthropic today needs,
Validators checked each tool on the way,
Tests keep the meadow from going astray,
Cheers for tidy hops across every clouded mead.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 68.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'anthropic header selection across providers' directly relates to the main objective of the PR, which is provider-specific handling of Anthropic beta headers and feature validation across multiple providers.
Description check ✅ Passed The PR description comprehensively follows the template with all major sections completed: clear summary, detailed changes, type of change selected, affected areas marked, testing instructions provided, breaking changes declared, and security considerations included. All checklist items are marked as completed.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 03-20-anthropic_header_selection_across_providers
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor Author

akshaydeo commented Mar 20, 2026

@akshaydeo akshaydeo mentioned this pull request Mar 20, 2026
18 tasks
@akshaydeo akshaydeo marked this pull request as ready for review March 20, 2026 07:45
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
core/providers/vertex/vertex.go (1)

403-425: ⚠️ Potential issue | 🟠 Major

Build anthropic_beta directly from the request instead of round-tripping through BifrostContextKeyExtraHeaders.

Using the context slot as temporary storage here is brittle for Vertex: if restricted writes are enabled, AddMissingBetaHeadersToContext can silently fail to persist the computed betas before you read them back, and any preexisting anthropic-beta values on the ctx get copied into the request body even when Vertex does not support them. Please compute the body field from reqBody (or have the helper return the slice) and treat HTTP/header propagation as a separate concern.

As per coding guidelines, BifrostContext reserved keys are silently dropped when BlockRestrictedWrites() is active; use custom key types for plugin data.

Also applies to: 768-792

🧹 Nitpick comments (2)
core/providers/anthropic/utils.go (1)

223-345: Consider removing unused error return value.

The function signature declares error as a return type but always returns nil. Either the error return should be removed, or the function should return errors for actual failure conditions (e.g., when context operations fail).

♻️ Option 1: Remove error return if not needed
-func AddMissingBetaHeadersToContext(ctx *schemas.BifrostContext, req *AnthropicMessageRequest, provider schemas.ModelProvider) error {
+func AddMissingBetaHeadersToContext(ctx *schemas.BifrostContext, req *AnthropicMessageRequest, provider schemas.ModelProvider) {
     // ... function body ...
-    return nil
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/providers/anthropic/utils.go` around lines 223 - 345, The function
AddMissingBetaHeadersToContext declares an error return but always returns nil;
either remove the error return from the signature and eliminate the final
"return nil" (and update all callers to not expect an error), or keep the error
return and actually propagate real errors from context ops (e.g., check
ctx.Value type assertions and ctx.SetValue success and return fmt.Errorf on
failures). Locate AddMissingBetaHeadersToContext and references to
schemas.BifrostContextKeyExtraHeaders, ctx.Value, and ctx.SetValue to implement
the chosen option and update all call sites accordingly.
core/providers/azure/azure.go (1)

557-558: Handle and propagate beta-header injection errors at both call sites.

anthropic.AddMissingBetaHeadersToContext(...) returns an error, but both calls currently ignore it. Please propagate the error to avoid silently continuing with incomplete header setup.

Proposed patch
-					// Add provider-aware beta headers for Azure
-					anthropic.AddMissingBetaHeadersToContext(ctx, reqBody, schemas.Azure)
+					// Add provider-aware beta headers for Azure
+					if err := anthropic.AddMissingBetaHeadersToContext(ctx, reqBody, provider.GetProviderKey()); err != nil {
+						return nil, err
+					}
@@
-					// Add provider-aware beta headers for Azure
-					anthropic.AddMissingBetaHeadersToContext(ctx, reqBody, schemas.Azure)
+					// Add provider-aware beta headers for Azure
+					if err := anthropic.AddMissingBetaHeadersToContext(ctx, reqBody, provider.GetProviderKey()); err != nil {
+						return nil, err
+					}

Also applies to: 686-687

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/providers/azure/azure.go` around lines 557 - 558, The calls to
anthropic.AddMissingBetaHeadersToContext(ctx, reqBody, schemas.Azure) ignore its
returned error; capture the returned error at both call sites in this file,
check if err != nil, and propagate it to the caller (e.g., return
fmt.Errorf("adding beta headers: %w", err) or return err) instead of continuing
silently. Update both occurrences so the error is handled consistently and
wrapped with context before returning.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@core/internal/llmtests/provider_feature_support_test.go`:
- Around line 208-972: Add a scenario-based Vertex integration test that
exercises the full provider path (not just anthropic helpers) by creating a
ComprehensiveTestConfig for provider=schemas.Vertex and driving a real request
through the provider harness, then validate behavior with the existing
validation presets (e.g., BasicChatExpectations or ToolCallExpectations) instead
of calling anthropic.ToAnthropicResponsesRequest/RemapRawToolVersionsForProvider
directly; reference the test harness symbols ComprehensiveTestConfig,
BasicChatExpectations, ToolCallExpectations and ensure the scenario covers a
Vertex case from the failing areas called out (e.g., beta header materialization
/ streamed-body remap), so regressions in core/providers/vertex/vertex.go are
caught.

In `@core/providers/anthropic/responses.go`:
- Around line 4697-4701: The opt-in logic incorrectly treats missing provider
entries as enabled for dynamic web tools; in the block that sets webSearchType
(using ProviderFeatures, provider, features, WebSearchDynamic, model and setting
AnthropicToolTypeWebSearch20260209) change the condition from (!ok ||
features.WebSearchDynamic) to ok && features.WebSearchDynamic so only mapped
providers with WebSearchDynamic=true select the 20260209 dynamic web_search (and
similarly ensure any analogous check for web_fetch_20260309 uses ok &&
features.WebSearchDynamic); this ensures unmapped providers safely fall back to
base tool versions.

In `@core/providers/anthropic/utils.go`:
- Around line 16-63: ValidateToolsForProvider currently omits handling for
ResponsesToolTypeFileSearch and ResponsesToolTypeImageGeneration; either
explicitly gate them or document intentional bypass. Update
ValidateToolsForProvider to add switch cases for ResponsesToolTypeFileSearch and
ResponsesToolTypeImageGeneration that check the corresponding provider feature
flags on features (e.g., features.FileSearch and features.ImageGeneration) and
return the same fmt.Errorf when unsupported, or if they are meant to be always
allowed, add a clear comment above the switch noting they intentionally bypass
provider-level gating.

In `@core/providers/vertex/utils.go`:
- Around line 106-107: The current flow calls
anthropic.AddMissingBetaHeadersToContext(ctx, reqBody, schemas.Vertex) but then
serializes whatever exists in BifrostContextKeyExtraHeaders["anthropic-beta"]
directly into the Vertex request, allowing pre-existing/unsupported flags to
leak; instead, read the extra-headers context entry, filter it using the same
provider-supported set (or call a helper that returns only supported headers),
and build a fresh anthropic_beta slice/string to serialize into the Vertex body
rather than reusing the raw context value—update the code around
AddMissingBetaHeadersToContext and the serialization logic to construct
anthropic_beta from the filtered list and replace any direct use of
BifrostContextKeyExtraHeaders["anthropic-beta"] so unsupported flags are never
propagated.
- Around line 69-73: When downgrading web_search tools for Vertex you must
remove dynamic filter fields and block unsupported beta headers: update
RemapRawToolVersionsForProvider and convertBifrostToolToAnthropic so that when a
tool type is remapped to the basic web_search version for schemas.Vertex you
strip filter arguments (AllowedDomains, BlockedDomains, UserLocation) from the
tool payload/args (so only the basic web_search fields remain); also update
AddMissingBetaHeadersToContext so it validates and filters any pre-existing
"anthropic-beta" headers against the provider feature set before merging (and
reapply provider-level filtering immediately before injecting headers into the
request body) to prevent unsupported beta flags from leaking to Vertex.

In `@core/providers/vertex/vertex.go`:
- Around line 482-489: The Anthropic tool-version remapping
(anthropic.RemapRawToolVersionsForProvider called when
schemas.IsAnthropicModel(deployment)) must run for streamed large-payload
requests too; move or duplicate the remap/validation to before
ApplyLargePayloadRequestBody is invoked (i.e., ensure the same logic that checks
jsonBody/jsonData and calls RemapRawToolVersionsForProvider executes on the
streaming path), and if you cannot remap there yet, fail fast by returning
providerUtils.NewBifrostOperationError with a clear message for streamed
Anthropic-on-Vertex bodies; reference the existing variables deployment,
jsonBody/jsonData, providerName, and the remapErr handling to mirror behavior on
the non-streaming path.

---

Nitpick comments:
In `@core/providers/anthropic/utils.go`:
- Around line 223-345: The function AddMissingBetaHeadersToContext declares an
error return but always returns nil; either remove the error return from the
signature and eliminate the final "return nil" (and update all callers to not
expect an error), or keep the error return and actually propagate real errors
from context ops (e.g., check ctx.Value type assertions and ctx.SetValue success
and return fmt.Errorf on failures). Locate AddMissingBetaHeadersToContext and
references to schemas.BifrostContextKeyExtraHeaders, ctx.Value, and ctx.SetValue
to implement the chosen option and update all call sites accordingly.

In `@core/providers/azure/azure.go`:
- Around line 557-558: The calls to
anthropic.AddMissingBetaHeadersToContext(ctx, reqBody, schemas.Azure) ignore its
returned error; capture the returned error at both call sites in this file,
check if err != nil, and propagate it to the caller (e.g., return
fmt.Errorf("adding beta headers: %w", err) or return err) instead of continuing
silently. Update both occurrences so the error is handled consistently and
wrapped with context before returning.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5cc52a8c-1773-4f35-8183-caae6d996577

📥 Commits

Reviewing files that changed from the base of the PR and between a0a1268 and dd332b9.

📒 Files selected for processing (11)
  • core/internal/llmtests/provider_feature_support_test.go
  • core/providers/anthropic/anthropic.go
  • core/providers/anthropic/responses.go
  • core/providers/anthropic/types.go
  • core/providers/anthropic/utils.go
  • core/providers/anthropic/utils_test.go
  • core/providers/azure/azure.go
  • core/providers/azure/utils.go
  • core/providers/bedrock/responses.go
  • core/providers/vertex/utils.go
  • core/providers/vertex/vertex.go

Comment thread core/internal/llmtests/provider_feature_support_test.go
Comment thread core/providers/anthropic/responses.go
Comment thread core/providers/anthropic/utils.go
Comment thread core/providers/vertex/utils.go
Comment thread core/providers/vertex/utils.go
Comment thread core/providers/vertex/vertex.go
@akshaydeo akshaydeo force-pushed the 03-20-anthropic_header_selection_across_providers branch from dd332b9 to 5767d72 Compare March 20, 2026 08:57
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
core/providers/vertex/utils.go (1)

75-81: ⚠️ Potential issue | 🟠 Major

Raw Vertex requests still drop beta flags.

The raw-body branch returns after setting anthropic_version, but never translates BifrostContextKeyExtraHeaders["anthropic-beta"] into the anthropic_beta body field. Since Vertex reads beta flags from the body, raw Anthropic-compatible requests can lose required betas here while the non-raw branch preserves them at Lines 123-131.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/providers/vertex/utils.go` around lines 75 - 81, The raw-body branch
currently only ensures anthropic_version via providerUtils.JSONFieldExists and
providerUtils.SetJSONField then returns, which drops the anthropic-beta flag;
update that branch to also read BifrostContextKeyExtraHeaders["anthropic-beta"]
from the request context and, if present, call providerUtils.SetJSONField to set
the anthropic_beta field in jsonBody (mirroring the non-raw branch behavior at
the lines handling anthropic_beta), handling and returning any error via
providerUtils.NewBifrostOperationError just like the anthropic_version handling.
♻️ Duplicate comments (3)
core/providers/anthropic/responses.go (2)

4697-4700: ⚠️ Potential issue | 🟠 Major

Do not auto-upgrade unknown providers to the dynamic web tool versions.

!ok || features.WebSearchDynamic makes an unmapped provider select web_search_20260209 / web_fetch_20260309, even though the surrounding comments say those variants are only available on Anthropic and Azure. Unknown providers should fall back to the base versions unless they are explicitly added to ProviderFeatures.

Suggested fix
-		if (!ok || features.WebSearchDynamic) &&
+		if ok && features.WebSearchDynamic &&
 			(strings.Contains(model, "4.6") || strings.Contains(model, "4-6")) {
 			webSearchType = AnthropicToolTypeWebSearch20260209
 		}
@@
-		if (!ok || features.WebSearchDynamic) &&
+		if ok && features.WebSearchDynamic &&
 			(strings.Contains(model, "4.6") || strings.Contains(model, "4-6")) {
 			webFetchType = AnthropicToolTypeWebFetch20260309
 		}

Also applies to: 4730-4732

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/providers/anthropic/responses.go` around lines 4697 - 4700, The
condition that chooses dynamic web tool variants incorrectly promotes unknown
providers because it uses "!ok || features.WebSearchDynamic"; change that logic
to require the provider be known and explicitly support dynamic web search by
using "ok && features.WebSearchDynamic" when checking ProviderFeatures[provider]
(the block that inspects ProviderFeatures, features.WebSearchDynamic, provider
and model for the web_search_20260209/web_fetch_20260309 selection). Make the
same change for the other occurrence that handles the same dynamic filtering
check so unknown providers fall back to the base variants unless explicitly
listed in ProviderFeatures.

4712-4715: ⚠️ Potential issue | 🟠 Major

Strip domain filters when the tool stays on web_search_20250305.

The fallback only changes the tool version. It still forwards AllowedDomains/BlockedDomains, so Vertex—and any other request that falls back to the basic web search tool—can still receive a dynamic-filter payload that the downgraded type does not support.

Suggested fix
-			if tool.ResponsesToolWebSearch.Filters != nil {
+			if tool.ResponsesToolWebSearch.Filters != nil && webSearchType == AnthropicToolTypeWebSearch20260209 {
 				anthropicTool.AnthropicToolWebSearch.AllowedDomains = tool.ResponsesToolWebSearch.Filters.AllowedDomains
 				anthropicTool.AnthropicToolWebSearch.BlockedDomains = tool.ResponsesToolWebSearch.Filters.BlockedDomains
 			}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/providers/anthropic/responses.go` around lines 4712 - 4715, When the
Responses tool remains on web_search_20250305 we must not forward dynamic domain
filters; change the copy logic so AllowedDomains/BlockedDomains are only
forwarded when the target tool version supports them. Specifically, in the block
that currently copies tool.ResponsesToolWebSearch.Filters into
anthropicTool.AnthropicToolWebSearch, check the tool version
(web_search_20250305) or the fallback condition and skip/clear AllowedDomains
and BlockedDomains for that case instead of copying them; leave other filter
fields intact only when version != "web_search_20250305".
core/providers/vertex/utils.go (1)

106-107: ⚠️ Potential issue | 🟠 Major

Filter pre-existing anthropic-beta values before writing anthropic_beta.

AddMissingBetaHeadersToContext() only appends provider-supported headers; it does not sanitize values that were already present on BifrostContextKeyExtraHeaders. This block writes the raw slice into the Vertex body, so unsupported upstream/manual beta flags can still leak through and make the request invalid. Build anthropic_beta from a Vertex-filtered list instead of extraHeaders["anthropic-beta"] directly.

Also applies to: 123-131

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/providers/vertex/utils.go` around lines 106 - 107, The code currently
writes extraHeaders["anthropic-beta"] directly into reqBody.anthropic_beta after
calling AddMissingBetaHeadersToContext; instead, read
BifrostContextKeyExtraHeaders, extract the "anthropic-beta" slice, filter its
values against the Vertex-supported beta names (the same whitelist used by
schemas.Vertex / AddMissingBetaHeadersToContext) and only set
reqBody.anthropic_beta to that filtered list; update both places that set
anthropic_beta (the block around AddMissingBetaHeadersToContext and the similar
block at lines 123-131) to use this sanitizing/filtering step so unsupported or
upstream values are not forwarded.
🧹 Nitpick comments (1)
core/providers/anthropic/utils.go (1)

250-259: Verify if advanced-tool-use beta header needs provider gating.

The AnthropicAdvancedToolUseBetaHeader is added unconditionally (without checking hasProvider/features) for DeferLoading, InputExamples, and AllowedCallers. If these features are only supported by certain providers, they should follow the same !hasProvider || features.X pattern used elsewhere.

If these features are universally supported across all Anthropic-compatible providers, consider adding a brief comment explaining this.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/providers/anthropic/utils.go` around lines 250 - 259, The code
unconditionally appends AnthropicAdvancedToolUseBetaHeader when
tool.DeferLoading, tool.InputExamples, or tool.AllowedCallers are present;
change each check to also gate on the provider feature flag using the same
pattern used elsewhere (e.g., use `if (!hasProvider || features.AdvancedToolUse)
&& tool.DeferLoading != nil && *tool.DeferLoading` and similarly for
`tool.InputExamples` and `tool.AllowedCallers`) so the header is only added when
the provider supports the advanced-tool-use feature; if these features truly are
universal, instead add a short comment above the block stating they are
supported by all Anthropic-compatible providers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@core/providers/vertex/utils.go`:
- Around line 75-81: The raw-body branch currently only ensures
anthropic_version via providerUtils.JSONFieldExists and
providerUtils.SetJSONField then returns, which drops the anthropic-beta flag;
update that branch to also read BifrostContextKeyExtraHeaders["anthropic-beta"]
from the request context and, if present, call providerUtils.SetJSONField to set
the anthropic_beta field in jsonBody (mirroring the non-raw branch behavior at
the lines handling anthropic_beta), handling and returning any error via
providerUtils.NewBifrostOperationError just like the anthropic_version handling.

---

Duplicate comments:
In `@core/providers/anthropic/responses.go`:
- Around line 4697-4700: The condition that chooses dynamic web tool variants
incorrectly promotes unknown providers because it uses "!ok ||
features.WebSearchDynamic"; change that logic to require the provider be known
and explicitly support dynamic web search by using "ok &&
features.WebSearchDynamic" when checking ProviderFeatures[provider] (the block
that inspects ProviderFeatures, features.WebSearchDynamic, provider and model
for the web_search_20260209/web_fetch_20260309 selection). Make the same change
for the other occurrence that handles the same dynamic filtering check so
unknown providers fall back to the base variants unless explicitly listed in
ProviderFeatures.
- Around line 4712-4715: When the Responses tool remains on web_search_20250305
we must not forward dynamic domain filters; change the copy logic so
AllowedDomains/BlockedDomains are only forwarded when the target tool version
supports them. Specifically, in the block that currently copies
tool.ResponsesToolWebSearch.Filters into anthropicTool.AnthropicToolWebSearch,
check the tool version (web_search_20250305) or the fallback condition and
skip/clear AllowedDomains and BlockedDomains for that case instead of copying
them; leave other filter fields intact only when version !=
"web_search_20250305".

In `@core/providers/vertex/utils.go`:
- Around line 106-107: The code currently writes extraHeaders["anthropic-beta"]
directly into reqBody.anthropic_beta after calling
AddMissingBetaHeadersToContext; instead, read BifrostContextKeyExtraHeaders,
extract the "anthropic-beta" slice, filter its values against the
Vertex-supported beta names (the same whitelist used by schemas.Vertex /
AddMissingBetaHeadersToContext) and only set reqBody.anthropic_beta to that
filtered list; update both places that set anthropic_beta (the block around
AddMissingBetaHeadersToContext and the similar block at lines 123-131) to use
this sanitizing/filtering step so unsupported or upstream values are not
forwarded.

---

Nitpick comments:
In `@core/providers/anthropic/utils.go`:
- Around line 250-259: The code unconditionally appends
AnthropicAdvancedToolUseBetaHeader when tool.DeferLoading, tool.InputExamples,
or tool.AllowedCallers are present; change each check to also gate on the
provider feature flag using the same pattern used elsewhere (e.g., use `if
(!hasProvider || features.AdvancedToolUse) && tool.DeferLoading != nil &&
*tool.DeferLoading` and similarly for `tool.InputExamples` and
`tool.AllowedCallers`) so the header is only added when the provider supports
the advanced-tool-use feature; if these features truly are universal, instead
add a short comment above the block stating they are supported by all
Anthropic-compatible providers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 77e3a660-5862-45d1-97cc-da15f011958d

📥 Commits

Reviewing files that changed from the base of the PR and between dd332b9 and 5767d72.

⛔ Files ignored due to path filters (2)
  • ui/public/images/google-workspace.png is excluded by !**/*.png
  • ui/public/images/zitadel.png is excluded by !**/*.png
📒 Files selected for processing (11)
  • core/internal/llmtests/provider_feature_support_test.go
  • core/providers/anthropic/anthropic.go
  • core/providers/anthropic/responses.go
  • core/providers/anthropic/types.go
  • core/providers/anthropic/utils.go
  • core/providers/anthropic/utils_test.go
  • core/providers/azure/azure.go
  • core/providers/azure/utils.go
  • core/providers/bedrock/responses.go
  • core/providers/vertex/utils.go
  • core/providers/vertex/vertex.go
✅ Files skipped from review due to trivial changes (5)
  • core/providers/anthropic/anthropic.go
  • core/providers/bedrock/responses.go
  • core/internal/llmtests/provider_feature_support_test.go
  • core/providers/vertex/vertex.go
  • core/providers/anthropic/utils_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • core/providers/azure/azure.go
  • core/providers/anthropic/types.go
  • core/providers/azure/utils.go

@akshaydeo akshaydeo force-pushed the 03-20-anthropic_header_selection_across_providers branch from 5767d72 to d27ccde Compare March 20, 2026 10:26
@akshaydeo akshaydeo force-pushed the 03-20-anthropic_header_selection_across_providers branch from d27ccde to 407ce34 Compare March 20, 2026 10:48
@akshaydeo akshaydeo force-pushed the 03-19-removing_map_marhsals_from_core branch from a0a1268 to 1bae615 Compare March 20, 2026 10:48
Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 20, 2026

✅ Actions performed

Full review triggered.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
core/providers/vertex/utils.go (1)

69-81: ⚠️ Potential issue | 🟠 Major

Filter raw anthropic_beta on the Vertex passthrough branch.

Lines 123-128 sanitize context-derived beta flags for the non-raw branch, but this raw branch still forwards any user-supplied anthropic_beta body field unchanged. A raw Vertex request can therefore carry unsupported flags like structured-outputs-* or mcp-client-* and fail downstream even though the non-raw path blocks them.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/providers/vertex/utils.go` around lines 69 - 81, Raw Vertex passthrough
currently forwards any user-supplied "anthropic_beta" which can include
unsupported flags; after the call to anthropic.RemapRawToolVersionsForProvider
and before returning, detect and sanitize/remove the "anthropic_beta" field on
jsonBody (use providerUtils.JSONFieldExists to check) by either removing the
field entirely or replacing it with a whitelisted/empty object via
providerUtils.SetJSONField so only allowed beta flags remain; ensure you reuse
the same error handling pattern (return providerUtils.NewBifrostOperationError
on SetJSONField errors) and keep DefaultVertexAnthropicVersion logic unchanged.
core/providers/anthropic/utils.go (1)

233-351: ⚠️ Potential issue | 🟡 Minor

Merge anthropic-beta values without duplicates.

The merge at Lines 346-349 appends onto any existing anthropic-beta slice verbatim. If the same BifrostContext already carries one of these headers—or this helper runs again during a retry/fallback—the duplicates now flow straight into Vertex’s anthropic_beta body array.

♻️ Proposed fix
-	if len(extraHeaders["anthropic-beta"]) == 0 {
-		extraHeaders["anthropic-beta"] = headers
-	} else {
-		extraHeaders["anthropic-beta"] = append(extraHeaders["anthropic-beta"], headers...)
-	}
+	mergedHeaders := extraHeaders["anthropic-beta"]
+	for _, header := range headers {
+		mergedHeaders = appendUniqueHeader(mergedHeaders, header)
+	}
+	extraHeaders["anthropic-beta"] = mergedHeaders
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/providers/anthropic/utils.go` around lines 233 - 351, The current
AddMissingBetaHeadersToContext merges headers into
extraHeaders["anthropic-beta"] by appending which can produce duplicates; change
the merge to deduplicate by combining the existing slice (if any) with the new
headers using the same uniqueness logic used elsewhere (e.g.,
appendUniqueHeader) so each header is present only once and order is preserved;
locate the merge around the extraHeaders handling and replace the verbatim
append (extraHeaders["anthropic-beta"] = append(...)) with logic that iterates
existing headers then new headers and builds a unique slice before calling
ctx.SetValue.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@core/providers/anthropic/utils.go`:
- Around line 233-351: The current AddMissingBetaHeadersToContext merges headers
into extraHeaders["anthropic-beta"] by appending which can produce duplicates;
change the merge to deduplicate by combining the existing slice (if any) with
the new headers using the same uniqueness logic used elsewhere (e.g.,
appendUniqueHeader) so each header is present only once and order is preserved;
locate the merge around the extraHeaders handling and replace the verbatim
append (extraHeaders["anthropic-beta"] = append(...)) with logic that iterates
existing headers then new headers and builds a unique slice before calling
ctx.SetValue.

In `@core/providers/vertex/utils.go`:
- Around line 69-81: Raw Vertex passthrough currently forwards any user-supplied
"anthropic_beta" which can include unsupported flags; after the call to
anthropic.RemapRawToolVersionsForProvider and before returning, detect and
sanitize/remove the "anthropic_beta" field on jsonBody (use
providerUtils.JSONFieldExists to check) by either removing the field entirely or
replacing it with a whitelisted/empty object via providerUtils.SetJSONField so
only allowed beta flags remain; ensure you reuse the same error handling pattern
(return providerUtils.NewBifrostOperationError on SetJSONField errors) and keep
DefaultVertexAnthropicVersion logic unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cc8b2c37-087d-4f12-bd33-ec1c456682e7

📥 Commits

Reviewing files that changed from the base of the PR and between 5767d72 and d27ccde.

⛔ Files ignored due to path filters (2)
  • ui/public/images/google-workspace.png is excluded by !**/*.png
  • ui/public/images/zitadel.png is excluded by !**/*.png
📒 Files selected for processing (11)
  • core/internal/llmtests/provider_feature_support_test.go
  • core/providers/anthropic/anthropic.go
  • core/providers/anthropic/responses.go
  • core/providers/anthropic/types.go
  • core/providers/anthropic/utils.go
  • core/providers/anthropic/utils_test.go
  • core/providers/azure/azure.go
  • core/providers/azure/utils.go
  • core/providers/bedrock/responses.go
  • core/providers/vertex/utils.go
  • core/providers/vertex/vertex.go
✅ Files skipped from review due to trivial changes (1)
  • core/providers/bedrock/responses.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • core/providers/azure/azure.go
  • core/providers/anthropic/anthropic.go
  • core/providers/anthropic/responses.go
  • core/providers/vertex/vertex.go
  • core/internal/llmtests/provider_feature_support_test.go

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 20, 2026

✅ Actions performed

Full review triggered.

@akshaydeo akshaydeo force-pushed the 03-20-anthropic_header_selection_across_providers branch from 407ce34 to df9a5e1 Compare March 20, 2026 11:42
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
core/providers/anthropic/utils.go (1)

338-350: ⚠️ Potential issue | 🟠 Major

Potential panic when BifrostContextKeyExtraHeaders has unexpected type.

If the context key exists but is not map[string][]string, extraHeaders remains nil and Line 347/349 writes to a nil map.

🛠️ Proposed fix
-	var extraHeaders map[string][]string
-	if ctx.Value(schemas.BifrostContextKeyExtraHeaders) == nil {
-		extraHeaders = map[string][]string{}
-	} else {
-		if ctxExtraHeaders, ok := ctx.Value(schemas.BifrostContextKeyExtraHeaders).(map[string][]string); ok {
-			extraHeaders = ctxExtraHeaders
-		}
-	}
+	extraHeaders := map[string][]string{}
+	if ctxExtraHeaders, ok := ctx.Value(schemas.BifrostContextKeyExtraHeaders).(map[string][]string); ok && ctxExtraHeaders != nil {
+		extraHeaders = ctxExtraHeaders
+	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/providers/anthropic/utils.go` around lines 338 - 350, The code can panic
if ctx.Value(schemas.BifrostContextKeyExtraHeaders) exists but isn't a
map[string][]string because extraHeaders stays nil; update the type-check branch
in the block using extraHeaders and ctxExtraHeaders so that if the assertion
fails you initialize extraHeaders = map[string][]string{} (instead of leaving it
nil), then proceed to set/append to extraHeaders["anthropic-beta"]; reference
the variables extraHeaders, ctx.Value(schemas.BifrostContextKeyExtraHeaders),
and ctxExtraHeaders when making this change.
🧹 Nitpick comments (3)
core/providers/vertex/utils.go (1)

69-73: Preserve the configured provider alias in validation errors.

These helpers need the base capability key, but they also bake "vertex" into the returned error text. For aliased Vertex providers, callers will get the wrong provider name even though providerName is already available here. Consider separating the lookup provider from the display provider, or rewrapping the message before returning. The same pattern was added in core/providers/bedrock/responses.go at Line 1644.

Based on learnings: When handling unsupported operations across providers, avoid hardcoding provider constants; use the actual provider key (or equivalent) so error messages adapt to custom provider names.

Also applies to: 83-87

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/providers/vertex/utils.go` around lines 69 - 73, The helper
anthropic.RemapRawToolVersionsForProvider and similar calls embed the literal
provider key (schemas.Vertex) into their returned error text which breaks
aliased provider names; update the error handling in the calls around
anthropic.RemapRawToolVersionsForProvider and the similar block (lines
referencing the same pattern) to preserve the configured providerName by
rewrapping or normalizing the error before passing to
providerUtils.NewBifrostOperationError — e.g., inspect err.Error(), replace
occurrences of schemas.Vertex (or the helper's lookup key) with providerName (or
construct a new error string including providerName) and then call
providerUtils.NewBifrostOperationError(cleanedErrorString, nil, providerName) so
displayed messages use the actual provider alias rather than the hardcoded
"vertex".
core/providers/anthropic/utils_test.go (1)

734-735: Assert the returned error from AddMissingBetaHeadersToContext in test flow.

Line 734 currently ignores the function error, which can mask regressions if validation logic evolves.

✅ Suggested test hardening
-			AddMissingBetaHeadersToContext(ctx, tt.req, tt.provider)
+			if err := AddMissingBetaHeadersToContext(ctx, tt.req, tt.provider); err != nil {
+				t.Fatalf("unexpected error: %v", err)
+			}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/providers/anthropic/utils_test.go` around lines 734 - 735, Capture and
assert the error returned by AddMissingBetaHeadersToContext instead of
discarding it: call err := AddMissingBetaHeadersToContext(ctx, tt.req,
tt.provider) and then assert the expected outcome (e.g., require.NoError(t, err)
or t.Fatalf on non-nil) using the test helpers in this file so failures in
validation logic are surfaced; reference the same ctx, tt.req and tt.provider
values used in the current test case.
core/providers/anthropic/utils.go (1)

192-192: Use providerName instead of hardcoded schemas.Anthropic for header gating.

Line 192 bypasses the function’s provider parameter and can drift from provider-aware behavior if this helper is reused across Anthropic-compatible providers.

♻️ Proposed change
-		AddMissingBetaHeadersToContext(ctx, reqBody, schemas.Anthropic)
+		AddMissingBetaHeadersToContext(ctx, reqBody, providerName)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/providers/anthropic/utils.go` at line 192, The call to
AddMissingBetaHeadersToContext currently uses the hardcoded schemas.Anthropic
which ignores the function's provider parameter; update the call to pass the
providerName (or the function's provider variable) instead of schemas.Anthropic
so header gating honors the actual provider; ensure any tests or callers that
rely on provider-specific behavior still pass and adjust any variable names if
needed to match the existing parameter (e.g., providerName).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@core/providers/anthropic/types.go`:
- Around line 50-52: The exported struct ProviderFeatureSupport in the Anthropic
provider should be renamed to include the provider prefix (e.g.,
AnthropicProviderFeatureSupport or AnthropicFeatureSupport) to follow the repo
naming rule; rename the type declaration (ProviderFeatureSupport ->
AnthropicProviderFeatureSupport) and update every usage/import/constructor/JSON
tag reference in the codebase to the new identifier (search for
ProviderFeatureSupport, methods or functions that accept/return it) so
compilation and public API are consistent.

In `@core/providers/anthropic/utils.go`:
- Around line 355-365: The exported provider-specific struct ToolVersionRemap
must be renamed to include the provider prefix (AnthropicToolVersionRemap) to
follow provider naming guidelines; update the type declaration and every usage
(e.g., change providerToolVersionRemaps's element type from []ToolVersionRemap
to []AnthropicToolVersionRemap and update any variables, function parameters,
returns, and imports that reference ToolVersionRemap) so the code compiles and
remains consistent across the package.

---

Outside diff comments:
In `@core/providers/anthropic/utils.go`:
- Around line 338-350: The code can panic if
ctx.Value(schemas.BifrostContextKeyExtraHeaders) exists but isn't a
map[string][]string because extraHeaders stays nil; update the type-check branch
in the block using extraHeaders and ctxExtraHeaders so that if the assertion
fails you initialize extraHeaders = map[string][]string{} (instead of leaving it
nil), then proceed to set/append to extraHeaders["anthropic-beta"]; reference
the variables extraHeaders, ctx.Value(schemas.BifrostContextKeyExtraHeaders),
and ctxExtraHeaders when making this change.

---

Nitpick comments:
In `@core/providers/anthropic/utils_test.go`:
- Around line 734-735: Capture and assert the error returned by
AddMissingBetaHeadersToContext instead of discarding it: call err :=
AddMissingBetaHeadersToContext(ctx, tt.req, tt.provider) and then assert the
expected outcome (e.g., require.NoError(t, err) or t.Fatalf on non-nil) using
the test helpers in this file so failures in validation logic are surfaced;
reference the same ctx, tt.req and tt.provider values used in the current test
case.

In `@core/providers/anthropic/utils.go`:
- Line 192: The call to AddMissingBetaHeadersToContext currently uses the
hardcoded schemas.Anthropic which ignores the function's provider parameter;
update the call to pass the providerName (or the function's provider variable)
instead of schemas.Anthropic so header gating honors the actual provider; ensure
any tests or callers that rely on provider-specific behavior still pass and
adjust any variable names if needed to match the existing parameter (e.g.,
providerName).

In `@core/providers/vertex/utils.go`:
- Around line 69-73: The helper anthropic.RemapRawToolVersionsForProvider and
similar calls embed the literal provider key (schemas.Vertex) into their
returned error text which breaks aliased provider names; update the error
handling in the calls around anthropic.RemapRawToolVersionsForProvider and the
similar block (lines referencing the same pattern) to preserve the configured
providerName by rewrapping or normalizing the error before passing to
providerUtils.NewBifrostOperationError — e.g., inspect err.Error(), replace
occurrences of schemas.Vertex (or the helper's lookup key) with providerName (or
construct a new error string including providerName) and then call
providerUtils.NewBifrostOperationError(cleanedErrorString, nil, providerName) so
displayed messages use the actual provider alias rather than the hardcoded
"vertex".
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 034a607d-d492-42c5-9f74-bf5f69fa5a63

📥 Commits

Reviewing files that changed from the base of the PR and between d27ccde and df9a5e1.

⛔ Files ignored due to path filters (2)
  • ui/public/images/google-workspace.png is excluded by !**/*.png
  • ui/public/images/zitadel.png is excluded by !**/*.png
📒 Files selected for processing (11)
  • core/internal/llmtests/provider_feature_support_test.go
  • core/providers/anthropic/anthropic.go
  • core/providers/anthropic/responses.go
  • core/providers/anthropic/types.go
  • core/providers/anthropic/utils.go
  • core/providers/anthropic/utils_test.go
  • core/providers/azure/azure.go
  • core/providers/azure/utils.go
  • core/providers/bedrock/responses.go
  • core/providers/vertex/utils.go
  • core/providers/vertex/vertex.go
✅ Files skipped from review due to trivial changes (2)
  • core/providers/azure/utils.go
  • core/internal/llmtests/provider_feature_support_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • core/providers/anthropic/responses.go
  • core/providers/azure/azure.go
  • core/providers/anthropic/anthropic.go
  • core/providers/vertex/vertex.go

Comment thread core/providers/anthropic/types.go
Comment thread core/providers/anthropic/types.go
Comment thread core/providers/anthropic/utils.go
@akshaydeo akshaydeo force-pushed the 03-20-anthropic_header_selection_across_providers branch from df9a5e1 to 2e01dbc Compare March 20, 2026 13:30
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
core/providers/anthropic/anthropic.go (2)

434-441: Consider handling the error return from AddMissingBetaHeadersToContext.

The function returns an error, but it's being discarded. While the current implementation always returns nil, propagating the error would future-proof this code against changes to the function.

♻️ Suggested change
 		func() (providerUtils.RequestBodyWithExtraParams, error) {
 			anthropicReq, convErr := ToAnthropicChatRequest(ctx, request)
 			if convErr != nil {
 				return nil, convErr
 			}
-			AddMissingBetaHeadersToContext(ctx, anthropicReq, schemas.Anthropic)
+			if err := AddMissingBetaHeadersToContext(ctx, anthropicReq, schemas.Anthropic); err != nil {
+				return nil, err
+			}
 			return anthropicReq, nil
 		},
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/providers/anthropic/anthropic.go` around lines 434 - 441, The anonymous
function currently ignores the error returned by AddMissingBetaHeadersToContext;
update it to capture and propagate that error: after calling
ToAnthropicChatRequest(ctx, request) and before returning anthropicReq, call
AddMissingBetaHeadersToContext(ctx, anthropicReq, schemas.Anthropic), check its
returned error, and if non-nil return nil, err (rather than discarding it), so
the function (the providerUtils.RequestBodyWithExtraParams-producing closure
around ToAnthropicChatRequest and AddMissingBetaHeadersToContext) correctly
forwards any header-addition failures.

517-525: Same pattern: handle the error return for consistency.

Similar to ChatCompletion, the error return from AddMissingBetaHeadersToContext should be propagated.

♻️ Suggested change
 		func() (providerUtils.RequestBodyWithExtraParams, error) {
 			anthropicReq, convErr := ToAnthropicChatRequest(ctx, request)
 			if convErr != nil {
 				return nil, convErr
 			}
 			anthropicReq.Stream = schemas.Ptr(true)
-			AddMissingBetaHeadersToContext(ctx, anthropicReq, schemas.Anthropic)
+			if err := AddMissingBetaHeadersToContext(ctx, anthropicReq, schemas.Anthropic); err != nil {
+				return nil, err
+			}
 			return anthropicReq, nil
 		},
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/providers/anthropic/anthropic.go` around lines 517 - 525, The closure
currently ignores the error from AddMissingBetaHeadersToContext; update the
anonymous function that builds the providerUtils.RequestBodyWithExtraParams (the
block that calls ToAnthropicChatRequest and sets anthropicReq.Stream) to capture
the error returned by AddMissingBetaHeadersToContext (e.g., err :=
AddMissingBetaHeadersToContext(ctx, anthropicReq, schemas.Anthropic)) and if err
!= nil return nil, err so the error is propagated consistently alongside the
convErr handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@core/providers/anthropic/anthropic.go`:
- Around line 434-441: The anonymous function currently ignores the error
returned by AddMissingBetaHeadersToContext; update it to capture and propagate
that error: after calling ToAnthropicChatRequest(ctx, request) and before
returning anthropicReq, call AddMissingBetaHeadersToContext(ctx, anthropicReq,
schemas.Anthropic), check its returned error, and if non-nil return nil, err
(rather than discarding it), so the function (the
providerUtils.RequestBodyWithExtraParams-producing closure around
ToAnthropicChatRequest and AddMissingBetaHeadersToContext) correctly forwards
any header-addition failures.
- Around line 517-525: The closure currently ignores the error from
AddMissingBetaHeadersToContext; update the anonymous function that builds the
providerUtils.RequestBodyWithExtraParams (the block that calls
ToAnthropicChatRequest and sets anthropicReq.Stream) to capture the error
returned by AddMissingBetaHeadersToContext (e.g., err :=
AddMissingBetaHeadersToContext(ctx, anthropicReq, schemas.Anthropic)) and if err
!= nil return nil, err so the error is propagated consistently alongside the
convErr handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 40ee83b5-a1b7-4747-9dc8-69ac402e063f

📥 Commits

Reviewing files that changed from the base of the PR and between df9a5e1 and 2e01dbc.

⛔ Files ignored due to path filters (2)
  • ui/public/images/google-workspace.png is excluded by !**/*.png
  • ui/public/images/zitadel.png is excluded by !**/*.png
📒 Files selected for processing (11)
  • core/internal/llmtests/provider_feature_support_test.go
  • core/providers/anthropic/anthropic.go
  • core/providers/anthropic/responses.go
  • core/providers/anthropic/types.go
  • core/providers/anthropic/utils.go
  • core/providers/anthropic/utils_test.go
  • core/providers/azure/azure.go
  • core/providers/azure/utils.go
  • core/providers/bedrock/responses.go
  • core/providers/vertex/utils.go
  • core/providers/vertex/vertex.go
✅ Files skipped from review due to trivial changes (4)
  • core/providers/anthropic/utils_test.go
  • core/internal/llmtests/provider_feature_support_test.go
  • core/providers/vertex/vertex.go
  • core/providers/anthropic/utils.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • core/providers/azure/utils.go
  • core/providers/bedrock/responses.go
  • core/providers/vertex/utils.go
  • core/providers/azure/azure.go

Copy link
Copy Markdown
Contributor Author

akshaydeo commented Mar 20, 2026

Merge activity

  • Mar 20, 4:42 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Mar 20, 4:44 PM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo akshaydeo changed the base branch from 03-19-removing_map_marhsals_from_core to graphite-base/2182 March 20, 2026 16:43
@akshaydeo akshaydeo changed the base branch from graphite-base/2182 to main March 20, 2026 16:43
@akshaydeo akshaydeo merged commit ca3b0c4 into main Mar 20, 2026
2 of 4 checks passed
@akshaydeo akshaydeo deleted the 03-20-anthropic_header_selection_across_providers branch March 20, 2026 16:44
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.

2 participants