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 31b9de52_3b0b_f20e_01d3_803490d7de7e["Messages"] 32bd9d9e_8b62_b229_7718_45771b424c40["SyncAPIResource"] 31b9de52_3b0b_f20e_01d3_803490d7de7e -->|extends| 32bd9d9e_8b62_b229_7718_45771b424c40 29105ffb_b1ec_ed79_9d81_a213fc4534d2["JSONOutputFormatParam"] 31b9de52_3b0b_f20e_01d3_803490d7de7e -->|extends| 29105ffb_b1ec_ed79_9d81_a213fc4534d2 01beb2f6_442c_779e_7c57_22078b50dcf4["Message"] 31b9de52_3b0b_f20e_01d3_803490d7de7e -->|extends| 01beb2f6_442c_779e_7c57_22078b50dcf4 05fc3602_684b_cc2f_c460_4a8d7984a874["messages.py"] 31b9de52_3b0b_f20e_01d3_803490d7de7e -->|defined in| 05fc3602_684b_cc2f_c460_4a8d7984a874 0cf4c5da_7c6c_2679_1b9c_c5c856bd16d7["batches()"] 31b9de52_3b0b_f20e_01d3_803490d7de7e -->|method| 0cf4c5da_7c6c_2679_1b9c_c5c856bd16d7 eb8b46c3_fdc1_b7e3_1d1c_034699d6cbdb["with_raw_response()"] 31b9de52_3b0b_f20e_01d3_803490d7de7e -->|method| eb8b46c3_fdc1_b7e3_1d1c_034699d6cbdb 6e6e5d79_6957_e762_85a6_b32c39d4c1fa["with_streaming_response()"] 31b9de52_3b0b_f20e_01d3_803490d7de7e -->|method| 6e6e5d79_6957_e762_85a6_b32c39d4c1fa ea2fe77e_073d_25a0_5ca4_f2772ef51e21["create()"] 31b9de52_3b0b_f20e_01d3_803490d7de7e -->|method| ea2fe77e_073d_25a0_5ca4_f2772ef51e21 f79b127d_5a1b_a7b8_4eda_ad6f6166bae9["stream()"] 31b9de52_3b0b_f20e_01d3_803490d7de7e -->|method| f79b127d_5a1b_a7b8_4eda_ad6f6166bae9 e39b95d3_6106_fca7_db85_ce3b819a4002["parse()"] 31b9de52_3b0b_f20e_01d3_803490d7de7e -->|method| e39b95d3_6106_fca7_db85_ce3b819a4002 e7ad2d22_c063_ff41_ff5b_c612e290358f["count_tokens()"] 31b9de52_3b0b_f20e_01d3_803490d7de7e -->|method| e7ad2d22_c063_ff41_ff5b_c612e290358f
Relationship Graph
Source Code
src/anthropic/resources/messages/messages.py lines 77–1492
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[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.
Domain
Defined In
Source
Frequently Asked Questions
What is the Messages class?
Messages is a class in the anthropic-sdk-python codebase, defined in src/anthropic/resources/messages/messages.py.
Where is Messages defined?
Messages is defined in src/anthropic/resources/messages/messages.py at line 77.
What does Messages extend?
Messages extends SyncAPIResource, JSONOutputFormatParam, Message.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free