pub struct ChatRequest {
pub model: String,
pub messages: Vec<ChatMessage>,
pub temperature: Option<f32>,
pub max_tokens: Option<u32>,
pub tools: Option<Vec<ToolDefinition>>,
pub tool_choice: Option<Value>,
pub stop: Option<Vec<String>>,
pub usage: Option<RequestUsageConfig>,
}Expand description
The full request body for a chat/completions call.
Why: every adapter accepts this one shape; provider-specific translation
(tool-choice dialect, usage directive) happens inside the adapter, not here.
What: model is the provider slug; messages is the conversation history;
the remaining fields are optional sampling/tool/stop knobs plus usage
(OpenRouter’s detailed-accounting opt-in). tool_choice is a raw Value
because its wire spelling is provider-dialect-specific (produced by
super::tool::openai_tool_choice or an adapter’s own mapper).
Test: minimal_request_omits_optionals, request_with_tools_and_stop_serialises.
Fields§
§model: StringProvider model slug, e.g. "anthropic/claude-sonnet-4-5".
messages: Vec<ChatMessage>Conversation history, including the new user turn.
temperature: Option<f32>Sampling temperature.
max_tokens: Option<u32>Maximum tokens to generate.
tools: Option<Vec<ToolDefinition>>Tools the model may call.
tool_choice: Option<Value>Tool-choice policy in the target provider’s wire dialect.
stop: Option<Vec<String>>Stop sequences that end generation.
usage: Option<RequestUsageConfig>OpenRouter detailed-usage directive; None (omitted) for every other
provider/path.
Implementations§
Source§impl ChatRequest
impl ChatRequest
Sourcepub fn new(model: impl Into<String>, messages: Vec<ChatMessage>) -> ChatRequest
pub fn new(model: impl Into<String>, messages: Vec<ChatMessage>) -> ChatRequest
Construct a minimal request from a model slug and message history.
Why: the overwhelming majority of call sites want “this model, these
messages, defaults for everything else”; a builder-free constructor keeps
them terse while the optional knobs stay directly assignable.
What: sets model and messages; every optional field starts None.
Test: minimal_request_omits_optionals.
Trait Implementations§
Source§impl Clone for ChatRequest
impl Clone for ChatRequest
Source§fn clone(&self) -> ChatRequest
fn clone(&self) -> ChatRequest
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ChatRequest
impl Debug for ChatRequest
Source§impl<'de> Deserialize<'de> for ChatRequest
impl<'de> Deserialize<'de> for ChatRequest
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ChatRequest, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ChatRequest, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for ChatRequest
impl Serialize for ChatRequest
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for ChatRequest
impl RefUnwindSafe for ChatRequest
impl Send for ChatRequest
impl Sync for ChatRequest
impl Unpin for ChatRequest
impl UnsafeUnpin for ChatRequest
impl UnwindSafe for ChatRequest
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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