From d41aec0beb36ab783eeb0ea1cf7fc2ee089bcbae Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Thu, 17 Sep 2026 01:41:41 -0700 Subject: [PATCH] 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). --- agent/auxiliary_client.py | 4 ++++ tests/agent/test_auxiliary_named_custom_providers.py | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py index 6ad1b4442f..979904bbaf 100644 --- a/agent/auxiliary_client.py +++ b/agent/auxiliary_client.py @@ -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) diff --git a/tests/agent/test_auxiliary_named_custom_providers.py b/tests/agent/test_auxiliary_named_custom_providers.py index 6d5ef93d73..7c8022e23b 100644 --- a/tests/agent/test_auxiliary_named_custom_providers.py +++ b/tests/agent/test_auxiliary_named_custom_providers.py @@ -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), (