pub struct ModelRequest {Show 15 fields
pub request_id: RequestId,
pub purpose: ModelPurpose,
pub messages: Vec<Message>,
pub system: Option<String>,
pub output: OutputSpec,
pub tools: Vec<ToolSpec>,
pub tool_choice: ToolChoice,
pub max_output_tokens: Option<u32>,
pub temperature: Option<f32>,
pub reasoning_effort: Option<ReasoningEffort>,
pub seed: Option<u64>,
pub stop: Vec<String>,
pub metadata: RequestMetadata,
pub timeout: Duration,
pub cache_hint: CacheHint,
}Expand description
One model call (spec §20.1).
Build it with ModelRequest::new and the with_* methods; every field is
public so an adapter can read it without ceremony.
Fields§
§request_id: RequestIdStable id of the logical call, unchanged across retries and fallbacks (spec §20.7).
purpose: ModelPurposeWhy the call is being made. Decides capability requirements and logging policy; adapters do not branch on it.
messages: Vec<Message>The conversation, oldest first.
system: Option<String>Framing instructions, hoisted out of messages because most providers
carry them in a dedicated field.
output: OutputSpecThe shape of the answer.
tools: Vec<ToolSpec>Read-only tools the model may call.
tool_choice: ToolChoiceHow free the model is to call them.
max_output_tokens: Option<u32>Cap on generated tokens.
temperature: Option<f32>Sampling temperature. None leaves the provider’s default in place.
reasoning_effort: Option<ReasoningEffort>How much a reasoning model may think. None leaves the provider’s default.
seed: Option<u64>Sampling seed, for providers that honour one.
stop: Vec<String>Stop sequences.
metadata: RequestMetadataNon-personal labels.
timeout: DurationDeadline for the whole call, including reading a streamed body.
cache_hint: CacheHintPrompt-caching hint.
Implementations§
Source§impl ModelRequest
impl ModelRequest
Sourcepub fn new(purpose: ModelPurpose) -> Self
pub fn new(purpose: ModelPurpose) -> Self
A free-text request for purpose with a fresh
RequestId and the DEFAULT_TIMEOUT.
Sourcepub fn with_request_id(self, request_id: RequestId) -> Self
pub fn with_request_id(self, request_id: RequestId) -> Self
Pins the request id, so a retry or a fallback reuses it.
Sourcepub fn with_system(self, system: impl Into<String>) -> Self
pub fn with_system(self, system: impl Into<String>) -> Self
Sets the system prompt.
Sourcepub fn with_message(self, message: Message) -> Self
pub fn with_message(self, message: Message) -> Self
Appends one message.
Sourcepub fn with_messages(self, messages: Vec<Message>) -> Self
pub fn with_messages(self, messages: Vec<Message>) -> Self
Replaces the conversation.
Sourcepub fn with_output(self, output: OutputSpec) -> Self
pub fn with_output(self, output: OutputSpec) -> Self
Sets the expected output shape.
Sourcepub fn with_tools(self, tools: Vec<ToolSpec>) -> Self
pub fn with_tools(self, tools: Vec<ToolSpec>) -> Self
Declares the read-only tools.
Sourcepub fn with_tool_choice(self, tool_choice: ToolChoice) -> Self
pub fn with_tool_choice(self, tool_choice: ToolChoice) -> Self
Sets the tool-choice mode.
Sourcepub fn with_max_output_tokens(self, tokens: u32) -> Self
pub fn with_max_output_tokens(self, tokens: u32) -> Self
Caps generated tokens.
Sourcepub fn with_temperature(self, temperature: f32) -> Self
pub fn with_temperature(self, temperature: f32) -> Self
Sets the sampling temperature.
Sourcepub fn sampling_for(&self, capabilities: &ProviderCapabilities) -> Sampling
pub fn sampling_for(&self, capabilities: &ProviderCapabilities) -> Sampling
The sampling parameters capabilities accepts, with the rest named as dropped.
Sourcepub fn with_reasoning_effort(self, effort: ReasoningEffort) -> Self
pub fn with_reasoning_effort(self, effort: ReasoningEffort) -> Self
Sets how much a reasoning model may think.
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Sets the deadline.
Sourcepub fn with_cache_hint(self, cache_hint: CacheHint) -> Self
pub fn with_cache_hint(self, cache_hint: CacheHint) -> Self
Sets the caching hint.
Sourcepub fn with_metadata(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Result<Self, MetadataError>
pub fn with_metadata( self, key: impl Into<String>, value: impl Into<String>, ) -> Result<Self, MetadataError>
Sourcepub fn requirements(&self) -> CapabilityRequirements
pub fn requirements(&self) -> CapabilityRequirements
The capability requirements this request implies on its own, before the purpose’s own requirements are folded in.
It asks for tools when tools are declared, vision when any message
carries an image, document input when any message carries a document,
and the structured-output transports the purpose accepts when
OutputSpec::Json is requested.