Model

Trait Model 

Source
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§

Source

fn name(&self) -> &'static str

Human-readable model name (e.g., “Claude Sonnet 4.5”)

Source

fn max_context_tokens(&self) -> usize

Maximum input context tokens

Source

fn max_output_tokens(&self) -> usize

Maximum output tokens the model can generate

Source

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§

Source

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.

Source

fn estimate_content_block_tokens(&self, block: &ContentBlock) -> usize

Estimate tokens for a single content block

Implementors§