Skip to content

Commit 3e614dd

Browse files
committed
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. (cherry picked from commit a1391e7)
1 parent f220198 commit 3e614dd

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎agent-ag2/tests/test_main.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ def test_an_anthropic_key_uses_the_official_endpoint_when_compose_sets_a_blank_u
190190

191191
async def respond(transport, request):
192192
body = json.loads(request.content)
193-
seen.append((str(request.url), request.headers.get("x-api-key"), body["model"]))
193+
# Anthropic's SDK sends the key as `x-api-key` up to 1.x and as `Authorization: Bearer` from
194+
# 2.x; either is the key reaching Anthropic, which is what this test is about.
195+
bearer = request.headers.get("authorization") or ""
196+
key = request.headers.get("x-api-key") or bearer.removeprefix("Bearer ") or None
197+
seen.append((str(request.url), key, body["model"]))
194198
return httpx2.Response(
195199
200,
196200
request=request,

0 commit comments

Comments
 (0)