pub enum ContentBlock {
Text {
text: String,
},
Thinking {
text: String,
},
Image {
mime_type: String,
source: ImageSource,
},
ToolCall {
tool_call_id: ToolCallId,
provider_call_id: Option<String>,
tool_name: String,
arguments: Value,
},
HostedTool {
activity: HostedToolActivity,
},
Citation {
citation: SourceCitation,
},
}Expand description
A provider-neutral message content block.
Variants§
Text
Visible text content.
Thinking
Model reasoning content that products may choose to hide.
Image
Image content with a MIME type and source.
ToolCall
A request to invoke a named tool.
Fields
tool_call_id: ToolCallIdCanonical tool-call identifier.
HostedTool
One complete provider-hosted activity, including normalized sources.
Fields
activity: HostedToolActivityValidated activity and opaque same-provider continuation state.
Citation
A normalized citation associated with assistant text.
Fields
citation: SourceCitationValidated cited source and optional provider continuation state.
Implementations§
Source§impl ContentBlock
impl ContentBlock
Sourcepub fn text(text: impl Into<String>) -> Result<Self, ContentValidationError>
pub fn text(text: impl Into<String>) -> Result<Self, ContentValidationError>
Creates a validated visible text block.
§Errors
Returns ContentValidationError::InvalidText when the text is empty,
contains a null character, or exceeds MAX_TEXT_BLOCK_BYTES.
Sourcepub fn thinking(text: impl Into<String>) -> Result<Self, ContentValidationError>
pub fn thinking(text: impl Into<String>) -> Result<Self, ContentValidationError>
Creates a validated thinking block.
§Errors
Returns ContentValidationError::InvalidText when the text is empty,
contains a null character, or exceeds MAX_TEXT_BLOCK_BYTES.
Sourcepub fn inline_image(
mime_type: impl Into<String>,
data: impl Into<String>,
) -> Result<Self, ContentValidationError>
pub fn inline_image( mime_type: impl Into<String>, data: impl Into<String>, ) -> Result<Self, ContentValidationError>
Creates a validated inline Base64 image block.
§Errors
Returns an error when the MIME type is invalid or the data is empty, oversized, or not valid standard Base64.
Sourcepub fn image_reference(
mime_type: impl Into<String>,
reference: impl Into<String>,
) -> Result<Self, ContentValidationError>
pub fn image_reference( mime_type: impl Into<String>, reference: impl Into<String>, ) -> Result<Self, ContentValidationError>
Creates a validated referenced image block.
§Errors
Returns an error when the MIME type or bounded reference is invalid.
Sourcepub fn tool_call(
tool_call_id: ToolCallId,
tool_name: impl Into<String>,
arguments: Value,
) -> Result<Self, ContentValidationError>
pub fn tool_call( tool_call_id: ToolCallId, tool_name: impl Into<String>, arguments: Value, ) -> Result<Self, ContentValidationError>
Creates a validated tool-call block.
§Errors
Returns an error when the tool name is invalid, arguments are not an object, or arguments exceed the byte or nesting limits.
Sourcepub fn tool_call_with_provider_id(
tool_call_id: ToolCallId,
provider_call_id: impl Into<String>,
tool_name: impl Into<String>,
arguments: Value,
) -> Result<Self, ContentValidationError>
pub fn tool_call_with_provider_id( tool_call_id: ToolCallId, provider_call_id: impl Into<String>, tool_name: impl Into<String>, arguments: Value, ) -> Result<Self, ContentValidationError>
Creates a validated tool-call block that retains its provider identifier.
§Errors
Returns an error when the provider identifier, tool name, or arguments violate their protocol bounds.
Sourcepub fn hosted_tool(activity: HostedToolActivity) -> Self
pub fn hosted_tool(activity: HostedToolActivity) -> Self
Wraps one validated provider-hosted tool activity.
Sourcepub fn citation(citation: SourceCitation) -> Self
pub fn citation(citation: SourceCitation) -> Self
Wraps one validated external source citation.
Sourcepub fn provider_call_id(&self) -> Option<&str>
pub fn provider_call_id(&self) -> Option<&str>
Returns the opaque provider identifier for a tool-call block.
Trait Implementations§
Source§impl Clone for ContentBlock
impl Clone for ContentBlock
Source§fn clone(&self) -> ContentBlock
fn clone(&self) -> ContentBlock
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more