TestAsyncMessages Class — anthropic-sdk-python Architecture
Architecture documentation for the TestAsyncMessages class in test_beta_messages.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD 692db1db_e9a7_ed62_b129_14081098a7ae["TestAsyncMessages"] 17ce5647_6f06_0676_a4a5_e378a3f57cb1["BaseModel"] 692db1db_e9a7_ed62_b129_14081098a7ae -->|extends| 17ce5647_6f06_0676_a4a5_e378a3f57cb1 145ee5ba_422d_688e_ca30_dbf4a26bf47f["AnthropicError"] 692db1db_e9a7_ed62_b129_14081098a7ae -->|extends| 145ee5ba_422d_688e_ca30_dbf4a26bf47f 61bcf220_f0ab_e6e0_1d11_6d45d9dbf60b["test_beta_messages.py"] 692db1db_e9a7_ed62_b129_14081098a7ae -->|defined in| 61bcf220_f0ab_e6e0_1d11_6d45d9dbf60b dd54031b_584a_4852_c5cc_c514cb424766["test_stream_with_raw_schema()"] 692db1db_e9a7_ed62_b129_14081098a7ae -->|method| dd54031b_584a_4852_c5cc_c514cb424766 55e28727_496a_adff_d21a_2d67318f4082["test_parse_uses_output_config()"] 692db1db_e9a7_ed62_b129_14081098a7ae -->|method| 55e28727_496a_adff_d21a_2d67318f4082 74e22072_e66b_fa27_b5a9_eeef81fb4f31["test_rejects_both_output_format_and_config()"] 692db1db_e9a7_ed62_b129_14081098a7ae -->|method| 74e22072_e66b_fa27_b5a9_eeef81fb4f31
Relationship Graph
Source Code
tests/lib/_parse/test_beta_messages.py lines 17–131
class TestAsyncMessages:
async def test_stream_with_raw_schema(self, async_client: AsyncAnthropic, respx_mock: MockRouter) -> None:
async def async_stream_parse(client: AsyncAnthropic) -> ParsedBetaMessage[None]:
async with client.beta.messages.stream(
model="claude-sonnet-4-5",
messages=[
{
"role": "user",
"content": "Extract order IDs from the following text:\n\nOrder 12345\nOrder 67890",
}
],
output_format={
"type": "json_schema",
"schema": {
"type": "array",
"items": {"type": "integer"},
},
},
betas=["structured-outputs-2025-12-15"],
max_tokens=1024,
) as stream:
return await stream.get_final_message()
response = await make_async_stream_snapshot_request(
async_stream_parse,
content_snapshot=external("uuid:48aac7c3-f271-47b3-854b-af4ed31e10bb.json"),
respx_mock=respx_mock,
mock_client=async_client,
path="/v1/messages?beta=true",
)
assert response.content[0].text == snapshot("[12345,67890]")
async def test_parse_uses_output_config(self, async_client: AsyncAnthropic, respx_mock: MockRouter) -> None:
class User(BaseModel):
name: str
age: int
async def simple_parse(client: AsyncAnthropic) -> LegacyAPIResponse[ParsedBetaMessage[User]]:
return await client.beta.with_raw_response.messages.parse(
model="claude-sonnet-4-5",
messages=[
{
"role": "user",
"content": "Extract the user's name and age from the following text:\n\nMy name is John Doe and I am 30 years old.",
}
],
output_format=User,
max_tokens=1024,
)
response = await make_async_stream_snapshot_request(
simple_parse,
content_snapshot=external("uuid:044ce19d-3e9c-42d2-90e7-759c978cd94b.json"),
respx_mock=respx_mock,
mock_client=async_client,
path="/v1/messages?beta=true",
)
request_json = json.loads(response.http_request.content)
assert request_json == snapshot(
{
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": """\
Extract the user's name and age from the following text:
My name is John Doe and I am 30 years old.\
""",
}
],
"model": "claude-sonnet-4-5",
"output_config": {
"format": {
"schema": {
"type": "object",
"title": "User",
"properties": {
"name": {"type": "string", "title": "Name"},
Domain
Defined In
Extends
Source
Frequently Asked Questions
What is the TestAsyncMessages class?
TestAsyncMessages is a class in the anthropic-sdk-python codebase, defined in tests/lib/_parse/test_beta_messages.py.
Where is TestAsyncMessages defined?
TestAsyncMessages is defined in tests/lib/_parse/test_beta_messages.py at line 17.
What does TestAsyncMessages extend?
TestAsyncMessages extends BaseModel, AnthropicError.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free