Home / File/ test_beta_messages.py — anthropic-sdk-python Source File

test_beta_messages.py — anthropic-sdk-python Source File

Architecture documentation for test_beta_messages.py, a python file in the anthropic-sdk-python codebase. 9 imports, 0 dependents.

File python AnthropicClient AsyncAPI 9 imports 2 classes

Entity Profile

Dependency Diagram

graph LR
  61bcf220_f0ab_e6e0_1d11_6d45d9dbf60b["test_beta_messages.py"]
  077dc885_0b93_48bf_b408_eb69a4ebc905["snapshots"]
  61bcf220_f0ab_e6e0_1d11_6d45d9dbf60b --> 077dc885_0b93_48bf_b408_eb69a4ebc905
  28b0c811_20f6_fc4a_4b48_7fb9e87bf7e5["json"]
  61bcf220_f0ab_e6e0_1d11_6d45d9dbf60b --> 28b0c811_20f6_fc4a_4b48_7fb9e87bf7e5
  cde8421b_93c7_41e4_d69d_2a3f1bade2f2["pytest"]
  61bcf220_f0ab_e6e0_1d11_6d45d9dbf60b --> cde8421b_93c7_41e4_d69d_2a3f1bade2f2
  f6010db4_1656_22a8_b4ae_e0060d80d8c6["respx"]
  61bcf220_f0ab_e6e0_1d11_6d45d9dbf60b --> f6010db4_1656_22a8_b4ae_e0060d80d8c6
  21de8837_7dae_989e_fdbb_1415c0770d90["pydantic"]
  61bcf220_f0ab_e6e0_1d11_6d45d9dbf60b --> 21de8837_7dae_989e_fdbb_1415c0770d90
  8cc1f0ad_0f79_35fa_324c_9980bd002940["inline_snapshot"]
  61bcf220_f0ab_e6e0_1d11_6d45d9dbf60b --> 8cc1f0ad_0f79_35fa_324c_9980bd002940
  d10c5377_2939_0f0b_cc44_8759393f2853["anthropic"]
  61bcf220_f0ab_e6e0_1d11_6d45d9dbf60b --> d10c5377_2939_0f0b_cc44_8759393f2853
  f9fce826_b216_5ab1_fca0_52dbed3ce2ad["anthropic._legacy_response"]
  61bcf220_f0ab_e6e0_1d11_6d45d9dbf60b --> f9fce826_b216_5ab1_fca0_52dbed3ce2ad
  c6e963a0_47d8_f3d4_54b1_cd562f2c420d["anthropic.types.beta.parsed_beta_message"]
  61bcf220_f0ab_e6e0_1d11_6d45d9dbf60b --> c6e963a0_47d8_f3d4_54b1_cd562f2c420d
  style 61bcf220_f0ab_e6e0_1d11_6d45d9dbf60b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import json

import pytest
from respx import MockRouter
from pydantic import BaseModel
from inline_snapshot import external, snapshot

from anthropic import AnthropicError, AsyncAnthropic, _compat
from anthropic._legacy_response import LegacyAPIResponse
from anthropic.types.beta.parsed_beta_message import ParsedBetaMessage

from ..snapshots import make_async_stream_snapshot_request


@pytest.mark.skipif(_compat.PYDANTIC_V1, reason="tool runner not supported with pydantic v1")
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
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",
// ... (72 more lines)

Subdomains

Dependencies

  • anthropic
  • anthropic._legacy_response
  • anthropic.types.beta.parsed_beta_message
  • inline_snapshot
  • json
  • pydantic
  • pytest
  • respx
  • snapshots

Frequently Asked Questions

What does test_beta_messages.py do?
test_beta_messages.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, AsyncAPI subdomain.
What does test_beta_messages.py depend on?
test_beta_messages.py imports 9 module(s): anthropic, anthropic._legacy_response, anthropic.types.beta.parsed_beta_message, inline_snapshot, json, pydantic, pytest, respx, and 1 more.
Where is test_beta_messages.py in the architecture?
test_beta_messages.py is located at tests/lib/_parse/test_beta_messages.py (domain: AnthropicClient, subdomain: AsyncAPI, directory: tests/lib/_parse).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free