pub struct MessageCountTokensParams {
pub messages: Vec<MessageParam>,
pub model: Model,
pub system: Option<SystemPrompt>,
pub thinking: Option<ThinkingConfig>,
pub tool_choice: Option<ToolChoice>,
pub tools: Option<Vec<ToolUnionParam>>,
}anthropic-client only.Expand description
Parameters for counting tokens in messages.
Fields§
§messages: Vec<MessageParam>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.
model: ModelThe model that will count tokens.
See models for additional details and options.
system: Option<SystemPrompt>System prompt.
A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role. See the guide to system prompts.
thinking: Option<ThinkingConfig>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 for details.
tool_choice: Option<ToolChoice>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: Option<Vec<ToolUnionParam>>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.
Implementations§
Source§impl MessageCountTokensParams
impl MessageCountTokensParams
Sourcepub fn new(
messages: Vec<MessageParam>,
model: Model,
) -> MessageCountTokensParams
pub fn new( messages: Vec<MessageParam>, model: Model, ) -> MessageCountTokensParams
Create a new MessageCountTokensParams with the required fields.
Sourcepub fn with_system_string(self, system: String) -> MessageCountTokensParams
pub fn with_system_string(self, system: String) -> MessageCountTokensParams
Add a system prompt as a string.
Sourcepub fn with_system_blocks(
self,
blocks: Vec<TextBlock>,
) -> MessageCountTokensParams
pub fn with_system_blocks( self, blocks: Vec<TextBlock>, ) -> MessageCountTokensParams
Add a system prompt as text blocks.
Sourcepub fn with_system(self, system: SystemPrompt) -> MessageCountTokensParams
pub fn with_system(self, system: SystemPrompt) -> MessageCountTokensParams
Add a system prompt.
Sourcepub fn with_thinking(self, thinking: ThinkingConfig) -> MessageCountTokensParams
pub fn with_thinking(self, thinking: ThinkingConfig) -> MessageCountTokensParams
Add thinking configuration.
Sourcepub fn with_tool_choice(
self,
tool_choice: ToolChoice,
) -> MessageCountTokensParams
pub fn with_tool_choice( self, tool_choice: ToolChoice, ) -> MessageCountTokensParams
Add tool choice.
Sourcepub fn with_tools(self, tools: Vec<ToolUnionParam>) -> MessageCountTokensParams
pub fn with_tools(self, tools: Vec<ToolUnionParam>) -> MessageCountTokensParams
Add tools.
Trait Implementations§
Source§impl Clone for MessageCountTokensParams
impl Clone for MessageCountTokensParams
Source§fn clone(&self) -> MessageCountTokensParams
fn clone(&self) -> MessageCountTokensParams
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MessageCountTokensParams
impl Debug for MessageCountTokensParams
Source§impl<'de> Deserialize<'de> for MessageCountTokensParams
impl<'de> Deserialize<'de> for MessageCountTokensParams
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<MessageCountTokensParams, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<MessageCountTokensParams, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for MessageCountTokensParams
impl Serialize for MessageCountTokensParams
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for MessageCountTokensParams
impl RefUnwindSafe for MessageCountTokensParams
impl Send for MessageCountTokensParams
impl Sync for MessageCountTokensParams
impl Unpin for MessageCountTokensParams
impl UnsafeUnpin for MessageCountTokensParams
impl UnwindSafe for MessageCountTokensParams
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request