fix: distinguish callable Anthropic bearer sources from OAuth text

This commit is contained in:
Teknium
2026-09-07 02:40:07 -07:00
parent c573e62074
commit 4270e9ad10
2 changed files with 18 additions and 1 deletions
+4 -1
View File
@@ -78,7 +78,10 @@ def _swap_fallback_clients(agent, fb_client, fb_provider: str, fb_model: str, fb
agent.api_key = agent._anthropic_api_key = effective_key
agent._anthropic_base_url = fb_base_url
agent._anthropic_client = build_anthropic_client(effective_key, fb_base_url, timeout=timeout)
agent._is_anthropic_oauth = _is_oauth_token(effective_key) if is_anthropic else False
agent._is_anthropic_oauth = (
_is_oauth_token(effective_key)
if is_anthropic and isinstance(effective_key, str) else False
)
agent.client, agent._client_kwargs = None, {}
return
agent.api_key = credential
@@ -33,3 +33,17 @@ def test_fallback_rebuild_preserves_rotating_and_static_credentials(mode, dynami
finally:
client.close()
rebuilt.close()
def test_anthropic_fallback_keeps_callable_without_treating_it_as_oauth_text():
source = lambda: "fixture-token" # noqa: E731
client = OpenAI(api_key=source, base_url="http://localhost:1234/v1")
agent = SimpleNamespace()
try:
_swap_fallback_clients(agent, client, "anthropic", "fixture", str(client.base_url), "anthropic_messages")
assert agent.api_key is source
assert agent._anthropic_api_key is source
assert agent._is_anthropic_oauth is False
agent._anthropic_client.close()
finally:
client.close()