| 423 | @pytest.mark.respx() |
| 424 | @pytest.mark.asyncio() |
| 425 | async 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 | |
| 441 | def test_api_key_from_env(monkeypatch: t.Any) -> None: |