pub struct AnthropicProvider { /* private fields */ }Expand description
Built-in provider for the Anthropic Messages API.
Requires the anthropic feature flag.
§Example
use llm_agent_runtime::providers::AnthropicProvider;
let provider = AnthropicProvider::new("sk-ant-...");Implementations§
Source§impl AnthropicProvider
impl AnthropicProvider
Sourcepub fn new(api_key: impl Into<String>) -> Self
pub fn new(api_key: impl Into<String>) -> Self
Create a new Anthropic provider with the given API key.
Sourcepub fn with_base_url(
api_key: impl Into<String>,
api_url: impl Into<String>,
) -> Self
pub fn with_base_url( api_key: impl Into<String>, api_url: impl Into<String>, ) -> Self
Create a provider pointing to a custom API endpoint.
Useful for testing against a mock server or routing through a proxy.
Sourcepub fn with_max_concurrent_streams(
api_key: impl Into<String>,
max: usize,
) -> Self
pub fn with_max_concurrent_streams( api_key: impl Into<String>, max: usize, ) -> Self
Create a provider with a custom limit on concurrent streaming tasks.
Useful when many agents share a single provider and you want to cap the number of simultaneous SSE parse tasks.
Sourcepub fn with_stream_max_tokens(self, max_tokens: u32) -> Self
pub fn with_stream_max_tokens(self, max_tokens: u32) -> Self
Set the maximum output tokens used by stream_complete.
By default stream_complete uses the hard-coded MAX_TOKENS constant
(1024). Call this method to override that value, e.g. when a task
requires longer streamed responses.
Trait Implementations§
Source§impl LlmProvider for AnthropicProvider
impl LlmProvider for AnthropicProvider
Source§fn complete_with_options<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
options: CompletionOptions<'life2>,
) -> Pin<Box<dyn Future<Output = Result<String, AgentRuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn complete_with_options<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
options: CompletionOptions<'life2>,
) -> Pin<Box<dyn Future<Output = Result<String, AgentRuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Complete with per-request options (max_tokens, temperature).
Falls back to Self::MAX_TOKENS when options.max_tokens is not set.
Source§fn stream_complete<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
model: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Receiver<Result<String, AgentRuntimeError>>, AgentRuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn stream_complete<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
model: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Receiver<Result<String, AgentRuntimeError>>, AgentRuntimeError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Stream the completion token-by-token using chunk() for true streaming.
Uses response.chunk() to consume the SSE body incrementally so tokens
are emitted as they arrive rather than after the entire response has been
buffered, fixing the original bytes().await implementation.