Skip to content

fix: forward Anthropic-Beta header to Anthropic provider#205

Merged
ssncferreira merged 1 commit intomainfrom
ssncf/fix-anthropic-beta-header
Mar 6, 2026
Merged

fix: forward Anthropic-Beta header to Anthropic provider#205
ssncferreira merged 1 commit intomainfrom
ssncf/fix-anthropic-beta-header

Conversation

@ssncferreira
Copy link
Contributor

@ssncferreira ssncferreira commented Mar 6, 2026

Description

AI Bridge drops client request headers when making upstream API calls through bridge routes. This causes failures when the client sends headers that correspond to features used in the request body. For example, Claude Code sends Anthropic-Beta: context-management alongside a context_management field in the body. AI Bridge preserves the body but drops the header, causing Anthropic to reject the request.

Rather than forwarding all client headers (addressed in #195), this PR takes a targeted approach by forwarding only known required headers for Anthropic, matching the same pattern used by the Copilot provider with ExtraHeaders.

Related to #192

Note: This is an intermediary fix. The full solution, forwarding all client headers to upstream providers, is tracked in #195. Related to internal Slack thread: https://codercom.slack.com/archives/C096PFVBZKN/p1772792545309049

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ssncferreira ssncferreira marked this pull request as ready for review March 6, 2026 11:36
Copy link
Collaborator

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

LGTM

assert.Contains(t, err.Error(), "unmarshal request body")
})

t.Run("Messages_ForwardsAnthropicBetaHeaderToUpstream", func(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: AFAICS this is the only relevant sub-test.
Adding the others is a nice improvement, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the others are not really testing the header logic. Should have been added in another PR, sorry about that

"github.com/coder/aibridge/internal/testutil"
)

func TestAnthropic_CreateInterceptor(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Those test look quite copy-pasty, eg. body in each test case looks the same or verification that interceptor was created without error.
Would it be possible to shorten them with table test approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably, yes. I reused some from the Copilot tests, so we should probably update there as well.

@ssncferreira ssncferreira merged commit 1e9e0d8 into main Mar 6, 2026
5 checks passed
ssncferreira added a commit that referenced this pull request Mar 6, 2026
ssncferreira added a commit to coder/coder that referenced this pull request Mar 6, 2026
…fix (#22711)

Bumps aibridge to include coder/aibridge#205
which forwards the Anthropic-Beta header to the upstream Anthropic API.

Related to: 
* issue: coder/aibridge#192
* Internal Slack thread:
https://codercom.slack.com/archives/C096PFVBZKN/p1772792545309049
@ssncferreira ssncferreira deleted the ssncf/fix-anthropic-beta-header branch March 6, 2026 16:23
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.

3 participants