Skip to main content

LlmProvider

Trait LlmProvider 

Source
pub trait LlmProvider: Send + Sync {
    // Required methods
    fn complete<'life0, 'async_trait>(
        &'life0 self,
        request: CompletionRequest,
    ) -> Pin<Box<dyn Future<Output = Result<CompletionResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn stream<'life0, 'async_trait>(
        &'life0 self,
        request: CompletionRequest,
    ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamChunk>> + Send>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn model_id(&self) -> &str;
    fn max_tokens(&self) -> usize;
    fn provider_name(&self) -> &str;
    fn supports_strict_tools(&self) -> bool;
    fn supports_streaming_tool_deltas(&self) -> bool;
    fn native_tool_format(&self) -> ToolFormat;
}
Expand description

Trait for LLM completion providers (Anthropic, OpenAI, OpenRouter, Ollama).

Each provider uses its native SDK and implements this unified interface. The native_tool_format() method indicates which tool schema format the provider expects, enabling automatic translation via crates/providers/tool_formats.rs.

Required Methods§

Source

fn complete<'life0, 'async_trait>( &'life0 self, request: CompletionRequest, ) -> Pin<Box<dyn Future<Output = Result<CompletionResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send a completion request and return the full response.

Source

fn stream<'life0, 'async_trait>( &'life0 self, request: CompletionRequest, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamChunk>> + Send>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send a completion request and return a stream of chunks.

Source

fn model_id(&self) -> &str

The model identifier (e.g. “claude-sonnet-4-20250514”, “gpt-4o”).

Source

fn max_tokens(&self) -> usize

Maximum context window size in tokens.

Source

fn provider_name(&self) -> &str

Provider name for logging and fallback chain (“anthropic”, “openai”, “openrouter”, “ollama”).

Source

fn supports_strict_tools(&self) -> bool

Whether this provider supports strict tool mode (guaranteed schema compliance).

Source

fn supports_streaming_tool_deltas(&self) -> bool

Whether this provider supports streaming tool call deltas (e.g. Anthropic fine-grained tool streaming).

Source

fn native_tool_format(&self) -> ToolFormat

The native tool definition format this provider expects.

Implementors§