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

AsyncMessages Class — anthropic-sdk-python Architecture

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

Entity Profile

Dependency Diagram

graph TD
  bafd0838_b212_5f78_7082_11123724d722["AsyncMessages"]
  f98629a5_73f4_23f2_1f7f_c8db837848d1["AsyncAPIResource"]
  bafd0838_b212_5f78_7082_11123724d722 -->|extends| f98629a5_73f4_23f2_1f7f_c8db837848d1
  29105ffb_b1ec_ed79_9d81_a213fc4534d2["JSONOutputFormatParam"]
  bafd0838_b212_5f78_7082_11123724d722 -->|extends| 29105ffb_b1ec_ed79_9d81_a213fc4534d2
  01beb2f6_442c_779e_7c57_22078b50dcf4["Message"]
  bafd0838_b212_5f78_7082_11123724d722 -->|extends| 01beb2f6_442c_779e_7c57_22078b50dcf4
  05fc3602_684b_cc2f_c460_4a8d7984a874["messages.py"]
  bafd0838_b212_5f78_7082_11123724d722 -->|defined in| 05fc3602_684b_cc2f_c460_4a8d7984a874
  edab6357_eee9_f51d_73cc_1dad602fd971["batches()"]
  bafd0838_b212_5f78_7082_11123724d722 -->|method| edab6357_eee9_f51d_73cc_1dad602fd971
  293275ee_28a8_7c57_6a6b_e6391e207f87["with_raw_response()"]
  bafd0838_b212_5f78_7082_11123724d722 -->|method| 293275ee_28a8_7c57_6a6b_e6391e207f87
  e3d1b495_28fc_dece_f425_dde866022698["with_streaming_response()"]
  bafd0838_b212_5f78_7082_11123724d722 -->|method| e3d1b495_28fc_dece_f425_dde866022698
  e0f7bea1_12cd_3cb9_ee1b_0529b0f9b174["create()"]
  bafd0838_b212_5f78_7082_11123724d722 -->|method| e0f7bea1_12cd_3cb9_ee1b_0529b0f9b174
  43284ee0_8672_7150_889b_e464fb5a8cf1["stream()"]
  bafd0838_b212_5f78_7082_11123724d722 -->|method| 43284ee0_8672_7150_889b_e464fb5a8cf1
  224b3cfd_d77c_12ea_9523_cee2cda5dc60["parse()"]
  bafd0838_b212_5f78_7082_11123724d722 -->|method| 224b3cfd_d77c_12ea_9523_cee2cda5dc60
  ad2ba7ce_f9ac_913e_2c74_215533e7f0d3["count_tokens()"]
  bafd0838_b212_5f78_7082_11123724d722 -->|method| ad2ba7ce_f9ac_913e_2c74_215533e7f0d3

Relationship Graph

Source Code

src/anthropic/resources/messages/messages.py lines 1495–2909

class AsyncMessages(AsyncAPIResource):
    @cached_property
    def batches(self) -> AsyncBatches:
        return AsyncBatches(self._client)

    @cached_property
    def with_raw_response(self) -> AsyncMessagesWithRawResponse:
        """
        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 AsyncMessagesWithRawResponse(self)

    @cached_property
    def with_streaming_response(self) -> AsyncMessagesWithStreamingResponse:
        """
        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 AsyncMessagesWithStreamingResponse(self)

    @overload
    async def create(
        self,
        *,
        max_tokens: int,
        messages: Iterable[MessageParam],
        model: ModelParam,
        inference_geo: Optional[str] | Omit = omit,
        metadata: MetadataParam | Omit = omit,
        output_config: OutputConfigParam | Omit = omit,
        service_tier: Literal["auto", "standard_only"] | Omit = omit,
        stop_sequences: SequenceNotStr[str] | Omit = omit,
        stream: Literal[False] | Omit = omit,
        system: Union[str, Iterable[TextBlockParam]] | Omit = omit,
        temperature: float | Omit = omit,
        thinking: ThinkingConfigParam | Omit = omit,
        tool_choice: ToolChoiceParam | Omit = omit,
        tools: Iterable[ToolUnionParam] | Omit = omit,
        top_k: int | Omit = omit,
        top_p: float | 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,
    ) -> Message:
        """
        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
              the next `Message` in the conversation. Consecutive `user` or `assistant` turns
              in your request will be combined into a single turn.

              Each input message must be an object with a `role` and `content`. You can
              specify a single `user`-role message, or you can include multiple `user` and
              `assistant` messages.

Frequently Asked Questions

What is the AsyncMessages class?
AsyncMessages is a class in the anthropic-sdk-python codebase, defined in src/anthropic/resources/messages/messages.py.
Where is AsyncMessages defined?
AsyncMessages is defined in src/anthropic/resources/messages/messages.py at line 1495.
What does AsyncMessages extend?
AsyncMessages extends AsyncAPIResource, JSONOutputFormatParam, Message.

Analyze Your Own Codebase

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

Try Supermodel Free