| 405 | |
| 406 | @pytest.mark.respx() |
| 407 | def test_api_key_auth(respx_mock: MockRouter) -> None: |
| 408 | respx_mock.post(re.compile(r"https://bedrock-runtime\.us-east-1\.amazonaws\.com/model/.*/invoke")).mock( |
| 409 | return_value=httpx2.Response(200, json={"foo": "bar"}), |
| 410 | ) |
| 411 | |
| 412 | sync_api_key_client.messages.create( |
| 413 | max_tokens=1024, |
| 414 | messages=[{"role": "user", "content": "Say hello there!"}], |
| 415 | model="anthropic.claude-3-5-sonnet-20241022-v2:0", |
| 416 | ) |
| 417 | |
| 418 | calls = cast("list[MockRequestCall]", respx_mock.calls) |
| 419 | assert len(calls) == 1 |
| 420 | assert calls[0].request.headers["Authorization"] == "Bearer test-api-key" |
| 421 | |
| 422 | |
| 423 | @pytest.mark.respx() |