Home / Class/ Messages Class — anthropic-sdk-python Architecture

Messages Class — anthropic-sdk-python Architecture

Architecture documentation for the Messages class in messages.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  8c902234_0aa5_f23d_186e_7c523acb8fed["Messages"]
  32bd9d9e_8b62_b229_7718_45771b424c40["SyncAPIResource"]
  8c902234_0aa5_f23d_186e_7c523acb8fed -->|extends| 32bd9d9e_8b62_b229_7718_45771b424c40
  0da6889b_9352_8c02_9f21_a1deb1bdab0f["BetaMessage"]
  8c902234_0aa5_f23d_186e_7c523acb8fed -->|extends| 0da6889b_9352_8c02_9f21_a1deb1bdab0f
  18faea44_da45_8ccd_f3b1_057ca68b7fd4["BetaJSONOutputFormatParam"]
  8c902234_0aa5_f23d_186e_7c523acb8fed -->|extends| 18faea44_da45_8ccd_f3b1_057ca68b7fd4
  16f9761f_052b_9813_1b8d_d40d64684eff["messages.py"]
  8c902234_0aa5_f23d_186e_7c523acb8fed -->|defined in| 16f9761f_052b_9813_1b8d_d40d64684eff
  16d624dd_ef13_2c5c_1649_6cfea81712eb["batches()"]
  8c902234_0aa5_f23d_186e_7c523acb8fed -->|method| 16d624dd_ef13_2c5c_1649_6cfea81712eb
  fbfc0407_406e_2a75_717c_fd079a5f54a0["with_raw_response()"]
  8c902234_0aa5_f23d_186e_7c523acb8fed -->|method| fbfc0407_406e_2a75_717c_fd079a5f54a0
  9fbc1b48_281e_434d_cde7_07bcbe0b02b6["with_streaming_response()"]
  8c902234_0aa5_f23d_186e_7c523acb8fed -->|method| 9fbc1b48_281e_434d_cde7_07bcbe0b02b6
  34d38135_c378_e9a4_ba05_661bc9121152["create()"]
  8c902234_0aa5_f23d_186e_7c523acb8fed -->|method| 34d38135_c378_e9a4_ba05_661bc9121152
  1f77730a_8062_4443_ad97_1696c0294a47["parse()"]
  8c902234_0aa5_f23d_186e_7c523acb8fed -->|method| 1f77730a_8062_4443_ad97_1696c0294a47
  22f51a8f_1741_b57a_a8ad_306e7f9091ae["tool_runner()"]
  8c902234_0aa5_f23d_186e_7c523acb8fed -->|method| 22f51a8f_1741_b57a_a8ad_306e7f9091ae
  11f0e821_29f9_1b06_ca3c_9f9f9b07b9c7["stream()"]
  8c902234_0aa5_f23d_186e_7c523acb8fed -->|method| 11f0e821_29f9_1b06_ca3c_9f9f9b07b9c7
  c307d27a_5711_a0a0_93ca_406e62eb1e1d["count_tokens()"]
  8c902234_0aa5_f23d_186e_7c523acb8fed -->|method| c307d27a_5711_a0a0_93ca_406e62eb1e1d

Relationship Graph

Source Code

src/anthropic/resources/beta/messages/messages.py lines 82–1861

class Messages(SyncAPIResource):
    @cached_property
    def batches(self) -> Batches:
        return Batches(self._client)

    @cached_property
    def with_raw_response(self) -> MessagesWithRawResponse:
        """
        This property can be used as a prefix for any HTTP method call to return
        the raw response object instead of the parsed content.

        For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
        """
        return MessagesWithRawResponse(self)

    @cached_property
    def with_streaming_response(self) -> MessagesWithStreamingResponse:
        """
        An alternative to `.with_raw_response` that doesn't eagerly read the response body.

        For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
        """
        return MessagesWithStreamingResponse(self)

    @overload
    def create(
        self,
        *,
        max_tokens: int,
        messages: Iterable[BetaMessageParam],
        model: ModelParam,
        container: Optional[message_create_params.Container] | Omit = omit,
        context_management: Optional[BetaContextManagementConfigParam] | Omit = omit,
        inference_geo: Optional[str] | Omit = omit,
        mcp_servers: Iterable[BetaRequestMCPServerURLDefinitionParam] | Omit = omit,
        metadata: BetaMetadataParam | Omit = omit,
        output_config: BetaOutputConfigParam | Omit = omit,
        output_format: Optional[BetaJSONOutputFormatParam] | Omit = omit,
        service_tier: Literal["auto", "standard_only"] | Omit = omit,
        speed: Optional[Literal["standard", "fast"]] | Omit = omit,
        stop_sequences: SequenceNotStr[str] | Omit = omit,
        stream: Literal[False] | Omit = omit,
        system: Union[str, Iterable[BetaTextBlockParam]] | Omit = omit,
        temperature: float | Omit = omit,
        thinking: BetaThinkingConfigParam | Omit = omit,
        tool_choice: BetaToolChoiceParam | Omit = omit,
        tools: Iterable[BetaToolUnionParam] | Omit = omit,
        top_k: int | Omit = omit,
        top_p: float | Omit = omit,
        betas: List[AnthropicBetaParam] | Omit = omit,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> BetaMessage:
        """
        Send a structured list of input messages with text and/or image content, and the
        model will generate the next message in the conversation.

        The Messages API can be used for either single queries or stateless multi-turn
        conversations.

        Learn more about the Messages API in our
        [user guide](https://docs.claude.com/en/docs/initial-setup)

        Args:
          max_tokens: The maximum number of tokens to generate before stopping.

              Note that our models may stop _before_ reaching this maximum. This parameter
              only specifies the absolute maximum number of tokens to generate.

              Different models have different maximum values for this parameter. See
              [models](https://docs.claude.com/en/docs/models-overview) for details.

          messages: Input messages.

              Our models are trained to operate on alternating `user` and `assistant`
              conversational turns. When creating a new `Message`, you specify the prior
              conversational turns with the `messages` parameter, and the model then generates

Frequently Asked Questions

What is the Messages class?
Messages is a class in the anthropic-sdk-python codebase, defined in src/anthropic/resources/beta/messages/messages.py.
Where is Messages defined?
Messages is defined in src/anthropic/resources/beta/messages/messages.py at line 82.
What does Messages extend?
Messages extends SyncAPIResource, BetaMessage, BetaJSONOutputFormatParam.

Analyze Your Own Codebase

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

Try Supermodel Free