pub struct AnthropicClient { /* private fields */ }Expand description
An Anthropic (Claude) Messages API chat client.
Implementations§
Source§impl AnthropicClient
impl AnthropicClient
Sourcepub fn new(api_key: impl Into<String>, model: impl Into<String>) -> Self
pub fn new(api_key: impl Into<String>, model: impl Into<String>) -> Self
Create a client for the given API key and default model.
Sourcepub fn from_env(model: impl Into<String>) -> Result<Self>
pub fn from_env(model: impl Into<String>) -> Result<Self>
Build a client from the ANTHROPIC_API_KEY (and optional
ANTHROPIC_BASE_URL) environment variables.
Sourcepub fn with_base_url(self, base_url: impl Into<String>) -> Self
pub fn with_base_url(self, base_url: impl Into<String>) -> Self
Override the base URL (for proxies or private deployments).
Sourcepub fn with_max_tokens(self, max_tokens: u32) -> Self
pub fn with_max_tokens(self, max_tokens: u32) -> Self
Override the default max_tokens sent when ChatOptions::max_tokens
is unset (the Anthropic API requires this field on every request).
Sourcepub fn with_default_options(self, options: ChatOptions) -> Self
pub fn with_default_options(self, options: ChatOptions) -> Self
Set default ChatOptions applied as a base under any options passed
per-request (per-request options take precedence; see
ChatOptions::merge).
Sourcepub fn with_additional_beta_flags(
self,
flags: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_additional_beta_flags( self, flags: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Additional anthropic-beta flags to send (via the anthropic-beta
header) on every request, unioned with the always-on
convert::DEFAULT_BETA_FLAGS and any per-request flags supplied
through ChatOptions::additional_properties["additional_beta_flags"].
Mirrors upstream’s additional_beta_flags constructor keyword
argument (_chat_client.py ~126, ~139-140): “Default flags are:
mcp-client-2025-04-04, code-execution-2025-08-25.”
Trait Implementations§
Source§impl ChatClient for AnthropicClient
impl ChatClient for AnthropicClient
Source§fn get_response<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
options: ChatOptions,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_response<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
options: ChatOptions,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn get_streaming_response<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
options: ChatOptions,
) -> Pin<Box<dyn Future<Output = Result<ChatStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_streaming_response<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
options: ChatOptions,
) -> Pin<Box<dyn Future<Output = Result<ChatStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§impl Clone for AnthropicClient
impl Clone for AnthropicClient
Source§fn clone(&self) -> AnthropicClient
fn clone(&self) -> AnthropicClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more