aws_sdk_bedrockruntime/client/count_tokens.rs
1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2impl super::Client {
3    /// Constructs a fluent builder for the [`CountTokens`](crate::operation::count_tokens::builders::CountTokensFluentBuilder) operation.
4    ///
5    /// - The fluent builder is configurable:
6    ///   - [`model_id(impl Into<String>)`](crate::operation::count_tokens::builders::CountTokensFluentBuilder::model_id) / [`set_model_id(Option<String>)`](crate::operation::count_tokens::builders::CountTokensFluentBuilder::set_model_id):<br>required: **true**<br><p>The unique identifier or ARN of the foundation model to use for token counting. Each model processes tokens differently, so the token count is specific to the model you specify.</p><br>
7    ///   - [`input(CountTokensInput)`](crate::operation::count_tokens::builders::CountTokensFluentBuilder::input) / [`set_input(Option<CountTokensInput>)`](crate::operation::count_tokens::builders::CountTokensFluentBuilder::set_input):<br>required: **true**<br><p>The input for which to count tokens. The structure of this parameter depends on whether you're counting tokens for an <code>InvokeModel</code> or <code>Converse</code> request:</p> <ul>  <li>   <p>For <code>InvokeModel</code> requests, provide the request body in the <code>invokeModel</code> field</p></li>  <li>   <p>For <code>Converse</code> requests, provide the messages and system content in the <code>converse</code> field</p></li> </ul> <p>The input format must be compatible with the model specified in the <code>modelId</code> parameter.</p><br>
8    /// - On success, responds with [`CountTokensOutput`](crate::operation::count_tokens::CountTokensOutput) with field(s):
9    ///   - [`input_tokens(i32)`](crate::operation::count_tokens::CountTokensOutput::input_tokens): <p>The number of tokens in the provided input according to the specified model's tokenization rules. This count represents the number of input tokens that would be processed if the same input were sent to the model in an inference request. Use this value to estimate costs and ensure your inputs stay within model token limits.</p>
10    /// - On failure, responds with [`SdkError<CountTokensError>`](crate::operation::count_tokens::CountTokensError)
11    pub fn count_tokens(&self) -> crate::operation::count_tokens::builders::CountTokensFluentBuilder {
12        crate::operation::count_tokens::builders::CountTokensFluentBuilder::new(self.handle.clone())
13    }
14}