pub trait Model: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn max_context_tokens(&self) -> usize;
fn max_output_tokens(&self) -> usize;
fn estimate_token_count(&self, text: &str) -> usize;
// Provided methods
fn estimate_message_tokens(&self, messages: &[Message]) -> usize { ... }
fn estimate_content_block_tokens(&self, block: &ContentBlock) -> usize { ... }
}Expand description
Core model metadata trait
All models implement this to provide their capabilities. This is provider-agnostic - the same model has the same context window whether accessed via Bedrock or Anthropic.
Required Methods§
Sourcefn max_context_tokens(&self) -> usize
fn max_context_tokens(&self) -> usize
Maximum input context tokens
Sourcefn max_output_tokens(&self) -> usize
fn max_output_tokens(&self) -> usize
Maximum output tokens the model can generate
Sourcefn estimate_token_count(&self, text: &str) -> usize
fn estimate_token_count(&self, text: &str) -> usize
Estimate token count for text
Models should implement this to provide accurate token estimation. A simple heuristic (~4 characters per token) works reasonably well for most models but can be overridden with actual tokenization.
Provided Methods§
Sourcefn estimate_message_tokens(&self, messages: &[Message]) -> usize
fn estimate_message_tokens(&self, messages: &[Message]) -> usize
Estimate tokens for a conversation
Default implementation sums token estimates for all content blocks plus overhead for message structure.
Sourcefn estimate_content_block_tokens(&self, block: &ContentBlock) -> usize
fn estimate_content_block_tokens(&self, block: &ContentBlock) -> usize
Estimate tokens for a single content block