Skip to main content

CreateMessagesRequest

Struct CreateMessagesRequest 

Source
pub struct CreateMessagesRequest {
Show 14 fields pub max_tokens: i64, pub messages: Vec<MessagesMessage>, pub metadata: Option<MessagesMetadata>, pub model: String, pub output_config: Option<MessagesOutputConfig>, pub stop_sequences: Vec<String>, pub stream: bool, pub system: Option<CreateMessagesRequestSystem>, pub temperature: Option<f32>, pub thinking: Option<CreateMessagesRequestThinking>, pub tool_choice: Option<MessagesToolChoice>, pub tools: Vec<MessagesTool>, pub top_k: Option<i64>, pub top_p: Option<f32>,
}
Expand description

Request body for creating a message via the Anthropic-compatible Messages API.

JSON schema
{
 "description": "Request body for creating a message via the Anthropic-compatible\nMessages API.\n",
 "type": "object",
 "required": [
   "max_tokens",
   "messages",
   "model"
 ],
 "properties": {
   "max_tokens": {
     "description": "The maximum number of tokens to generate before stopping.\n",
     "type": "integer"
   },
   "messages": {
     "description": "The messages to generate a response for. Each message has a\n`role` (user or assistant) and `content`.\n",
     "type": "array",
     "items": {
       "$ref": "#/definitions/MessagesMessage"
     }
   },
   "metadata": {
     "$ref": "#/definitions/MessagesMetadata"
   },
   "model": {
     "description": "The model to use for generating the message.",
     "type": "string"
   },
   "output_config": {
     "$ref": "#/definitions/MessagesOutputConfig"
   },
   "stop_sequences": {
     "description": "Custom text sequences that will cause the model to stop\ngenerating.\n",
     "type": "array",
     "items": {
       "type": "string"
     }
   },
   "stream": {
     "description": "Whether to stream the response using server-sent events.\n",
     "default": false,
     "type": "boolean"
   },
   "system": {
     "description": "The system prompt. Can be a string or an array of system content\nblocks (for prompt caching).\n",
     "oneOf": [
       {
         "description": "System prompt as a string.",
         "type": "string"
       },
       {
         "type": "array",
         "items": {
           "$ref": "#/definitions/MessagesTextBlock"
         }
       }
     ]
   },
   "temperature": {
     "description": "Amount of randomness injected into the response. Ranges from\n0.0 to 1.0. Use closer to 0 for analytical / multiple choice,\ncloser to 1 for creative and generative tasks.\n",
     "type": "number",
     "format": "float"
   },
   "thinking": {
     "description": "Configuration for extended thinking.\n",
     "type": "object",
     "required": [
       "budget_tokens",
       "type"
     ],
     "properties": {
       "budget_tokens": {
         "description": "The maximum number of tokens the model is allowed to use\nfor thinking.\n",
         "type": "integer"
       },
       "type": {
         "description": "Always `enabled`.",
         "type": "string",
         "enum": [
           "enabled"
         ]
       }
     }
   },
   "tool_choice": {
     "$ref": "#/definitions/MessagesToolChoice"
   },
   "tools": {
     "description": "Definitions of tools the model may call. Each tool can include\n`cache_control` for prompt caching.\n",
     "type": "array",
     "items": {
       "$ref": "#/definitions/MessagesTool"
     }
   },
   "top_k": {
     "description": "Only sample from the top K options for each subsequent token.\n",
     "type": "integer"
   },
   "top_p": {
     "description": "Use nucleus sampling. Only consider the tokens with top_p\nprobability mass.\n",
     "type": "number",
     "format": "float"
   }
 }
}

Fields§

§max_tokens: i64

The maximum number of tokens to generate before stopping.

§messages: Vec<MessagesMessage>

The messages to generate a response for. Each message has a role (user or assistant) and content.

§metadata: Option<MessagesMetadata>§model: String

The model to use for generating the message.

§output_config: Option<MessagesOutputConfig>§stop_sequences: Vec<String>

Custom text sequences that will cause the model to stop generating.

§stream: bool

Whether to stream the response using server-sent events.

§system: Option<CreateMessagesRequestSystem>

The system prompt. Can be a string or an array of system content blocks (for prompt caching).

§temperature: Option<f32>

Amount of randomness injected into the response. Ranges from 0.0 to 1.0. Use closer to 0 for analytical / multiple choice, closer to 1 for creative and generative tasks.

§thinking: Option<CreateMessagesRequestThinking>§tool_choice: Option<MessagesToolChoice>§tools: Vec<MessagesTool>

Definitions of tools the model may call. Each tool can include cache_control for prompt caching.

§top_k: Option<i64>

Only sample from the top K options for each subsequent token.

§top_p: Option<f32>

Use nucleus sampling. Only consider the tokens with top_p probability mass.

Trait Implementations§

Source§

impl Clone for CreateMessagesRequest

Source§

fn clone(&self) -> CreateMessagesRequest

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CreateMessagesRequest

Source§

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

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

impl<'de> Deserialize<'de> for CreateMessagesRequest

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for CreateMessagesRequest

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

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> MaybeSendSync for T

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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