pub struct Client { /* private fields */ }Expand description
Claude Messages API client.
Implementations§
Source§impl Client
impl Client
Sourcepub fn with_token(_token: impl Into<String>) -> Self
pub fn with_token(_token: impl Into<String>) -> Self
Create a new client with a single token (no pool/rotation).
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Create a client builder.
Sourcepub async fn message(
&self,
model: &str,
messages: &[Message],
max_tokens: u32,
) -> Result<MessagesResponse>
pub async fn message( &self, model: &str, messages: &[Message], max_tokens: u32, ) -> Result<MessagesResponse>
Send a Messages API request.
Sourcepub async fn message_with_system(
&self,
model: &str,
messages: &[Message],
max_tokens: u32,
system: Option<&str>,
) -> Result<MessagesResponse>
pub async fn message_with_system( &self, model: &str, messages: &[Message], max_tokens: u32, system: Option<&str>, ) -> Result<MessagesResponse>
Send a Messages API request with system prompt.
Sourcepub async fn message_with_tools(
&self,
model: &str,
messages: &[Message],
max_tokens: u32,
system: Option<&str>,
tools: Option<&[Tool]>,
) -> Result<MessagesResponse>
pub async fn message_with_tools( &self, model: &str, messages: &[Message], max_tokens: u32, system: Option<&str>, tools: Option<&[Tool]>, ) -> Result<MessagesResponse>
Send a Messages API request with system prompt and tools.
Sourcepub async fn run_agent_loop(
&self,
model: &str,
system: &str,
initial_message: &str,
tools: &[Tool],
max_turns: u32,
tool_handler: &dyn ToolHandler,
) -> Result<AgentLoopResult>
pub async fn run_agent_loop( &self, model: &str, system: &str, initial_message: &str, tools: &[Tool], max_turns: u32, tool_handler: &dyn ToolHandler, ) -> Result<AgentLoopResult>
Run an agent loop with tool use support.
This method sends the initial message, handles tool calls via the handler, and continues the conversation until Claude stops calling tools or max_turns is reached.
§Arguments
model: The model to use (e.g., “claude-sonnet-4-5”)system: System promptinitial_message: The user’s initial requesttools: Tool definitionsmax_turns: Maximum conversation turns (each turn = one API call)tool_handler: Handler for executing tools
§Returns
An AgentLoopResult with final text, total tokens, turns used, and tool calls.
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
Mutably borrows from an owned value. Read more