pub struct Client { /* private fields */ }async only.Expand description
HTTP client for the Anthropic API.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(api_key: impl Into<String>) -> Self
pub fn new(api_key: impl Into<String>) -> Self
Construct a Client with default settings and the given API key.
§Panics
Panics if reqwest fails to build its default HTTP client (extremely
unusual; would indicate a broken TLS stack). Use Client::builder
for a fallible alternative.
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Begin configuring a Client.
Sourcepub fn managed_agents(&self) -> ManagedAgents<'_>
Available on crate feature managed-agents-preview only.
pub fn managed_agents(&self) -> ManagedAgents<'_>
managed-agents-preview only.Namespace handle for the Managed Agents API (preview).
Gated on the managed-agents-preview feature.
Sourcepub fn admin(&self) -> Admin<'_>
Available on crate feature admin only.
pub fn admin(&self) -> Admin<'_>
admin only.Namespace handle for the Admin API. Requires an admin API key.
Gated on the admin feature.
Sourcepub fn skills(&self) -> Skills<'_>
Available on crate feature skills only.
pub fn skills(&self) -> Skills<'_>
skills only.Namespace handle for the Skills API (beta).
Gated on the skills feature.
Sourcepub fn user_profiles(&self) -> UserProfiles<'_>
Available on crate feature user-profiles only.
pub fn user_profiles(&self) -> UserProfiles<'_>
user-profiles only.Namespace handle for the User Profiles API (beta).
Gated on the user-profiles feature.
Source§impl Client
impl Client
Sourcepub async fn run(
&self,
conversation: &mut Conversation,
registry: &ToolRegistry,
options: RunOptions,
) -> Result<Message>
Available on crate feature conversation only.
pub async fn run( &self, conversation: &mut Conversation, registry: &ToolRegistry, options: RunOptions, ) -> Result<Message>
conversation only.Drive a multi-turn agent loop against this client.
Each iteration:
- Builds a
CreateMessageRequestfromconversation, overriding itstoolsfield withregistry.to_messages_tools(). - Sends it (retries handled by the client’s configured retry policy).
- Records the response’s
Usageon the conversation. - Appends the assistant’s full response (text +
tool_useblocks) to the conversation history. - If
stop_reason != ToolUse, returns the response. - Otherwise dispatches each
tool_useblock viaregistry, builds matchingtool_resultblocks (withis_error = truefor failures), appends them as a user turn, and loops.
Returns Error::MaxIterationsExceeded if the loop hits
options.max_iterations without the model terminating. Tool
execution errors do not propagate; they are surfaced back to
the model as is_error = true tool results so it can recover.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin for Client
impl !UnwindSafe for Client
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more