MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / test_api_key_auth_async

Function test_api_key_auth_async

tests/lib/test_bedrock.py:425–438  ·  view source on GitHub ↗
(respx_mock: MockRouter)

Source from the content-addressed store, hash-verified

423@pytest.mark.respx()
424@pytest.mark.asyncio()
425async def test_api_key_auth_async(respx_mock: MockRouter) -> None:
426 respx_mock.post(re.compile(r"https://bedrock-runtime\.us-east-1\.amazonaws\.com/model/.*/invoke")).mock(
427 return_value=httpx2.Response(200, json={"foo": "bar"}),
428 )
429
430 await async_api_key_client.messages.create(
431 max_tokens=1024,
432 messages=[{"role": "user", "content": "Say hello there!"}],
433 model="anthropic.claude-3-5-sonnet-20241022-v2:0",
434 )
435
436 calls = cast("list[MockRequestCall]", respx_mock.calls)
437 assert len(calls) == 1
438 assert calls[0].request.headers["Authorization"] == "Bearer test-api-key"
439
440
441def test_api_key_from_env(monkeypatch: t.Any) -> None:

Callers

nothing calls this directly

Calls 2

postMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected