L iPddlmZddlZddlZddlmZmZmZmZm Z m Z m Z ddl m Z ddlmZddlmZmZddlZddlZddlmZd d lmZmZmZmZmZmZdd lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'dd l(m)Z)m*Z*m+Z+m,Z,m-Z-dd l.m/Z/ddl0m1Z1ddl2m3Z3m4Z4ddl5m6Z6m7Z7ddl8m9Z9m:Z:m;Z;mZ>m?Z?ddl@mAZAmBZBddlCmDZDmEZEmFZFddlGmHZHddlImJZJmKZKddlLmMZMddlNmOZOddlPmQZQmRZRddlSmTZTddlUmVZVddlWmXZXmYZYddlZm[Z[ddl\m]Z]dd l^m_Z_dd!l`maZadd"lbmcZcdd#ldmeZedd$lfmgZgdd%lhmiZidd&ljmDZDdd'lkmlZldd(lmmnZndd)lompZpdd*lqmrZrerdd+lsmtZtmuZud,d-gZvGd.d,e3ZwGd/d-e4ZxGd0d1ZyGd2d3ZzGd4d5Z{Gd6d7Z|d9d8Z}y):) annotationsN) TYPE_CHECKINGListTypeUnionIterableOptionalcast)partial)chain)Literaloverload)_legacy_response)Batches AsyncBatchesBatchesWithRawResponseAsyncBatchesWithRawResponseBatchesWithStreamingResponse!AsyncBatchesWithStreamingResponse) NOT_GIVENBodyOmitQueryHeadersNotGivenSequenceNotStromit not_given)is_given required_argsmaybe_transformstrip_not_givenasync_maybe_transform)cached_property) TypeAdapter)SyncAPIResourceAsyncAPIResource)to_streamed_response_wrapper"async_to_streamed_response_wrapper)BetaToolRunnerBetaAsyncToolRunnerBetaStreamingToolRunnerBetaAsyncStreamingToolRunner)DEFAULT_TIMEOUTMODEL_NONSTREAMING_TOKENS)Stream AsyncStream)BetaThinkingConfigParammessage_create_paramsmessage_count_tokens_params)make_request_options)BetaMessageStreamManagerBetaAsyncMessageStreamManager)DEPRECATED_MODELS) ModelParam)ResponseFormatTparse_response)transform_schema) BetaMessage)BetaRunnableToolBetaAsyncRunnableTool)AnthropicBetaParam)BetaMessageParam)BetaMetadataParam)ParsedBetaMessage)BetaTextBlockParam)BetaToolUnionParam)BetaToolChoiceParam)BetaMessageTokensCount)r4)BetaJSONOutputFormatParam)BetaRawMessageStreamEvent) BetaContextManagementConfigParam)&BetaRequestMCPServerURLDefinitionParam) AnthropicAsyncAnthropicMessages AsyncMessagesceZdZeddZeddZeddZeeeeeeeeeeeeeeeeeddde d ddZ eeeeeeeeeeeeeeeeddde d ddZ eeeeeeeeeeeeeeeeddde d dd Z e gd gd eeeeeeeeeeeeeeeeddde d dd Z eeeeeeeeeeeeeeeeddde d dd Z eeeeeeeeeeeeeeeeeddde d d dZeeeeeeeeeeeeeeeeddde d d!dZeeeeeeeeeeeeeeeeddde d d"dZeeeeeeeeeeeeeeeeddde d d#dZeeeeeeeeeeeeeeeddde d d$dZeeeeeeeeddde d d%dZy)&rQc,t|jSN)r_clientselfs p/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/anthropic/resources/beta/messages/messages.pybatcheszMessages.batchesHst||$$ct|Sa 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 )MessagesWithRawResponserWs rYwith_raw_responsezMessages.with_raw_responseLs't,,r[ct|Sz 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 )MessagesWithStreamingResponserWs rYwith_streaming_responsez Messages.with_streaming_responseVs-T22r[N containercontext_management mcp_serversmetadata output_format service_tierstop_sequencesstreamsystem temperaturethinking tool_choicetoolstop_ktop_pbetas extra_headers extra_query extra_bodytimeoutcyu, 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. If the final message uses the `assistant` role, the response content will continue immediately from the content in that message. This can be used to constrain part of the model's response. Example with a single `user` message: ```json [{ "role": "user", "content": "Hello, Claude" }] ``` Example with multiple conversational turns: ```json [ { "role": "user", "content": "Hello there." }, { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" }, { "role": "user", "content": "Can you explain LLMs in plain English?" } ] ``` Example with a partially-filled response from Claude: ```json [ { "role": "user", "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun" }, { "role": "assistant", "content": "The best answer is (" } ] ``` Each input message `content` may be either a single `string` or an array of content blocks, where each block has a specific `type`. Using a `string` for `content` is shorthand for an array of one content block of type `"text"`. The following input messages are equivalent: ```json { "role": "user", "content": "Hello, Claude" } ``` ```json { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] } ``` See [input examples](https://docs.claude.com/en/api/messages-examples). Note that if you want to include a [system prompt](https://docs.claude.com/en/docs/system-prompts), you can use the top-level `system` parameter — there is no `"system"` role for input messages in the Messages API. There is a limit of 100,000 messages in a single request. model: The model that will complete your prompt. See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options. container: Container identifier for reuse across requests. context_management: Context management configuration. This allows you to control how Claude manages context across multiple requests, such as whether to clear function results or not. mcp_servers: MCP servers to be utilized in this request metadata: An object describing metadata about the request. output_format: A schema to specify Claude's output format in responses. service_tier: Determines whether to use priority capacity (if available) or standard capacity for this request. Anthropic offers different levels of service for your API requests. See [service-tiers](https://docs.claude.com/en/api/service-tiers) for details. stop_sequences: Custom text sequences that will cause the model to stop generating. Our models will normally stop when they have naturally completed their turn, which will result in a response `stop_reason` of `"end_turn"`. If you want the model to stop generating when it encounters custom strings of text, you can use the `stop_sequences` parameter. If the model encounters one of the custom sequences, the response `stop_reason` value will be `"stop_sequence"` and the response `stop_sequence` value will contain the matched stop sequence. stream: Whether to incrementally stream the response using server-sent events. See [streaming](https://docs.claude.com/en/api/messages-streaming) for details. system: System prompt. A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role. See our [guide to system prompts](https://docs.claude.com/en/docs/system-prompts). temperature: Amount of randomness injected into the response. Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0` for analytical / multiple choice, and closer to `1.0` for creative and generative tasks. Note that even with `temperature` of `0.0`, the results will not be fully deterministic. thinking: Configuration for enabling Claude's extended thinking. When enabled, responses include `thinking` content blocks showing Claude's thinking process before the final answer. Requires a minimum budget of 1,024 tokens and counts towards your `max_tokens` limit. See [extended thinking](https://docs.claude.com/en/docs/build-with-claude/extended-thinking) for details. tool_choice: How the model should use the provided tools. The model can use a specific tool, any available tool, decide by itself, or not use tools at all. tools: Definitions of tools that the model may use. If you include `tools` in your API request, the model may return `tool_use` content blocks that represent the model's use of those tools. You can then run those tools using the tool input generated by the model and then optionally return results back to the model using `tool_result` content blocks. There are two types of tools: **client tools** and **server tools**. The behavior described below applies to client tools. For [server tools](https://docs.claude.com/en/docs/agents-and-tools/tool-use/overview#server-tools), see their individual documentation as each has its own behavior (e.g., the [web search tool](https://docs.claude.com/en/docs/agents-and-tools/tool-use/web-search-tool)). Each tool definition includes: - `name`: Name of the tool. - `description`: Optional, but strongly-recommended description of the tool. - `input_schema`: [JSON schema](https://json-schema.org/draft/2020-12) for the tool `input` shape that the model will produce in `tool_use` output content blocks. For example, if you defined `tools` as: ```json [ { "name": "get_stock_price", "description": "Get the current stock price for a given ticker symbol.", "input_schema": { "type": "object", "properties": { "ticker": { "type": "string", "description": "The stock ticker symbol, e.g. AAPL for Apple Inc." } }, "required": ["ticker"] } } ] ``` And then asked the model "What's the S&P 500 at today?", the model might produce `tool_use` content blocks in the response like this: ```json [ { "type": "tool_use", "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV", "name": "get_stock_price", "input": { "ticker": "^GSPC" } } ] ``` You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an input, and return the following back to the model in a subsequent `user` message: ```json [ { "type": "tool_result", "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV", "content": "259.75 USD" } ] ``` Tools can be used for workflows that include running client-side tools and functions, or more generally whenever you want the model to produce a particular JSON structure of output. See our [guide](https://docs.claude.com/en/docs/tool-use) for more details. top_k: Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277). Recommended for advanced use cases only. You usually only need to use `temperature`. top_p: Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by `top_p`. You should either alter `temperature` or `top_p`, but not both. Recommended for advanced use cases only. You usually only need to use `temperature`. betas: Optional header to specify the beta version(s) you want to use. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds NrX max_tokensmessagesmodelrerfrgrhrirjrkrlrmrnrorprqrrrsrtrurvrwrxs rYcreatezMessages.create_x r[rerfrgrhrirjrkrmrnrorprqrrrsrtrurvrwrxcyu, 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. If the final message uses the `assistant` role, the response content will continue immediately from the content in that message. This can be used to constrain part of the model's response. Example with a single `user` message: ```json [{ "role": "user", "content": "Hello, Claude" }] ``` Example with multiple conversational turns: ```json [ { "role": "user", "content": "Hello there." }, { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" }, { "role": "user", "content": "Can you explain LLMs in plain English?" } ] ``` Example with a partially-filled response from Claude: ```json [ { "role": "user", "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun" }, { "role": "assistant", "content": "The best answer is (" } ] ``` Each input message `content` may be either a single `string` or an array of content blocks, where each block has a specific `type`. Using a `string` for `content` is shorthand for an array of one content block of type `"text"`. The following input messages are equivalent: ```json { "role": "user", "content": "Hello, Claude" } ``` ```json { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] } ``` See [input examples](https://docs.claude.com/en/api/messages-examples). Note that if you want to include a [system prompt](https://docs.claude.com/en/docs/system-prompts), you can use the top-level `system` parameter — there is no `"system"` role for input messages in the Messages API. There is a limit of 100,000 messages in a single request. model: The model that will complete your prompt. See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options. stream: Whether to incrementally stream the response using server-sent events. See [streaming](https://docs.claude.com/en/api/messages-streaming) for details. container: Container identifier for reuse across requests. context_management: Context management configuration. This allows you to control how Claude manages context across multiple requests, such as whether to clear function results or not. mcp_servers: MCP servers to be utilized in this request metadata: An object describing metadata about the request. output_format: A schema to specify Claude's output format in responses. service_tier: Determines whether to use priority capacity (if available) or standard capacity for this request. Anthropic offers different levels of service for your API requests. See [service-tiers](https://docs.claude.com/en/api/service-tiers) for details. stop_sequences: Custom text sequences that will cause the model to stop generating. Our models will normally stop when they have naturally completed their turn, which will result in a response `stop_reason` of `"end_turn"`. If you want the model to stop generating when it encounters custom strings of text, you can use the `stop_sequences` parameter. If the model encounters one of the custom sequences, the response `stop_reason` value will be `"stop_sequence"` and the response `stop_sequence` value will contain the matched stop sequence. system: System prompt. A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role. See our [guide to system prompts](https://docs.claude.com/en/docs/system-prompts). temperature: Amount of randomness injected into the response. Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0` for analytical / multiple choice, and closer to `1.0` for creative and generative tasks. Note that even with `temperature` of `0.0`, the results will not be fully deterministic. thinking: Configuration for enabling Claude's extended thinking. When enabled, responses include `thinking` content blocks showing Claude's thinking process before the final answer. Requires a minimum budget of 1,024 tokens and counts towards your `max_tokens` limit. See [extended thinking](https://docs.claude.com/en/docs/build-with-claude/extended-thinking) for details. tool_choice: How the model should use the provided tools. The model can use a specific tool, any available tool, decide by itself, or not use tools at all. tools: Definitions of tools that the model may use. If you include `tools` in your API request, the model may return `tool_use` content blocks that represent the model's use of those tools. You can then run those tools using the tool input generated by the model and then optionally return results back to the model using `tool_result` content blocks. There are two types of tools: **client tools** and **server tools**. The behavior described below applies to client tools. For [server tools](https://docs.claude.com/en/docs/agents-and-tools/tool-use/overview#server-tools), see their individual documentation as each has its own behavior (e.g., the [web search tool](https://docs.claude.com/en/docs/agents-and-tools/tool-use/web-search-tool)). Each tool definition includes: - `name`: Name of the tool. - `description`: Optional, but strongly-recommended description of the tool. - `input_schema`: [JSON schema](https://json-schema.org/draft/2020-12) for the tool `input` shape that the model will produce in `tool_use` output content blocks. For example, if you defined `tools` as: ```json [ { "name": "get_stock_price", "description": "Get the current stock price for a given ticker symbol.", "input_schema": { "type": "object", "properties": { "ticker": { "type": "string", "description": "The stock ticker symbol, e.g. AAPL for Apple Inc." } }, "required": ["ticker"] } } ] ``` And then asked the model "What's the S&P 500 at today?", the model might produce `tool_use` content blocks in the response like this: ```json [ { "type": "tool_use", "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV", "name": "get_stock_price", "input": { "ticker": "^GSPC" } } ] ``` You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an input, and return the following back to the model in a subsequent `user` message: ```json [ { "type": "tool_result", "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV", "content": "259.75 USD" } ] ``` Tools can be used for workflows that include running client-side tools and functions, or more generally whenever you want the model to produce a particular JSON structure of output. See our [guide](https://docs.claude.com/en/docs/tool-use) for more details. top_k: Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277). Recommended for advanced use cases only. You usually only need to use `temperature`. top_p: Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by `top_p`. You should either alter `temperature` or `top_p`, but not both. Recommended for advanced use cases only. You usually only need to use `temperature`. betas: Optional header to specify the beta version(s) you want to use. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds Nr{rXr}r~rrlrerfrgrhrirjrkrmrnrorprqrrrsrtrurvrwrxs rYrzMessages.create}rr[cyrr{rs rYrzMessages.createrr[r}r~rr}r~rrlc t|| sXt|sM|jjtk(r0|jj |t j|d}|tvr*tjd|dt|dtditdt|rdjd|Dnti|xsi}|jd t!id |d |d |d |d|d|d|d|d| d| d| d| d| d|d|d|d|d|i| rt"j$nt"j&t)||||t*| xsdt,t.S)N The model '.' is deprecated and will reach end-of-life on ~. Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.r: stacklevelanthropic-beta,c32K|]}t|ywrUstr.0es rY z"Messages.create..9PQ#a&9P/v1/messages?beta=truer}r~rrerfrgrhrirjrkrlrmrnrorprqrrrsrurvrwrxFbodyoptionscast_torl stream_cls)validate_output_formatr!rVrxr0_calculate_nonstreaming_timeoutr1getr;warningswarnDeprecationWarningr$joinr _postr#r5MessageCreateParamsStreamingMessageCreateParamsNonStreamingr7r@r2rLr|s rYrzMessages.creates< }-hw/DLL4H4HO4[llBB599%FG % % MMeW$RSdejSkRlmlm"   /T\]bTc9P%9P1Pirst " zz $  *U   )*<  "; $]#L%nff";"; U!"U#$U%*&BB*JJ/2)+Q[el ?U78A! ! r[c 8| sXt|sM|jjtk(r0|jj |t j |d}|tvr*tjd|dt|dtdt|r|Dcgc]}|c}ng}d|vr|jddditd t|rd jd |Dnti|xsi}t}tr>t@d$%Scc}w#t(j*j,$r}t/d|d}~wwxYw)'Nrrrr:rstructured-outputs-2025-11-13X-Stainless-Helperbeta.messages.parserrc32K|]}t|ywrUrrs rYrz!Messages.parse..=rr json_schemaschematypetCould not generate JSON schema for the given `output_format` type. Use a type that works with `pydanitc.TypeAdapter`c rt|tttr  StSNresponserir>r r=r!rrs rYparserzMessages.parse..parserSC!!"#%-m%<AZM aj r[rr}r~rrerfrgrhrirjrkrlrmrnrorprqrrrsrurvrwrx post_parserFrrrrlrr@return"ParsedBetaMessage[ResponseFormatT]!r!rVrxr0rr1rr;rrrappendr$rrr'rr5 OutputFormatr?pydanticerrorsPydanticSchemaGenerationError TypeErrorrr#rr7r rrFr=r@rXr}r~rrerfrgrhrirjrkrlrmrnrorprqrrrsrtrurvrwrxbetatransformed_output_format adapted_typerrrs ` rYparsezMessages.parse s:hw/DLL4H4HO4[llBB599%FG % % MMeW$RSdejSkRlmlm"  -5UO%($( *% 7 LL8 9 !"7 /T\]bTc9P%9P1Pirst " ^g! M "}'@9D]9SL %113,A,N,N+F3--) zz $  *U   )*<  "; $%>#L%nff";"; U!"U#$U%(&EE+.)+'%" /@A;OC" " O),??@@ L   s G&0G++H HH)rerfmax_iterationsrgrhrirjrkrlrmrnrrrsrorprtrurvrwrxcyrUr{)rXr}r~rrqrerfrrgrhrirjrkrlrmrnrrrsrorprtrurvrwrxs rY tool_runnerzMessages.tool_runners<+.r[rrerfrgrhrirjrkrmrnrrrsrorprtrurvrwrxcyrUr{rXr}r~rrqrlrrerfrgrhrirjrkrmrnrrrsrorprtrurvrwrxs rYrzMessages.tool_runners<47r[cyrUr{rs rYrzMessages.tool_runners <VYr[rrerfrgrhrirjrkrlrmrnrrrsrorprtrurvrwrxc |tvr*tjd|dt|dtdddit dt |rd j d |Dnti|xsi}ttjtid |d |d |d|d|d|d| d| d| d| d|d|d|d|d|Dcgc]}|jc}d|d|}| rBtt||||||dtd|jt |r|SdStt||||||dtd|jt |r|SdScc}w) Create a Message streamrrrr:rrr,rrc32K|]}t|ywrUrrs rYrz'Messages.tool_runner..rrr}r~rrerfrgrhrirjrkrmrnrorprqrrrsrrONrqparamsrclientr)r;rrrr$r!rrr r5ParseMessageCreateParamsBaser=to_dictr.rVr,rXr}r~rrqrrerfrgrhrirjrkrlrmrnrrrsrorprtrurvrwrxtoolrs rYrzMessages.tool_runners;> % % MMeW$RSdejSkRlmlm"  !"2 /T\]bTc9P%9P1Pirst "  ! > > O j H  Y   %&8   {  H     !. & { H { U;T$,,.;  ! "#  . *?;%2#.",&  K619.1I~  PT  o.!.*("   T\\2-5n-E>  LP  '<<E'c (|tvr*tjd|dt|dtd ddit dt |rd j d |Dnti|xsi}t}t |r>|.crrrrrrr}r~rrhrirerfrgrjrkrmrnrorrrsrqrprlTrrri)r;rrrr$r!rrr'rr5rr?rrrrr rr#MessageCreateParamsr7r@r2rLr8r r=)rXr}r~rrerfrgrhrirjrkrmrnrorprqrrrsrtrurvrwrxrrrr make_requests rYrlzMessages.stream=sV8 % % MMeW$RSdejSkRlmlm"  & ' /T\]bTc9P%9P1Pirst " ^g! M "}'@9D]9SL %113,A,N,N+F3--) JJ $  *U  $%>    )*<";#L%nf";UU U!"";#$d%(&99+.)+Q[el 78?  B( DZgDhiiS??@@ L   s0E##F F  F rfrgrirmrorprqrtrurvrwrxc4itdt| r#djtd| Ddgnti| xsi} ddi| xsi} |j dt ||||||||| d tjt| | | |tS) 1 Count the number of tokens in a Message. The Token Count API can be used to count the number of tokens in a Message, including tools, images, and documents, without creating it. Learn more about token counting in our [user guide](https://docs.claude.com/en/docs/build-with-claude/token-counting) Args: 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. If the final message uses the `assistant` role, the response content will continue immediately from the content in that message. This can be used to constrain part of the model's response. Example with a single `user` message: ```json [{ "role": "user", "content": "Hello, Claude" }] ``` Example with multiple conversational turns: ```json [ { "role": "user", "content": "Hello there." }, { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" }, { "role": "user", "content": "Can you explain LLMs in plain English?" } ] ``` Example with a partially-filled response from Claude: ```json [ { "role": "user", "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun" }, { "role": "assistant", "content": "The best answer is (" } ] ``` Each input message `content` may be either a single `string` or an array of content blocks, where each block has a specific `type`. Using a `string` for `content` is shorthand for an array of one content block of type `"text"`. The following input messages are equivalent: ```json { "role": "user", "content": "Hello, Claude" } ``` ```json { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] } ``` See [input examples](https://docs.claude.com/en/api/messages-examples). Note that if you want to include a [system prompt](https://docs.claude.com/en/docs/system-prompts), you can use the top-level `system` parameter — there is no `"system"` role for input messages in the Messages API. There is a limit of 100,000 messages in a single request. model: The model that will complete your prompt. See [models](https://docs.anthropic.com/en/docs/models-overview) for additional details and options. context_management: Context management configuration. This allows you to control how Claude manages context across multiple requests, such as whether to clear function results or not. mcp_servers: MCP servers to be utilized in this request output_format: A schema to specify Claude's output format in responses. system: System prompt. A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role. See our [guide to system prompts](https://docs.claude.com/en/docs/system-prompts). thinking: Configuration for enabling Claude's extended thinking. When enabled, responses include `thinking` content blocks showing Claude's thinking process before the final answer. Requires a minimum budget of 1,024 tokens and counts towards your `max_tokens` limit. See [extended thinking](https://docs.claude.com/en/docs/build-with-claude/extended-thinking) for details. tool_choice: How the model should use the provided tools. The model can use a specific tool, any available tool, decide by itself, or not use tools at all. tools: Definitions of tools that the model may use. If you include `tools` in your API request, the model may return `tool_use` content blocks that represent the model's use of those tools. You can then run those tools using the tool input generated by the model and then optionally return results back to the model using `tool_result` content blocks. There are two types of tools: **client tools** and **server tools**. The behavior described below applies to client tools. For [server tools](https://docs.claude.com/en/docs/agents-and-tools/tool-use/overview#server-tools), see their individual documentation as each has its own behavior (e.g., the [web search tool](https://docs.claude.com/en/docs/agents-and-tools/tool-use/web-search-tool)). Each tool definition includes: - `name`: Name of the tool. - `description`: Optional, but strongly-recommended description of the tool. - `input_schema`: [JSON schema](https://json-schema.org/draft/2020-12) for the tool `input` shape that the model will produce in `tool_use` output content blocks. For example, if you defined `tools` as: ```json [ { "name": "get_stock_price", "description": "Get the current stock price for a given ticker symbol.", "input_schema": { "type": "object", "properties": { "ticker": { "type": "string", "description": "The stock ticker symbol, e.g. AAPL for Apple Inc." } }, "required": ["ticker"] } } ] ``` And then asked the model "What's the S&P 500 at today?", the model might produce `tool_use` content blocks in the response like this: ```json [ { "type": "tool_use", "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV", "name": "get_stock_price", "input": { "ticker": "^GSPC" } } ] ``` You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an input, and return the following back to the model in a subsequent `user` message: ```json [ { "type": "tool_result", "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV", "content": "259.75 USD" } ] ``` Tools can be used for workflows that include running client-side tools and functions, or more generally whenever you want the model to produce a particular JSON structure of output. See our [guide](https://docs.claude.com/en/docs/tool-use) for more details. betas: Optional header to specify the beta version(s) you want to use. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds rrc32K|]}t|ywrUrrs rYrz(Messages.count_tokens..u5Lc!f5Lrtoken-counting-2024-11-01#/v1/messages/count_tokens?beta=true r~rrfrgrirmrorprqrrrr) r$r!rr r rr#r6MessageCountTokensParamsr7rJrXr~rrfrgrirmrorprqrtrurvrwrxs rY count_tokenszMessages.count_tokenssl  $'*hhu5Le5LOjNk/l&m"  "  *+F`=K^\^` zz 1 ("*<#.%2$ (#." ,DD )+Q[el+'  r[)rr)rr^)rrb0r}intr~Iterable[BetaMessageParam]rr<re0Optional[message_create_params.Container] | Omitrf1Optional[BetaContextManagementConfigParam] | Omitrg7Iterable[BetaRequestMCPServerURLDefinitionParam] | OmitrhBetaMetadataParam | Omitri*Optional[BetaJSONOutputFormatParam] | Omitrj'Literal['auto', 'standard_only'] | OmitrkSequenceNotStr[str] | OmitrlLiteral[False] | Omitrm/Union[str, Iterable[BetaTextBlockParam]] | Omitrn float | OmitroBetaThinkingConfigParam | OmitrpBetaToolChoiceParam | Omitrq#Iterable[BetaToolUnionParam] | Omitrr int | OmitrsrrtList[AnthropicBetaParam] | OmitruHeaders | Nonerv Query | Nonerw Body | Nonerx'float | httpx.Timeout | None | NotGivenrr@)0r}rr~rrr<rl Literal[True]rerrfrrgrrhrrirrjrrkrrmrrnrrorrprrqrrrrrsrrtrrurrvrrwrrxr rz!Stream[BetaRawMessageStreamEvent])0r}rr~rrr<rlboolrerrfrrgrrhrrirrjrrkrrmrrnrrorrprrqrrrrrsrrtrrurrvrrwrrxr r/BetaMessage | Stream[BetaRawMessageStreamEvent])0r}rr~rrr<rerrfrrgrrhrrirrjrrkrrl%Literal[False] | Literal[True] | Omitrmrrnrrorrprrqrrrrrsrrtrrurrvrrwrrxr rr 0r}rr~rrr<rerrfrrgrrhrri&Optional[type[ResponseFormatT]] | Omitrjrrkrrlr rmrrnrrorrprrqrrrrrsrrtrrurrvrrwrrxr rr)2r}rr~rrr<rqIterable[BetaRunnableTool]rerrfrrrrgrrhrrirrjrrkrrlrrmrrnrrrrrsrrorrprrtrrurrvrrwrrxr rzBetaToolRunner[ResponseFormatT])2r}rr~rrr<rqrrlr rrrerrfrrgrrhrrirrjrrkrrmrrnrrrrrsrrorrprrtrrurrvrrwrrxr rz(BetaStreamingToolRunner[ResponseFormatT])2r}rr~rrr<rqrrlr rrrerrfrrgrrhrrirrjrrkrrmrrnrrrrrsrrorrprrtrrurrvrrwrrxr rJBetaStreamingToolRunner[ResponseFormatT] | BetaToolRunner[ResponseFormatT])2r}rr~rrr<rqrrrrerrfrrgrrhrrirrjrrkrrlz bool | Omitrmrrnrrrrrsrrorrprrtrrurrvrrwrrxr rr).r}rr~rrr<rerrfrrgrrhrrirrjrrkrrmrrnrrorrprrqrrrrrsrrtrrurrvrrwrrxr rz)BetaMessageStreamManager[ResponseFormatT]r~rrr<rfrrgrrirrmrrorrprrqz1Iterable[message_count_tokens_params.Tool] | Omitrtrrurrvrrwrrxr rrJ__name__ __module__ __qualname__r&rZr_rcrrr rr"rrrrlrr{r[rYrQrQGs%%--33GKPTOS-1DH@D59(,BF$(372659 "15)-$("&;D7[ [ - [  [ D [ N[ M[ +[ B[ >[ 3[ &[ @[ "[ 1![ "0#[ $3%[ &'[ ()[ */+[ 0&1[ 2"3[ 4 5[ 697[ 8 9[ [ zGKPTOS-1DH@D59BF$(372659 "15)-$("&;D7[ [ - [  [  [ D[ N[ M[ +[ B[ >[ 3[ @[ "[ 1![ "0#[ $3%[ &'[ ()[ */+[ 0&1[ 2"3[ 4 5[ 697[ 8 +9[ [ zGKPTOS-1DH@D59BF$(372659 "15)-$("&;D7[ [ - [  [  [ D[ N[ M[ +[ B[ >[ 3[ @[ "[ 1![ "0#[ $3%[ &'[ ()[ */+[ 0&1[ 2"3[ 4 5[ 697[ 8 99[ [ z68efGKPTOS-1DH@D598P 3P 6P @P "P 1!P "0#P $3%P &'P ()P */+P 0&1P 2"3P 4 5P 697P 8 99P gP pGKPTOS-1@D@D598r >r 3r 6r @r "r 1!r "0#r $3%r &'r ()r */+r 0&1r 2"3r 4 5r 697r 8 ,9r hGKPT%)OS-1@D@D59(,BF$( "372615)-$("&;D9..- .  . * .D.N.#.M.+.>.>.3.&. @!.""#.$%.&'.(1).*0+.,/-.2&3.4"5.6 7.899.: );..>&*FJPTOS-1@D@D59BF$( "372615)-$("&;D977- 7  7 * 77#7D7N7M7+7>7>737 @!7""#7$%7&'7(1)7*0+7,/-72&374"576 778997: 2;77>&*FJPTOS-1@D@D59BF$( "372615)-$("&;D9YY- Y  Y * YY#YDYNYMY+Y>Y>Y3Y @!Y""#Y$%Y&'Y(1)Y*0+Y,/-Y2&3Y4"5Y6 7Y899Y: T;YYL&*FJPTOS-1@D@D59"BF$( "372615)-$("&;D9[ [ - [  [ * [ #[ D[ N[ M[ +[ >[ >[ 3[ [ @![ ""#[ $%[ &'[ (1)[ *0+[ ,/-[ 2&3[ 4"5[ 6 7[ 899[ : T;[ FGKPTOS-1@D@D59BF$(372659 "15)-$("&;D5]j]j- ]j  ]j D ]jN]jM]j+]j>]j>]j3]j@]j"]j1]j 0!]j"3#]j$%]j&']j(/)]j.&/]j0"1]j2 3]j495]j6 37]jHQUOSDHBF3726CG15)-$("&;D%u -u  u N u M u Bu @u 1u 0u Au /u &u "!u " #u $9%u & 'u r[ceZdZeddZeddZeddZeeeeeeeeeeeeeeeeeddde d ddZ eeeeeeeeeeeeeeeeddde d ddZ eeeeeeeeeeeeeeeeddde d dd Z e gd gd eeeeeeeeeeeeeeeeddde d dd Z eeeeeeeeeeeeeeeeddde d dd Z eeeeeeeeeeeeeeeeeddde d d dZeeeeeeeeeeeeeeeeddde d d!dZeeeeeeeeeeeeeeeeddde d d"dZeeeeeeeeeeeeeeeeddde d d#dZeeeeeeeeeeeeeeeddde d d$dZeeeeeeeeddde d d%dZy)&rRc,t|jSrU)rrVrWs rYrZzAsyncMessages.batchessDLL))r[ct|Sr])AsyncMessagesWithRawResponserWs rYr_zAsyncMessages.with_raw_responses,D11r[ct|Sra)"AsyncMessagesWithStreamingResponserWs rYrcz%AsyncMessages.with_streaming_responses2$77r[Nrdc Kywrzr{r|s rYrzAsyncMessages.create x rc Kywrr{rs rYrzAsyncMessages.createrrc Kywrr{rs rYrzAsyncMessages.createrrrrc Kt|| sXt|sM|jjtk(r0|jj |t j|d}|tvr*tjd|dt|dtditdt|rdjd|Dnti|xsi}|jd t!id |d |d |d |d|d|d|d|d| d| d| d| d| d|d|d|d|d|i| rt"j$nt"j&d{t)||||t*| xsdt,t.d{S757w)Nrrrr:rrrc32K|]}t|ywrUrrs rYrz'AsyncMessages.create..3 rrrr}r~rrerfrgrhrirjrkrlrmrnrorprqrrrsrFr)rr!rVrxr0rr1rr;rrrr$rr rr%r5rrr7r@r3rLr|s rYrzAsyncMessages.create s*< }-hw/DLL4H4HO4[llBB599%FG % % MMeW$RSdejSkRlmlm"   /T\]bTc9P%9P1Pirst " ZZ $, *U   )*<  "; $]#L%nff";"; U!"U#$U%*&BB*JJ/2)+Q[el ?U"#<=A ! ! ! ! s$EFE> 0F9F:FFc TK| sXt|sM|jjtk(r0|jj |t j |d}|tvr*tjd|dt|dtdt|r|Dcgc]}|c}ng}d|vr|jddditd t|rd jd |Dnti|xsi}t}tr>t@d$%d{Scc}w#t(j*j,$r}t/d|d}~wwxYw7:w)'Nrrrr:rrrrrrc32K|]}t|ywrUrrs rYrz&AsyncMessages.parse.. rrrrrc rt|tttr  StSrrrs rYrz#AsyncMessages.parse..parser rr[rr}r~rrerfrgrhrirjrkrlrmrnrorprqrrrsrFrrrrs ` rYrzAsyncMessages.parseY s:hw/DLL4H4HO4[llBB599%FG % % MMeW$RSdejSkRlmlm"  -5UO%($( *% 7 LL8 9 !"7 /T\]bTc9P%9P1Pirst " ^g! M "}'@9D]9SL %113,A,N,N+F3--) ZZ $  *U   )*<  "; $%>#L%nff";"; U!"U#$U%(&EE+.)+'%" /@A;OC " " " O),??@@ L   "" sDBH( G0(A6H(0G5BH(+H&, H(5H# HH##H(rcyrUr{)rXr}r~rrqrrerfrgrhrirjrkrlrmrnrrrsrorprtrurvrwrxs rYrzAsyncMessages.tool_runner s<03r[rcyrUr{rs rYrzAsyncMessages.tool_runner s<9.T rrr}r~rrerfrgrhrirjrkrmrnrorprqrrrsrrPNr)r;rrrr$r!rrr r5rr=rr/rVr-rs rYrzAsyncMessages.tool_runner, s=> % % MMeW$RSdejSkRlmlm"  !"2 /T\]bTc9P%9P1Pirst "  ! > > O j H  Y   %&8   {  H     !. & { H { U;T$,,.;  ! "#  . /@%2#.",&  ,dll;19.1I~  PT  #?3!.*("  ($,,7-5n-E>  LP  '|. rrrrrz /v1/messagesr}r~rrhrirerfrgrjrkrmrnrorrrsrqrprlTrrr)r;rrrr$r!rrr'rr5rr?rrrrrr#rr7r@r3rLr9r r=)rXr}r~rrhrirerfrgrjrkrmrnrorprqrrrsrtrurvrwrxrrrrrequests rYrlzAsyncMessages.stream sU8 % % MMeW$RSdejSkRlmlm"  ( /T\]bTc9P%9P1Pirst " ^g! M "}'@9D]9SL %113,A,N,N+F3--)**   *U  $%>    )*<";#L%nf";UU U!"";#$d%(&99+.)+Q[el "#<== @-WDZgDhiiO??@@ L   s0EF : FF rcdKitdt| r#djtd| Ddgnti| xsi} ddi| xsi} |j dt ||||||||| d tjd{t| | | |t d{S7$7w) rrrc32K|]}t|ywrUrrs rYrz-AsyncMessages.count_tokens.. rrrrrNrr) r$r!rr r rr%r6rr7rJrs rYrzAsyncMessages.count_tokens sl  $'*hhu5Le5LOjNk/l&m"  "  *+F`=K^\^` ZZ 1, ("*<#.%2$ (#." ,DD  )+Q[el+'      s$BB0B, B0'B.(B0.B0)rr)rr)rrr)0r}rr~rrr<rlr rerrfrrgrrhrrirrjrrkrrmrrnrrorrprrqrrrrrsrrtrrurrvrrwrrxr rz&AsyncStream[BetaRawMessageStreamEvent])0r}rr~rrr<rlr rerrfrrgrrhrrirrjrrkrrmrrnrrorrprrqrrrrrsrrtrrurrvrrwrrxr r4BetaMessage | AsyncStream[BetaRawMessageStreamEvent])0r}rr~rrr<rerrfrrgrrhrrirrjrrkrrlr rmrrnrrorrprrqrrrrrsrrtrrurrvrrwrrxr rr1r)2r}rr~rrr<rqIterable[BetaAsyncRunnableTool]rrrerrfrrgrrhrrirrjrrkrrlrrmrrnrrrrrsrrorrprrtrrurrvrrwrrxr rz$BetaAsyncToolRunner[ResponseFormatT])2r}rr~rrr<rqr2rlr rrrerrfrrgrrhrrirrjrrkrrmrrnrrrrrsrrorrprrtrrurrvrrwrrxr rz-BetaAsyncStreamingToolRunner[ResponseFormatT])2r}rr~rrr<rqr2rlr rrrerrfrrgrrhrrirrjrrkrrmrrnrrrrrsrrorrprrtrrurrvrrwrrxr rzTBetaAsyncStreamingToolRunner[ResponseFormatT] | BetaAsyncToolRunner[ResponseFormatT])2r}rr~rrr<rqr2rrrerrfrrgrrhrrirrjrrkrrlz%Literal[True] | Literal[False] | Omitrmrrnrrrrrsrrorrprrtrrurrvrrwrrxr rzTBetaAsyncToolRunner[ResponseFormatT] | BetaAsyncStreamingToolRunner[ResponseFormatT]).r}rr~rrr<rhrrirrerrfrrgrrjrrkrrmrrnrrorrprrqrrrrrsrrtrrurrvrrwrrxr rz.BetaAsyncMessageStreamManager[ResponseFormatT]rrr{r[rYrRrRs**2288GKPTOS-1DH@D59(,BF$(372659 "15)-$("&;D7[ [ - [  [ D [ N[ M[ +[ B[ >[ 3[ &[ @[ "[ 1![ "0#[ $3%[ &'[ ()[ */+[ 0&1[ 2"3[ 4 5[ 697[ 8 9[ [ zGKPTOS-1DH@D59BF$(372659 "15)-$("&;D7[ [ - [  [  [ D[ N[ M[ +[ B[ >[ 3[ @[ "[ 1![ "0#[ $3%[ &'[ ()[ */+[ 0&1[ 2"3[ 4 5[ 697[ 8 09[ [ zGKPTOS-1DH@D59BF$(372659 "15)-$("&;D7[ [ - [  [  [ D[ N[ M[ +[ B[ >[ 3[ @[ "[ 1![ "0#[ $3%[ &'[ ()[ */+[ 0&1[ 2"3[ 4 5[ 697[ 8 >9[ [ z68efGKPTOS-1DH@D598P 3P 6P @P "P 1!P "0#P $3%P &'P ()P */+P 0&1P 2"3P 4 5P 697P 8 >9P gP pGKPTOS-1@D@D598q >q 3q 6q @q "q 1!q "0#q $3%q &'q ()q */+q 0&1q 2"3q 4 5q 697q 8 ,9q f&*FJPTOS-1@D@D59(,BF$( "372615)-$("&;D933- 3  3 / 3#3D3N3M3+3>3>333&3 @!3""#3$%3&'3(1)3*0+3,/-32&334"536 738993: .;33>&*FJPTOS-1@D@D59BF$( "372615)-$("&;D9<<- <  < / <<#<D<N<M<+<><><3< @!<""#<$%<&'<(1)<*0+<,/-<2&3<4"5<6 7<899<: 7;<<>&*FJPTOS-1@D@D59BF$( "372615)-$("&;D9cc- c  c / cc#cDcNcMc+c>c>c3c @!c""#c$%c&'c(1)c*0+c,/-c2&3c4"5c6 7c899c: ^;ccL&*FJPTOS-1@D@D598[ >[ 3[ 6[ @![ ""#[ $%[ &'[ (1)[ *0+[ ,/-[ 2&3[ 4"5[ 6 7[ 899[ : ^;[ F.2@DFJPTOS@D59BF$(372659 "15)-$("&;D5ZjZj- Zj  Zj + Zj>ZjDZjNZjMZj>Zj3Zj@Zj"Zj1Zj 0!Zj"3#Zj$%Zj&'Zj(/)Zj.&/Zj0"1Zj2 3Zj495Zj6 87ZjBQUOSDHBF3726CG15)-$("&;D%u -u  u N u M u Bu @u 1u 0u Au /u &u "!u " #u $9%u & 'u r[c&eZdZddZeddZy)r^c||_tj|j|_tj|j|_yrU) _messagesrto_raw_response_wrapperrrrXr~s rY__init__z MessagesWithRawResponse.__init__ s@!&>> OO  -DD  ! ! r[c@t|jjSrU)rr5rZrWs rYrZzMessagesWithRawResponse.batches s%dnn&<&<==r[Nr~rQrNone)rrrrrr8r&rZr{r[rYr^r^ s >>r[r^c&eZdZddZeddZy)rc||_tj|j|_tj|j|_yrU)r5rasync_to_raw_response_wrapperrrr7s rYr8z%AsyncMessagesWithRawResponse.__init__ s@!&DD OO  -JJ  ! ! r[c@t|jjSrU)rr5rZrWs rYrZz$AsyncMessagesWithRawResponse.batches s*4>>+A+ABBr[Nr~rRrr;)rrr<r{r[rYrr s CCr[rc&eZdZddZeddZy)rbcz||_t|j|_t|j|_yrU)r5r*rrr7s rYr8z&MessagesWithStreamingResponse.__init__ s4!2 OO  9  ! ! r[c@t|jjSrU)rr5rZrWs rYrZz%MessagesWithStreamingResponse.batches s+DNN,B,BCCr[Nr:)rrr<r{r[rYrbrb s DDr[rbc&eZdZddZeddZy)rcz||_t|j|_t|j|_yrU)r5r+rrr7s rYr8z+AsyncMessagesWithStreamingResponse.__init__ s4!8 OO  ?  ! ! r[c@t|jjSrU)rr5rZrWs rYrZz*AsyncMessagesWithStreamingResponse.batches s01G1GHHr[NrA)rrr<r{r[rYrr s IIr[rcztj|r&t|tjr t dyy)NzoYou tried to pass a `BaseModel` class to `beta.messages.create()`; You must use `beta.messages.parse()` instead)inspectisclass issubclassr BaseModelrrs rYrr s6}%*]HDVDV*W }  +X%r[)riobjectrr;)~ __future__rrIrtypingrrrrrr r functoolsr itertoolsr typing_extensionsr rhttpxrrrZrrrrrr_typesrrrrrrrrr _utilsr!r"r#r$r%_compatr&_modelsr' _resourcer(r) _responser*r+ lib.toolsr,r-r.r/ _constantsr0r1 _streamingr2r3 types.betar4r5r6 _base_clientr7 lib.streamingr8r9messages.messagesr;types.model_paramr<lib._parse._responser=r>lib._parse._transformr?types.beta.beta_messager@lib.tools._beta_functionsrArBtypes.anthropic_beta_paramrCtypes.beta.beta_message_paramrDtypes.beta.beta_metadata_paramrEtypes.beta.parsed_beta_messagerF types.beta.beta_text_block_paramrG types.beta.beta_tool_union_paramrH!types.beta.beta_tool_choice_paramrI$types.beta.beta_message_tokens_countrJ%types.beta.beta_thinking_config_param(types.beta.beta_json_output_format_paramrK(types.beta.beta_raw_message_stream_eventrL/types.beta.beta_context_management_config_paramrM7types.beta.beta_request_mcp_server_url_definition_paramrNrVrOrP__all__rQrRr^rrbrrr{r[rYrus#MMM/ !hgggg'#;Z F. 2U2,D63Q=>@@CCEKMRR`n5  'J J Z2F $F R2 > > C C D D I I  r[