Skip to content

Commit bb7e567

Browse files
committed
Read the Anthropic key and API version the 2.x SDK sends in the LangGraph AG-UI test
anthropic 2.x sends the key as Authorization: Bearer instead of x-api-key and dates its Messages API version later than 2023-06-01. The provider-boundary test asserted both by their 1.x values, so it failed once the unpinned requirements resolved 2.x. It now reads the key from either header and checks the version is a date; the endpoint, key, model and body it asserts are unchanged. (cherry picked from commit 99685ee)
1 parent 918e96c commit bb7e567

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎agent-langgraph-agui/tests/test_provider_boundaries.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
import re
34
import shutil
45
import subprocess
56
import sys
@@ -337,8 +338,13 @@ async def test_anthropic_selection_reaches_anthropic_boundary_without_openai_key
337338
assert result["messages"][0].content == "anthropic proof"
338339
assert "OPENAI_API_KEY" not in os.environ
339340
assert captured[0]["url"] == "http://127.0.0.1:4311/v1/messages"
340-
assert captured[0]["headers"]["x-api-key"] == "sk-ant-openbot-ci"
341-
assert captured[0]["headers"]["anthropic-version"] == "2023-06-01"
341+
# Anthropic's SDK sends the key as `x-api-key` up to 1.x and as `Authorization: Bearer` from
342+
# 2.x; either is the key reaching Anthropic, which is what this test is about.
343+
bearer = captured[0]["headers"].get("authorization") or ""
344+
key = captured[0]["headers"].get("x-api-key") or bearer.removeprefix("Bearer ") or None
345+
assert key == "sk-ant-openbot-ci"
346+
# The Messages API version is dated, and the SDK picks it: 1.x sends 2023-06-01, 2.x a later date.
347+
assert re.fullmatch(r"\d{4}-\d{2}-\d{2}", captured[0]["headers"]["anthropic-version"])
342348
assert captured[0]["body"]["model"] == request_model
343349
assert captured[0]["body"]["messages"] == [
344350
{"role": "user", "content": "Say hello."}

0 commit comments

Comments
 (0)