pub struct MessageRequestBuilder<'a> { /* private fields */ }Expand description
Fluent builder for Claude API message requests.
Created via ClaudeClient::messages(). Chain methods to configure,
then call .send() for the full response or .stream() for SSE events.
Implementations§
Source§impl<'a> MessageRequestBuilder<'a>
impl<'a> MessageRequestBuilder<'a>
Sourcepub fn system_cached(self, text: &str) -> Self
pub fn system_cached(self, text: &str) -> Self
Set the system prompt with prompt caching enabled
Sourcepub fn user_with_image_base64(
self,
text: &str,
media_type: &str,
base64_data: &str,
) -> Self
pub fn user_with_image_base64( self, text: &str, media_type: &str, base64_data: &str, ) -> Self
Add a user message with an image (base64 encoded)
Sourcepub fn user_with_image_url(self, text: &str, url: &str) -> Self
pub fn user_with_image_url(self, text: &str, url: &str) -> Self
Add a user message with an image URL
Sourcepub fn assistant(self, text: &str) -> Self
pub fn assistant(self, text: &str) -> Self
Add an assistant text message (for multi-turn conversations)
Sourcepub fn messages(self, msgs: Vec<Message>) -> Self
pub fn messages(self, msgs: Vec<Message>) -> Self
Set the full message list (for agentic loops where you manage messages)
Sourcepub fn tool_results(self, results: Vec<ContentBlock>) -> Self
pub fn tool_results(self, results: Vec<ContentBlock>) -> Self
Add tool results as a user message (for the agentic tool loop)
Sourcepub fn thinking_adaptive(self) -> Self
pub fn thinking_adaptive(self) -> Self
Enable adaptive thinking (recommended for Opus 4.6 / Sonnet 4.6). Claude dynamically decides when and how much to think.
Sourcepub fn thinking_enabled(self, budget_tokens: usize) -> Self
pub fn thinking_enabled(self, budget_tokens: usize) -> Self
Enable thinking with a fixed token budget (older models only).
budget_tokens must be less than max_tokens (minimum 1024).
Sourcepub fn thinking_disabled(self) -> Self
pub fn thinking_disabled(self) -> Self
Explicitly disable thinking
Sourcepub fn effort(self, level: &str) -> Self
pub fn effort(self, level: &str) -> Self
Set the effort level: “low”, “medium”, “high” (default), or “max” (Opus only). Lower effort = cheaper/faster. Higher effort = deeper reasoning.
Sourcepub fn tool_choice_auto(self) -> Self
pub fn tool_choice_auto(self) -> Self
Let Claude decide whether to use tools (default)
Sourcepub fn tool_choice_any(self) -> Self
pub fn tool_choice_any(self) -> Self
Force Claude to use at least one tool
Sourcepub fn tool_choice_specific(self, name: &str) -> Self
pub fn tool_choice_specific(self, name: &str) -> Self
Force Claude to use a specific tool by name
Sourcepub fn tool_choice_none(self) -> Self
pub fn tool_choice_none(self) -> Self
Prevent Claude from using any tools
Sourcepub fn json_schema(self, schema: Value) -> Self
pub fn json_schema(self, schema: Value) -> Self
Constrain the response to match a JSON schema
Sourcepub fn max_tokens(self, n: usize) -> Self
pub fn max_tokens(self, n: usize) -> Self
Maximum tokens to generate (default: 4096)
Sourcepub fn temperature(self, t: f32) -> Self
pub fn temperature(self, t: f32) -> Self
Sampling temperature (0.0 = deterministic, 1.0 = creative)
Sourcepub fn stop_sequences(self, seqs: Vec<String>) -> Self
pub fn stop_sequences(self, seqs: Vec<String>) -> Self
Custom stop sequences
Sourcepub fn beta(self, header: &str) -> Self
pub fn beta(self, header: &str) -> Self
Enable a beta feature by header string (e.g. “compact-2026-01-12”)
Sourcepub fn build(self) -> MessagesRequest
pub fn build(self) -> MessagesRequest
Build the request without sending (useful for inspection/testing)
Sourcepub async fn send(&self) -> Result<MessagesResponse, ClaudeApiError>
pub async fn send(&self) -> Result<MessagesResponse, ClaudeApiError>
Send the request and return the full response (non-streaming).
Sourcepub async fn stream(&self) -> Result<SseParser, ClaudeApiError>
pub async fn stream(&self) -> Result<SseParser, ClaudeApiError>
Send the request with streaming, returning an SSE event parser.
Use parser.next_event() to consume events one at a time.
Auto Trait Implementations§
impl<'a> Freeze for MessageRequestBuilder<'a>
impl<'a> !RefUnwindSafe for MessageRequestBuilder<'a>
impl<'a> Send for MessageRequestBuilder<'a>
impl<'a> Sync for MessageRequestBuilder<'a>
impl<'a> Unpin for MessageRequestBuilder<'a>
impl<'a> UnsafeUnpin for MessageRequestBuilder<'a>
impl<'a> !UnwindSafe for MessageRequestBuilder<'a>
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for 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