Skip to main content

CreateMessageRequestBuilder

Struct CreateMessageRequestBuilder 

Source
pub struct CreateMessageRequestBuilder { /* private fields */ }
Expand description

Builder for CreateMessageRequest.

Implementations§

Source§

impl CreateMessageRequestBuilder

Source

pub fn model(self, m: impl Into<ModelId>) -> Self

Set the model. Required.

Source

pub fn max_tokens(self, n: u32) -> Self

Set the max output tokens. Required.

Source

pub fn system(self, s: impl Into<SystemPrompt>) -> Self

Set the system prompt.

Source

pub fn messages(self, msgs: Vec<MessageInput>) -> Self

Replace the entire conversation history.

Source

pub fn user(self, content: impl Into<MessageContent>) -> Self

Append a user-authored message to the history.

Source

pub fn assistant(self, content: impl Into<MessageContent>) -> Self

Append an assistant-authored message (typically used for prefill).

Source

pub fn tools(self, tools: Vec<Tool>) -> Self

Set the available tools.

Source

pub fn tool_choice(self, choice: ToolChoice) -> Self

Set the tool-use policy.

Source

pub fn temperature(self, t: f32) -> Self

Set the sampling temperature.

Source

pub fn top_p(self, p: f32) -> Self

Set the nucleus sampling cutoff.

Source

pub fn top_k(self, k: u32) -> Self

Set the top-k sampling cutoff.

Source

pub fn stop_sequences(self, seqs: Vec<String>) -> Self

Set custom stop sequences.

Source

pub fn metadata(self, m: MessageMetadata) -> Self

Set request metadata (currently user_id only).

Source

pub fn service_tier(self, tier: RequestServiceTier) -> Self

Set the request-side service tier.

Source

pub fn thinking(self, t: ThinkingConfig) -> Self

Set the extended-thinking config.

Source

pub fn mcp_servers(self, servers: Vec<McpServerConfig>) -> Self

Set the MCP servers exposed on this request.

Source

pub fn container(self, id: impl Into<String>) -> Self

Set the container ID for the code-execution built-in tool.

Source

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 with cache_control: ephemeral.
  • Some(Blocks(_)) has cache_control: ephemeral set on the last text block.
  • None is a no-op.
Source

pub fn cache_system(self) -> Self

Shorter alias for Self::cache_control_on_system.

Source

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.

Source

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.

Source

pub fn cache_last_user(self) -> Self

Source

pub fn cache_last_user_with_ttl(self, ttl: impl Into<String>) -> Self

Like Self::cache_last_user but with an explicit TTL.

Source

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.

Source

pub fn cache_tools(self) -> Self

Shorter alias for Self::cache_control_on_tools.

Source

pub fn cache_tools_with_ttl(self, ttl: impl Into<String>) -> Self

Like Self::cache_tools but with an explicit TTL.

Source

pub fn build(self) -> Result<CreateMessageRequest>

Finalize the request.

§Errors

Returns Error::InvalidConfig if model or max_tokens was not set.

Trait Implementations§

Source§

impl Debug for CreateMessageRequestBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CreateMessageRequestBuilder

Source§

fn default() -> CreateMessageRequestBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more