From a1391e7526807b51dde669b4a295f0d56e0ab2d9 Mon Sep 17 00:00:00 2001 From: David McKay Date: Tue, 27 Oct 2026 14:53:29 -0700 Subject: [PATCH] Read the Anthropic key from either header in the AG2 test Anthropic's SDK 2.3.0, which CI now installs for the AG2 harness, sends the key as Authorization: Bearer instead of x-api-key. The agent's key still reaches Anthropic; the test only looked for the old header, so it failed on every pull request. It now accepts either, and passes with Anthropic's SDK 1.17.0 and 2.3.0 alike. --- agent-ag2/tests/test_main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/agent-ag2/tests/test_main.py b/agent-ag2/tests/test_main.py index 93cf26a8c3..e3824d90d0 100644 --- a/agent-ag2/tests/test_main.py +++ b/agent-ag2/tests/test_main.py @@ -190,7 +190,11 @@ def test_an_anthropic_key_uses_the_official_endpoint_when_compose_sets_a_blank_u async def respond(transport, request): body = json.loads(request.content) - seen.append((str(request.url), request.headers.get("x-api-key"), body["model"])) + # Anthropic's SDK sends the key as `x-api-key` up to 1.x and as `Authorization: Bearer` from + # 2.x; either is the key reaching Anthropic, which is what this test is about. + bearer = request.headers.get("authorization") or "" + key = request.headers.get("x-api-key") or bearer.removeprefix("Bearer ") or None + seen.append((str(request.url), key, body["model"])) return httpx2.Response( 200, request=request,