pub struct AnthropicProvider { /* private fields */ }anthropic only.Expand description
Anthropic LLM provider using the Messages API.
Implementations§
Source§impl AnthropicProvider
impl AnthropicProvider
Sourcepub const API_KEY_ENV: &'static str = "ANTHROPIC_API_KEY"
pub const API_KEY_ENV: &'static str = "ANTHROPIC_API_KEY"
The conventional environment variable holding the Anthropic API key.
Sourcepub fn new(
api_key: impl Into<String>,
model: impl Into<String>,
) -> AnthropicProvider
pub fn new( api_key: impl Into<String>, model: impl Into<String>, ) -> AnthropicProvider
Create a new Anthropic provider with the specified API key and model.
Automatically detects OAuth tokens (sk-ant-oat-*) and switches to
Bearer auth with Claude Code identity headers.
Sourcepub const fn is_oauth(&self) -> bool
pub const fn is_oauth(&self) -> bool
Returns whether this provider is using OAuth authentication.
Sourcepub fn from_env() -> AnthropicProvider
pub fn from_env() -> AnthropicProvider
Create a provider using Claude Sonnet, reading the API key from the
conventional ANTHROPIC_API_KEY environment
variable.
This is the zero-ceremony on-ramp for the quickstart. Use
try_from_env if you want to handle a missing
key without a panic.
§Panics
Panics if ANTHROPIC_API_KEY is not set. Prefer
try_from_env outside of examples/tests.
Sourcepub fn try_from_env() -> Result<AnthropicProvider, Error>
pub fn try_from_env() -> Result<AnthropicProvider, Error>
Create a provider using Claude Sonnet, reading the API key from the
conventional ANTHROPIC_API_KEY environment
variable.
§Errors
Returns an error if ANTHROPIC_API_KEY is unset or not valid UTF-8.
Sourcepub fn haiku(api_key: impl Into<String>) -> AnthropicProvider
pub fn haiku(api_key: impl Into<String>) -> AnthropicProvider
Create a provider using Claude Haiku 4.5.
Sourcepub fn sonnet(api_key: impl Into<String>) -> AnthropicProvider
pub fn sonnet(api_key: impl Into<String>) -> AnthropicProvider
Create a provider using Claude Sonnet 4.6.
Sourcepub fn sonnet_45(api_key: impl Into<String>) -> AnthropicProvider
pub fn sonnet_45(api_key: impl Into<String>) -> AnthropicProvider
Create a provider using Claude Sonnet 4.5.
Sourcepub fn sonnet_46(api_key: impl Into<String>) -> AnthropicProvider
pub fn sonnet_46(api_key: impl Into<String>) -> AnthropicProvider
Create a provider using Claude Sonnet 4.6.
Sourcepub fn opus(api_key: impl Into<String>) -> AnthropicProvider
pub fn opus(api_key: impl Into<String>) -> AnthropicProvider
Create a provider using Claude Opus 4.6.
Sourcepub fn opus_47(api_key: impl Into<String>) -> AnthropicProvider
pub fn opus_47(api_key: impl Into<String>) -> AnthropicProvider
Create a provider using Claude Opus 4.7.
Note: Opus 4.7 requires adaptive thinking. Passing a
ThinkingConfig with ThinkingMode::Enabled { budget_tokens }
will return an InvalidRequest — use ThinkingConfig::adaptive()
or ThinkingConfig::adaptive_with_effort(_) instead.
Sourcepub fn opus_48(api_key: impl Into<String>) -> AnthropicProvider
pub fn opus_48(api_key: impl Into<String>) -> AnthropicProvider
Create a provider using Claude Opus 4.8.
Note: Opus 4.8 requires adaptive thinking. Passing a
ThinkingConfig with ThinkingMode::Enabled { budget_tokens }
will return an InvalidRequest — use ThinkingConfig::adaptive()
or ThinkingConfig::adaptive_with_effort(_) instead.
Sourcepub fn fable(api_key: impl Into<String>) -> AnthropicProvider
pub fn fable(api_key: impl Into<String>) -> AnthropicProvider
Create a provider using Claude Fable 5.
Note: Fable 5 is adaptive-only — the API applies adaptive thinking
even when no thinking config is sent, and raw chain of thought is
never returned (thinking blocks arrive with empty content). Passing a
ThinkingConfig with ThinkingMode::Enabled { budget_tokens }
will return an InvalidRequest — use ThinkingConfig::adaptive()
or ThinkingConfig::adaptive_with_effort(_) instead.
Sourcepub const fn with_thinking(self, thinking: ThinkingConfig) -> AnthropicProvider
pub const fn with_thinking(self, thinking: ThinkingConfig) -> AnthropicProvider
Set the provider-owned thinking configuration for this model.
Sourcepub fn with_base_url(self, base_url: impl Into<String>) -> AnthropicProvider
pub fn with_base_url(self, base_url: impl Into<String>) -> AnthropicProvider
Override the base URL (default: https://api.anthropic.com).
Sourcepub fn with_extra_headers(
self,
headers: Vec<(String, String)>,
) -> AnthropicProvider
pub fn with_extra_headers( self, headers: Vec<(String, String)>, ) -> AnthropicProvider
Add extra HTTP headers applied to every request.
Trait Implementations§
Source§impl Clone for AnthropicProvider
impl Clone for AnthropicProvider
Source§fn clone(&self) -> AnthropicProvider
fn clone(&self) -> AnthropicProvider
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl LlmProvider for AnthropicProvider
impl LlmProvider for AnthropicProvider
Source§fn chat<'life0, 'async_trait>(
&'life0 self,
request: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatOutcome, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
AnthropicProvider: 'async_trait,
fn chat<'life0, 'async_trait>(
&'life0 self,
request: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatOutcome, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
AnthropicProvider: 'async_trait,
Source§fn chat_stream(
&self,
request: ChatRequest,
) -> Pin<Box<dyn Stream<Item = Result<StreamDelta, Error>> + Send + '_>>
fn chat_stream( &self, request: ChatRequest, ) -> Pin<Box<dyn Stream<Item = Result<StreamDelta, Error>> + Send + '_>>
Source§fn validate_thinking_config(
&self,
thinking: Option<&ThinkingConfig>,
) -> Result<(), Error>
fn validate_thinking_config( &self, thinking: Option<&ThinkingConfig>, ) -> Result<(), Error>
fn model(&self) -> &str
fn provider(&self) -> &'static str
Source§fn configured_thinking(&self) -> Option<&ThinkingConfig>
fn configured_thinking(&self) -> Option<&ThinkingConfig>
Source§fn default_max_tokens(&self) -> u32
fn default_max_tokens(&self) -> u32
AgentConfig.max_tokens.Source§fn capabilities(&self) -> Option<&'static ModelCapabilities>
fn capabilities(&self) -> Option<&'static ModelCapabilities>
Source§fn resolve_thinking_config(
&self,
request_thinking: Option<&ThinkingConfig>,
) -> Result<Option<ThinkingConfig>, Error>
fn resolve_thinking_config( &self, request_thinking: Option<&ThinkingConfig>, ) -> Result<Option<ThinkingConfig>, Error>
Source§fn structured_output_support(&self) -> StructuredOutputSupport
fn structured_output_support(&self) -> StructuredOutputSupport
ResponseFormat) request. Read more