Skip to main content

Module message

Module message 

Source

Structs§

AdditionalParams
Nonempty JSON object of provider-specific content metadata, serialized as an object under a named additional_params field rather than flattened. Constructors return None for empty maps. Bare deserialization rejects empty or non-object values; optional_additional_params maps null and empty objects to absence. Providers must replay only their own metadata.
Audio
Audio content containing audio data and metadata about it.
Document
Document content containing document data and metadata about it.
EmptyCallId
A provider call id was empty.
EmptyToolName
A tool name was empty.
Image
Image content containing image data and metadata about it.
Issuer
The service that issued reasoning: the descriptor name of the wire that decoded it ("anthropic"), or the model vendor where a gateway relays several ("openrouter/openai").
LocalCallId
A call id rig issued: a random (v4) UUID.
ProviderCallId
Provider-issued identifiers for replay. Single-id protocols use call_id; dual-id protocols also use item_id. Keep each identifier in its protocol slot.
Reasoning
Assistant reasoning payload with an optional provider-supplied identifier. A message carries it Sealed to the service that issued it: signatures, encrypted and redacted payloads and reasoning ids only mean something there.
Sealed
A value only its issuer may read: reasoning, whose signatures, encrypted payloads and ids mean something only to the service that produced them.
Text
Text with optional provider metadata under the named additional_params key. Unknown sibling fields are ignored on decode, not captured for replay.
ToolCall
Describes a tool call with an id and function to call, generally produced by a provider.
ToolFunction
Describes a tool function to call with a name and arguments, generally produced by a provider.
ToolName
A tool name, never empty.
ToolResult
The result of a tool call, sent back to the model.
Video
Video content containing video data and metadata about it.

Enums§

AssistantContent
Assistant text, tool calls, reasoning, or images. Deserialization requires the lowercase type tag.
AudioMediaType
Describes the audio media type of the content. Not every provider supports every media type. Convertible to and from MIME type strings.
CallId
A tool call’s one identity: the id the provider issued, or one rig issued because the provider sent none.
ContentFormat
Content representation as base64, text, or a URL.
DocumentMediaType
Describes the document media type of the content. Not every provider supports every media type. Includes also programming languages as document types for providers who support code running. Convertible to and from MIME type strings.
DocumentSourceKind
The kind of image source (to be used).
ImageDetail
Describes the detail of the image content, which can be low, high, or auto (open-ai specific).
ImageMediaType
Describes the image media type of the content. Not every provider supports every media type. Convertible to and from MIME type strings.
MediaType
Helper enum that tracks the media type of the content.
Message
A provider-agnostic chat message.
MessageError
Error type to represent issues with converting messages to and from specific provider messages.
ReasoningContent
A typed reasoning block used by providers that emit structured thinking data.
ToolChoice
ToolResultContent
Describes one typed item in a tool result.
UserContent
User text, tool results, or media. Supported source kinds and media types depend on the target provider.
VideoMediaType
Describes the video media type of the content. Not every provider supports every media type. Convertible to and from MIME type strings.

Constants§

EMPTY_RESPONSE_ERROR
Shared error text for an invalid empty response choice. Provider decoders must exempt legal empty outcomes, including recognized output truncation, before calling require_non_empty_response.

Traits§

MimeType
Trait for converting between MIME types and media types.

Functions§

canonical_streamed_choice
Groups streamed choices as reasoning, text, tool calls, then images, preserving order within each group. Choices without reasoning or tool calls retain their original order.
keys_lost_in_round_trip
Returns dot-separated paths whose original values are missing or changed after a round trip. Ignores added keys, null object members, and missing object members whose original value was an empty object. Array positions are compared individually.
non_empty
Returns None for an empty list or Some(items) otherwise. Individual items are not inspected.
optional_additional_params
Deserializes optional metadata, mapping null and empty objects to None. Nonempty objects produce metadata; other shapes return a deserialization error.
ordered_assistant_content
Concatenates reasoning, text, and trailing content in that order without dropping items. Each group’s input order is preserved.
require_non_empty
Returns items unchanged unless the list is empty, then calls error once. Does not inspect individual items: empty text can carry replay signatures. Request conversions that discard content must validate the converted list when their wire requires at least one block.
require_non_empty_response
Returns a response error using EMPTY_RESPONSE_ERROR for an empty list. Callers must handle provider-legal empty outcomes before invoking this guard.
turn_delivered_no_answer
Returns whether the choice contains no nonempty text, tool call, or image. Reasoning alone is not an answer, even when retained in history.