Skip to content

translator: preserve query string on Anthropic passthrough - #2844

Merged
nacx merged 3 commits into
theagentrouter:mainfrom
kerthans:fix/anthropic-preserve-query
Oct 20, 2026
Merged

nacx merged 3 commits into
theagentrouter:mainfrom
kerthans:fix/anthropic-preserve-query

Conversation

@kerthans

Copy link
Copy Markdown
Contributor

Description

The Anthropic passthrough translator replaced :path with the backend messages path (for example /v1/messages), which dropped the query string of the client request. Claude Code calls /anthropic/v1/messages?beta=true, so an Anthropic-schema backend received /v1/messages without ?beta=true.

This makes anthropicToAnthropicTranslator implement RequestHeadersSetter. It reads the query from the x-ai-eg-original-path header, which extproc sets to the original client path, and appends it to the rewritten path in RequestBody.

The AWS and GCP Anthropic translators embed this type but override both SetRequestHeaders and RequestBody and build their own paths, so their behavior is unchanged. A generic fix in the upstream processor would also touch backends that sign or build their own query strings (SigV4, GCP), so this keeps the change to the Anthropic passthrough.

Tests: added cases to TestAnthropicToAnthropic_RequestBody for a query string, a query string together with a model name override, and an original path without a query. go test ./internal/translator/ ./internal/extproc/ ./internal/endpointspec/ and golangci-lint run ./internal/translator/... pass.

Related Issues/PRs (if applicable)

Fixes #2842

Special notes for reviewers (if applicable)

The count_tokens passthrough has the same pattern and could get the same change in a follow-up.

AI tools were used to help write this change. I reviewed the code and tests and understand them.

The Anthropic passthrough translator replaced :path with the backend
messages path, which dropped the query string of the client request.
Claude Code calls /v1/messages?beta=true, so the backend received
/v1/messages without it.

Read the query from the original path header and append it to the
rewritten path. The AWS and GCP Anthropic translators override both
SetRequestHeaders and RequestBody and build their own paths, so they
are unchanged.

Fixes theagentrouter#2842

Signed-off-by: kerthans <1255829396@qq.com>
@kerthans
kerthans requested a review from a team as a code owner October 13, 2026 03:22
@netlify

netlify Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for theagentrouter canceled.

Name Link
🔨 Latest commit abe0eaf
🔍 Latest deploy log https://app.netlify.com/projects/theagentrouter/deploys/6ad735072500bb3387a03d1f

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@nacx
nacx enabled auto-merge (squash) October 20, 2026 09:32
@nacx
nacx merged commit f89fa2b into theagentrouter:main Oct 20, 2026
40 checks passed
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.

Anthropic Messages route drops the query string: /anthropic/v1/messages?beta=true reaches the backend as /v1/messages

3 participants