pub struct CreateMessageRequestBuilder { /* private fields */ }Expand description
Builder for CreateMessageRequest.
Implementations§
Source§impl CreateMessageRequestBuilder
impl CreateMessageRequestBuilder
Sourcepub fn max_tokens(self, n: u32) -> Self
pub fn max_tokens(self, n: u32) -> Self
Set the max output tokens. Required.
Sourcepub fn system(self, s: impl Into<SystemPrompt>) -> Self
pub fn system(self, s: impl Into<SystemPrompt>) -> Self
Set the system prompt.
Sourcepub fn messages(self, msgs: Vec<MessageInput>) -> Self
pub fn messages(self, msgs: Vec<MessageInput>) -> Self
Replace the entire conversation history.
Sourcepub fn user(self, content: impl Into<MessageContent>) -> Self
pub fn user(self, content: impl Into<MessageContent>) -> Self
Append a user-authored message to the history.
Sourcepub fn assistant(self, content: impl Into<MessageContent>) -> Self
pub fn assistant(self, content: impl Into<MessageContent>) -> Self
Append an assistant-authored message (typically used for prefill).
Sourcepub fn tool_choice(self, choice: ToolChoice) -> Self
pub fn tool_choice(self, choice: ToolChoice) -> Self
Set the tool-use policy.
Sourcepub fn temperature(self, t: f32) -> Self
pub fn temperature(self, t: f32) -> Self
Set the sampling temperature.
Sourcepub fn stop_sequences(self, seqs: Vec<String>) -> Self
pub fn stop_sequences(self, seqs: Vec<String>) -> Self
Set custom stop sequences.
Sourcepub fn metadata(self, m: MessageMetadata) -> Self
pub fn metadata(self, m: MessageMetadata) -> Self
Set request metadata (currently user_id only).
Sourcepub fn service_tier(self, tier: RequestServiceTier) -> Self
pub fn service_tier(self, tier: RequestServiceTier) -> Self
Set the request-side service tier.
Sourcepub fn thinking(self, t: ThinkingConfig) -> Self
pub fn thinking(self, t: ThinkingConfig) -> Self
Set the extended-thinking config.
Sourcepub fn mcp_servers(self, servers: Vec<McpServerConfig>) -> Self
pub fn mcp_servers(self, servers: Vec<McpServerConfig>) -> Self
Set the MCP servers exposed on this request.
Sourcepub fn container(self, id: impl Into<String>) -> Self
pub fn container(self, id: impl Into<String>) -> Self
Set the container ID for the code-execution built-in tool.
Sourcepub fn cache_control_on_system(self) -> Self
pub fn cache_control_on_system(self) -> Self
Sugar: apply an ephemeral cache breakpoint at the end of the system prompt.
Some(Text(s))becomes a single text block withcache_control: ephemeral.Some(Blocks(_))hascache_control: ephemeralset on the last text block.Noneis a no-op.
Sourcepub fn cache_system(self) -> Self
pub fn cache_system(self) -> Self
Shorter alias for Self::cache_control_on_system.
Sourcepub fn cache_system_with_ttl(self, ttl: impl Into<String>) -> Self
pub fn cache_system_with_ttl(self, ttl: impl Into<String>) -> Self
Like Self::cache_system but with an explicit TTL ("5m",
"1h"). The "1h" form requires the
extended-cache-ttl-2025-04-11 beta header.
Sourcepub fn cache_control_on_last_user(self) -> Self
pub fn cache_control_on_last_user(self) -> Self
Sugar: apply an ephemeral cache breakpoint to the last user-authored message in the history.
String content is converted to a single text block carrying
cache_control: ephemeral. Block content has cache_control set on
the last block that supports it (text, image, document, tool_result).
No-op if there are no user-authored messages.
Sourcepub fn cache_last_user(self) -> Self
pub fn cache_last_user(self) -> Self
Shorter alias for Self::cache_control_on_last_user.
Sourcepub fn cache_last_user_with_ttl(self, ttl: impl Into<String>) -> Self
pub fn cache_last_user_with_ttl(self, ttl: impl Into<String>) -> Self
Like Self::cache_last_user but with an explicit TTL.
Sourcepub fn cache_control_on_tools(self) -> Self
pub fn cache_control_on_tools(self) -> Self
Sugar: apply an ephemeral cache breakpoint to the last tool definition. The server caches all tool definitions up to that point; useful when the same tool list is reused across many requests. No-op if no tools are configured.
Sourcepub fn cache_tools(self) -> Self
pub fn cache_tools(self) -> Self
Shorter alias for Self::cache_control_on_tools.
Sourcepub fn cache_tools_with_ttl(self, ttl: impl Into<String>) -> Self
pub fn cache_tools_with_ttl(self, ttl: impl Into<String>) -> Self
Like Self::cache_tools but with an explicit TTL.
Sourcepub fn build(self) -> Result<CreateMessageRequest>
pub fn build(self) -> Result<CreateMessageRequest>
Trait Implementations§
Source§impl Debug for CreateMessageRequestBuilder
impl Debug for CreateMessageRequestBuilder
Source§impl Default for CreateMessageRequestBuilder
impl Default for CreateMessageRequestBuilder
Source§fn default() -> CreateMessageRequestBuilder
fn default() -> CreateMessageRequestBuilder
Auto Trait Implementations§
impl Freeze for CreateMessageRequestBuilder
impl RefUnwindSafe for CreateMessageRequestBuilder
impl Send for CreateMessageRequestBuilder
impl Sync for CreateMessageRequestBuilder
impl Unpin for CreateMessageRequestBuilder
impl UnsafeUnpin for CreateMessageRequestBuilder
impl UnwindSafe for CreateMessageRequestBuilder
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