Skip to main content

ModelResponse

Struct ModelResponse 

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

Immutable, fully normalized result of one model attempt.

Deserialization enforces intrinsic resource, metadata, usage, and finish invariants, but serialized model/tool identities remain unauthenticated claims. Call Self::validate_for against the attempt’s immutable descriptor and request snapshot before consuming a durable or remote value. Adapter code should prefer Self::new, which performs both validation layers.

Implementations§

Source§

impl ModelResponse

Source

pub const MAX_CONTENT_ITEMS: usize = ModelOutputItems::MAX_CONTENT_ITEMS

Maximum user-visible content and reasoning-summary items in one response.

Source

pub const MAX_TOOL_CALLS: usize = ModelOutputItems::MAX_TOOL_CALLS

Maximum complete tool proposals in one response.

Source

pub const MAX_OUTPUT_ITEMS: usize = ModelOutputItems::MAX_ITEMS

Maximum total ordered output items in one response.

Source

pub const MAX_INLINE_PAYLOAD_BYTES: ByteCount = ModelOutputItems::MAX_INLINE_PAYLOAD_BYTES

Maximum aggregate normalized output plus opaque provider replay bytes.

Source

pub fn new<I>( provenance: ModelResponseProvenance, descriptor: &ModelDescriptor, request: &ModelRequest, output: I, finish_reason: ModelFinishReason, usage: ModelUsage, extensions: Extensions, ) -> Result<Self, ModelResponseError>
where I: IntoIterator<Item = ModelOutputItem>,

Constructs and binds one response to an immutable descriptor and request.

§Errors

Returns ModelResponseError for any structural, resource, finish, capability-identity, request-limit, output-format, modality, or tool mismatch. Referenced JSON Schemas still require trusted registry resolution and validation by the adapter before construction.

Source

pub fn with_provider_replay( self, provider_replay: ModelProviderReplay, ) -> Result<Self, ModelResponseError>

Attaches exact provider continuation evidence to a tool-calling response.

§Errors

Returns ModelResponseError::ProviderReplayWithoutToolCalls when the response does not require a tool-result continuation.

Source

pub fn validate_for( &self, descriptor: &ModelDescriptor, request: &ModelRequest, ) -> Result<(), ModelResponseError>

Revalidates request- and registry-dependent response invariants.

§Errors

Returns ModelResponseError when provenance, usage, output modality, reasoning summaries, final text format, or tool proposals do not match the exact descriptor and request snapshot.

Source

pub const fn provenance(&self) -> &ModelResponseProvenance

Returns attempt and model identity provenance.

Source

pub fn output(&self) -> &[ModelOutputItem]

Returns all output items in exact provider order.

Source

pub fn tool_calls(&self) -> impl Iterator<Item = &ModelToolCallProposal>

Iterates complete, unapproved tool-call proposals in provider order.

Source

pub const fn tool_call_count(&self) -> usize

Returns the exact number of complete, unapproved tool proposals.

Source

pub const fn finish_reason(&self) -> ModelFinishReason

Returns the normalized portable finish reason.

Source

pub const fn usage(&self) -> &ModelUsage

Returns normalized per-attempt token usage.

Source

pub const fn extensions(&self) -> &Extensions

Returns registered opaque provider/adapter extension values.

Source

pub const fn provider_replay(&self) -> Option<&ModelProviderReplay>

Returns exact provider continuation evidence for a tool-calling turn.

Source

pub fn inline_payload_bytes(&self) -> ByteCount

Returns aggregate normalized output and provider replay bytes retained.

Trait Implementations§

Source§

impl Clone for ModelResponse

Source§

fn clone(&self) -> Self

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 ModelResponse

Source§

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

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

impl<'de> Deserialize<'de> for ModelResponse

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 Eq for ModelResponse

Source§

impl JsonSchema for ModelResponse

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for ModelResponse

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ModelResponse

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

impl StructuralPartialEq for ModelResponse

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Output = T

Should always be Self
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.