pub struct AnthropicClient { /* private fields */ }Expand description
Client for the Anthropic Messages API.
Prompt caching is on by default: the client marks the tool list, the system prompt, and the newest message as cache breakpoints, so each loop step and each scheduled run re-reads the stable prefix from the cache.
Implementations§
Source§impl AnthropicClient
impl AnthropicClient
Sourcepub const API_VERSION: &'static str = "2023-06-01"
pub const API_VERSION: &'static str = "2023-06-01"
Anthropic API version header sent with every request.
Sourcepub fn new(
base_url: impl Into<String>,
model: impl Into<String>,
api_key: impl Into<String>,
) -> Result<Self, AgentError>
pub fn new( base_url: impl Into<String>, model: impl Into<String>, api_key: impl Into<String>, ) -> Result<Self, AgentError>
Build a client. The key never leaves this struct except as a header.
§Errors
Returns AgentError when the underlying HTTP client cannot be built.
Sourcepub fn with_timeout(self, timeout: Duration) -> Result<Self, AgentError>
pub fn with_timeout(self, timeout: Duration) -> Result<Self, AgentError>
Replace the request timeout.
§Errors
Returns AgentError when the underlying HTTP client cannot be rebuilt.
Sourcepub const fn with_prompt_caching(self, enabled: bool) -> Self
pub const fn with_prompt_caching(self, enabled: bool) -> Self
Turn the cache_control breakpoints on or off.
Sourcepub fn messages_url(&self) -> String
pub fn messages_url(&self) -> String
Messages endpoint URL.
Trait Implementations§
Source§impl Debug for AnthropicClient
impl Debug for AnthropicClient
Source§impl LlmClient for AnthropicClient
impl LlmClient for AnthropicClient
Source§fn chat<'a>(
&'a self,
request: &'a ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse, AgentError>> + Send + 'a>>
fn chat<'a>( &'a self, request: &'a ChatRequest, ) -> Pin<Box<dyn Future<Output = Result<ChatResponse, AgentError>> + Send + 'a>>
Send one chat request and decode the response.
Source§fn list_models(
&self,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, AgentError>> + Send + '_>>
fn list_models( &self, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, AgentError>> + Send + '_>>
List available model ids. Cheap and read-only: the health check uses it.
Source§fn provider_name(&self) -> &'static str
fn provider_name(&self) -> &'static str
Human-readable provider name for logs and health details.
Auto Trait Implementations§
impl !RefUnwindSafe for AnthropicClient
impl !UnwindSafe for AnthropicClient
impl Forget for AnthropicClient
impl Freeze for AnthropicClient
impl Send for AnthropicClient
impl Sync for AnthropicClient
impl Unpin for AnthropicClient
impl UnsafeUnpin for AnthropicClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Scoped for T
impl<T> Scoped for T
Source§fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
Open a deferred
ScopeQuery for this type. Resolves the
registered scope at .load() time, not here.