pub async fn query_with_content(
content: impl Into<Vec<UserContentBlock>>,
options: Option<ClaudeAgentOptions>,
) -> Result<Vec<Message>>Expand description
Query Claude Code with structured content blocks (supports images).
This function allows you to send mixed content including text and images
to Claude. Use UserContentBlock to construct the content array.
Note: This function does not support can_use_tool callbacks or hooks.
For permission handling or hook support, use [ClaudeClient] instead.
§Errors
Returns an error if:
- The content vector is empty (must include at least one text or image block)
options.can_use_toolis set (use ClaudeClient instead)options.hooksis set (use ClaudeClient instead)- Claude CLI cannot be found or started
- The query execution fails
§Examples
use claude_agent_sdk_rs::{query_with_content, Message, ContentBlock, UserContentBlock};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create content with text and image
let content = vec![
UserContentBlock::text("What's in this image?"),
UserContentBlock::image_url("https://example.com/image.png"),
];
let messages = query_with_content(content, None).await?;
for message in messages {
if let Message::Assistant(msg) = message {
for block in &msg.message.content {
if let ContentBlock::Text(text) = block {
println!("Claude: {}", text.text);
}
}
}
}
Ok(())
}