fix(aux): named custom anthropic_messages entries send their extra_headers too

`_resolve_named_custom_branch` lifted a `providers:` entry's `extra_headers`
onto both OpenAI-wire clients but built the anthropic_messages client without
them, so a gateway that needs a header on an Anthropic-style relay still
dropped it on aux calls. `with_options(default_headers=...)` merges the entry
headers onto the beta / credential-Omit headers the builder installs, so the
one-credential invariant is unchanged.

Review follow-up on #113969; the existing anthropic_messages named-custom test
now asserts the header (red on the previous head).
This commit is contained in:
teknium1 authored and Teknium committed 2026-09-17 08:53:15 -07:00
1 parent b1db026f3a
commit d41aec0beb
2 files changed
+10 -1

No files matched your search

+4
View File
@@ -4967,6 +4967,10 @@ def _resolve_named_custom_branch(req: _ResolveRequest) -> Optional[_ResolveResul
try:
from agent.anthropic_adapter import build_anthropic_client
real_client = build_anthropic_client(custom_key, custom_base)
if entry_headers:
# Same entry headers as the two OpenAI-wire arms; ``with_options`` merges onto the
# beta/credential-Omit headers the builder installed (#109595).
real_client = real_client.with_options(default_headers=entry_headers)
except ImportError:
logger.warning("Named custom provider %r declares api_mode=anthropic_messages but the anthropic SDK "
"is not installed — falling back to OpenAI-wire.", provider)
@@ -312,7 +312,8 @@ class TestProvidersDictApiModeAnthropicMessages:
def test_resolve_provider_client_returns_anthropic_client(self, tmp_path, monkeypatch):
"""Named custom provider with api_mode=anthropic_messages must
route through AnthropicAuxiliaryClient."""
route through AnthropicAuxiliaryClient, carrying the entry's extra_headers
like the OpenAI-wire arms do (#109595)."""
monkeypatch.setenv("MYRELAY_API_KEY", "sk-test")
_write_config(tmp_path, {
"providers": {
@@ -322,6 +323,7 @@ class TestProvidersDictApiModeAnthropicMessages:
"key_env": "MYRELAY_API_KEY",
"api_mode": "anthropic_messages",
"default_model": "claude-opus-4-7",
"extra_headers": {"X-Gateway-Token": "gw-1"},
},
},
})
@@ -335,6 +337,9 @@ class TestProvidersDictApiModeAnthropicMessages:
f"expected AnthropicAuxiliaryClient, got {type(sync_client).__name__}"
)
assert sync_model == "claude-opus-4-7"
sdk_headers = sync_client._real_client._custom_headers
assert sdk_headers.get("X-Gateway-Token") == "gw-1"
assert "anthropic-beta" in sdk_headers, "entry headers must merge onto, not replace, the builder's headers"
async_client, async_model = resolve_provider_client("myrelay", async_mode=True)
assert isinstance(async_client, AsyncAnthropicAuxiliaryClient), (