fix(wrap): preserve pre-set ANTHROPIC_BASE_URL as proxy upstream#1358
Open
ousamabenyounes wants to merge 2 commits into
Open
fix(wrap): preserve pre-set ANTHROPIC_BASE_URL as proxy upstream#1358ousamabenyounes wants to merge 2 commits into
ousamabenyounes wants to merge 2 commits into
Conversation
Contributor
PR governanceThis PR does not yet satisfy the required template fields:
Please update the PR body, or move the PR back to draft while it is still in progress. |
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
JerrettDavis
approved these changes
Jun 24, 2026
JerrettDavis
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed the wrap claude inbound upstream handling and ran uv run --with pytest python -m pytest tests/test_cli/test_wrap_claude_inbound_upstream.py -q: 8 passed. The precedence with explicit target/Foundry/Vertex is preserved, and self-pointing proxy URLs are ignored to avoid loops. No blocking issues found.
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.
Description
Issue #1353: when the user already has
ANTHROPIC_BASE_URLpointing at a LiteLLM (or any custom Anthropic-compatible) gateway,headroom wrap claudeoverwrote it with the local proxy URL and silently forwarded toapi.anthropic.com.wrap claudenow treats a pre-existing non-self-pointingANTHROPIC_BASE_URLas the proxy's upstream (passed asANTHROPIC_TARGET_API_URL) so compression layers on top of the user's gateway instead of replacing it. ExplicitANTHROPIC_TARGET_API_URL, Foundry and Vertex paths still win.Closes #1353
Type of Change
Changes Made
_detect_inbound_anthropic_upstream(proxy_port)toheadroom/cli/wrap.py: returns a pre-setANTHROPIC_BASE_URLas the proxy upstream, ignoring unset/blank values and self-pointing localhost URLs on the proxy port.wrap claudeso a user's custom gateway is preserved asANTHROPIC_TARGET_API_URLinstead of being overwritten.ANTHROPIC_TARGET_API_URL, Foundry, and Vertex still take priority.tests/test_cli/test_wrap_claude_inbound_upstream.py(8 cases) covering detection, blank/unset, self-pointing URLs, and a different-port upstream.Testing
pytest)ruff check .)mypy headroom)Test Output
Real Behavior Proof
pytest tests/test_cli/test_wrap_claude_inbound_upstream.py -von the patched branch, then with the production fix reverted.AttributeError: module 'headroom.cli.wrap' has no attribute '_detect_inbound_anthropic_upstream'(8 failed in 0.37s).8 passed in 0.25s).Review Readiness
Checklist
Additional Notes
Docs/CHANGELOG checklist items left unchecked as N/A: this is a behavioral bug fix to existing
wrap claudeupstream handling with no new public surface to document.Real Behavior Proof
fix/issue-1353),.venv, proxy port 8787.wrap claude(_detect_inbound_anthropic_upstream) across representativeANTHROPIC_BASE_URLvalues:ANTHROPIC_BASE_URLis returned as the proxy upstream (wired toANTHROPIC_TARGET_API_URL), so compression layers on top of the user's gateway. Unset / blank / self-pointing values fall through toNone, so the proxy default applies and no self-forwarding loop is created.wrap claudelaunch end-to-end against a live LiteLLM gateway (needs the external gateway + Claude Code); the wiring fromcustom_upstreamtoANTHROPIC_TARGET_API_URLis covered by the unit suite.