feat(anthropic): add User-Agent header for Anthropic API calls (#35268)

This commit is contained in:
Mike Lambert
2026-02-17 15:59:54 -05:00
committed by GitHub
parent 8166e0137d
commit 0d13463e7f
2 changed files with 18 additions and 1 deletions

View File

@@ -53,6 +53,15 @@ def test_initialization() -> None:
assert model.anthropic_api_url == "https://api.anthropic.com"
def test_user_agent_header_in_client_params() -> None:
"""Test that _client_params includes a User-Agent header."""
llm = ChatAnthropic(model=MODEL_NAME, api_key="test-key") # type: ignore[arg-type]
params = llm._client_params
assert "default_headers" in params
assert "User-Agent" in params["default_headers"]
assert params["default_headers"]["User-Agent"].startswith("langchain-anthropic/")
@pytest.mark.parametrize("async_api", [True, False])
def test_streaming_attribute_should_stream(async_api: bool) -> None: # noqa: FBT001
llm = ChatAnthropic(model=MODEL_NAME, streaming=True)