Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

refactor(proxy): deprecate is_anthropic_auth (#4083)

Tejas Chopra098df1c74e35
diff --git a/headroom/proxy/helpers.py b/headroom/proxy/helpers.py
index 9f9683c99..ac4ae591b 100644
--- a/headroom/proxy/helpers.py
+++ b/headroom/proxy/helpers.py
@@ -18,6 +18,7 @@ import random
import re
import threading
import time
+import warnings
from collections import OrderedDict
from collections.abc import Callable, Iterator
from dataclasses import dataclass
@@ -1938,7 +1939,19 @@ def _setup_file_logging(
def is_anthropic_auth(headers: dict[str, str]) -> bool:
- """Detect Anthropic auth signals in request headers."""
+ """Detect Anthropic auth signals in request headers.
+
+ .. deprecated::
+ Request routing does not use this. It uses the classifier in
+ ``headroom.providers.registry``, which also recognises Claude Code's
+ user-agent.
+ """
+ warnings.warn(
+ "is_anthropic_auth is deprecated and will be removed in a future release; "
+ "request routing uses the auth classifier in headroom.providers.registry.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
if headers.get("x-api-key") or headers.get("anthropic-version"):
return True
auth = headers.get("authorization", "")
diff --git a/tests/test_oauth_bearer_routing.py b/tests/test_oauth_bearer_routing.py
index 99e0b9f9d..9870877df 100644
--- a/tests/test_oauth_bearer_routing.py
+++ b/tests/test_oauth_bearer_routing.py
@@ -3,11 +3,11 @@
import httpx
from fastapi.testclient import TestClient
-from headroom.proxy.helpers import is_anthropic_auth
+from headroom.providers.registry import _is_anthropic_auth as is_anthropic_auth
from headroom.proxy.server import ProxyConfig, create_app
# ---------------------------------------------------------------------------
-# Unit tests: is_anthropic_auth
+# Unit tests: the auth classifier the router uses (providers.registry)
# ---------------------------------------------------------------------------
@@ -50,6 +50,18 @@ class TestIsAnthropicAuth:
def test_empty_authorization(self):
assert is_anthropic_auth({"authorization": ""}) is False
+ def test_claude_code_user_agent_with_gateway_bearer(self):
+ """Claude Code behind a gateway token is still routed to Anthropic."""
+ assert (
+ is_anthropic_auth(
+ {
+ "authorization": "Bearer 1a18a113-ab50-43c8",
+ "user-agent": "claude-cli/2.1.0 (external, cli)",
+ }
+ )
+ is True
+ )
+
# ---------------------------------------------------------------------------
# Integration tests: /v1/models routing
diff --git a/tests/test_pr208_changes.py b/tests/test_pr208_changes.py
index ab99310cb..f45fad6af 100644
--- a/tests/test_pr208_changes.py
+++ b/tests/test_pr208_changes.py
@@ -290,43 +290,16 @@ class TestLatencyHistogram:
# ---------------------------------------------------------------------------
-# is_anthropic_auth tests
+# is_anthropic_auth (deprecated)
# ---------------------------------------------------------------------------
-class TestIsAnthropicAuth:
- """Tests for headroom.proxy.helpers.is_anthropic_auth."""
-
- def test_detects_x_api_key(self) -> None:
- from headroom.proxy.helpers import is_anthropic_auth
+def test_is_anthropic_auth_is_deprecated() -> None:
+ from headroom.proxy.helpers import is_anthropic_auth
+ with pytest.warns(DeprecationWarning, match="is_anthropic_auth is deprecated"):
assert is_anthropic_auth({"x-api-key": "sk-ant-abc123"}) is True
- def test_detects_anthropic_version_header(self) -> None:
- from headroom.proxy.helpers import is_anthropic_auth
-
- assert is_anthropic_auth({"anthropic-version": "2023-06-01"}) is True
-
- def test_detects_bearer_sk_ant_prefix(self) -> None:
- from headroom.proxy.helpers import is_anthropic_auth
-
- assert is_anthropic_auth({"authorization": "Bearer sk-ant-abc123"}) is True
-
- def test_rejects_openai_bearer_token(self) -> None:
- from headroom.proxy.helpers import is_anthropic_auth
-
- assert is_anthropic_auth({"authorization": "Bearer sk-openai-xyz"}) is False
-
- def test_rejects_empty_headers(self) -> None:
- from headroom.proxy.helpers import is_anthropic_auth
-
- assert is_anthropic_auth({}) is False
-
- def test_rejects_non_anthropic_auth(self) -> None:
- from headroom.proxy.helpers import is_anthropic_auth
-
- assert is_anthropic_auth({"authorization": "Bearer some-token"}) is False
-
# ---------------------------------------------------------------------------
# _setup_file_logging tests