pub struct ClientBuilder { /* private fields */ }
Expand description
Builder for creating Client
instances with fluent configuration
The ClientBuilder
provides a convenient way to construct client instances
using the builder pattern. All methods are chainable and return self
for
fluent composition.
§Examples
let client = Client::builder()
.model("claude-3-sonnet-20240229")
.system_prompt("You are a helpful assistant")
.stream_format(StreamFormat::Json)
.timeout_secs(60)
.build();
Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn config(self, config: Config) -> Self
pub fn config(self, config: Config) -> Self
Set the configuration directly
This allows you to use a pre-built Config
instance instead of
configuring individual options.
Sourcepub fn system_prompt(self, prompt: impl Into<String>) -> Self
pub fn system_prompt(self, prompt: impl Into<String>) -> Self
Set the system prompt for the assistant
§Examples
let client = Client::builder()
.system_prompt("You are a Rust expert")
.build();
Sourcepub fn model(self, model: impl Into<String>) -> Self
pub fn model(self, model: impl Into<String>) -> Self
Set the Claude model to use
§Examples
let client = Client::builder()
.model("claude-3-opus-20240229")
.build();
Sourcepub fn allowed_tools(self, tools: Vec<String>) -> Self
pub fn allowed_tools(self, tools: Vec<String>) -> Self
Set the list of allowed tools
§Examples
let client = Client::builder()
.allowed_tools(vec!["bash".to_string(), "filesystem".to_string()])
.build();
Sourcepub fn stream_format(self, format: StreamFormat) -> Self
pub fn stream_format(self, format: StreamFormat) -> Self
Set the output format for responses
§Examples
let client = Client::builder()
.stream_format(StreamFormat::Json)
.build();
Sourcepub fn timeout_secs(self, timeout_secs: u64) -> Self
pub fn timeout_secs(self, timeout_secs: u64) -> Self
Set the timeout in seconds
§Examples
let client = Client::builder()
.timeout_secs(120) // 2 minute timeout
.build();
Sourcepub fn continue_session(self) -> Self
pub fn continue_session(self) -> Self
Enable session continuation (–continue flag)
When enabled, the client will use the –continue flag to resume the most recent conversation session.
§Examples
let client = Client::builder()
.continue_session()
.build();
Sourcepub fn resume_session(self, session_id: impl Into<String>) -> Self
pub fn resume_session(self, session_id: impl Into<String>) -> Self
Resume a specific session by ID (–resume flag)
When set, the client will use the –resume flag with the specified session ID to continue a specific conversation session.
§Examples
let client = Client::builder()
.resume_session("session_123")
.build();
Sourcepub fn disallowed_tools(self, tools: Vec<String>) -> Self
pub fn disallowed_tools(self, tools: Vec<String>) -> Self
Set the list of disallowed tools
Controls which tools Claude cannot access during execution. Provides fine-grained control over tool restrictions.
§Examples
let client = Client::builder()
.disallowed_tools(vec!["bash".to_string(), "filesystem".to_string()])
.build();
Sourcepub fn skip_permissions(self, skip: bool) -> Self
pub fn skip_permissions(self, skip: bool) -> Self
Set whether to skip permission prompts (default: true)
When true
(default), adds the --dangerously-skip-permissions
flag
to bypass tool permission prompts. Set to false
for additional security.
§Examples
let client = Client::builder()
.skip_permissions(false) // Require permission prompts
.build();
Sourcepub fn append_system_prompt(self, prompt: impl Into<String>) -> Self
pub fn append_system_prompt(self, prompt: impl Into<String>) -> Self
Set an additional system prompt to append
When set, adds the --append-system-prompt
flag to extend the
existing system prompt. Cannot be used with system_prompt
.
§Examples
let client = Client::builder()
.append_system_prompt("Additionally, be concise in your responses.")
.build();
Sourcepub fn max_turns(self, turns: u32) -> Self
pub fn max_turns(self, turns: u32) -> Self
Set the maximum number of conversation turns
Limits the conversation to the specified number of back-and-forth exchanges. Useful for controlling conversation length.
§Examples
let client = Client::builder()
.max_turns(10)
.build();
Sourcepub fn security_level(self, level: SecurityLevel) -> Self
pub fn security_level(self, level: SecurityLevel) -> Self
Set the security validation level
Controls how strictly user input is validated for potential security threats.
§Examples
let client = Client::builder()
.security_level(SecurityLevel::Relaxed) // Allow more flexible input
.build();
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ClientBuilder
impl RefUnwindSafe for ClientBuilder
impl Send for ClientBuilder
impl Sync for ClientBuilder
impl Unpin for ClientBuilder
impl UnwindSafe for ClientBuilder
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> 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