pub async fn query_stream_with_content(
content: impl Into<Vec<UserContentBlock>>,
options: Option<ClaudeAgentOptions>,
) -> Result<Pin<Box<dyn Stream<Item = Result<Message>> + Send>>>Expand description
Query Claude Code with streaming and structured content blocks.
Combines the benefits of query_stream (memory efficiency, real-time processing)
with support for structured content blocks including images.
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 streaming connection fails
§Examples
use claude_agent_sdk_rs::{query_stream_with_content, Message, ContentBlock, UserContentBlock};
use futures::stream::StreamExt;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create content with base64 image
let content = vec![
UserContentBlock::image_base64("image/png", "iVBORw0KGgo...")?,
UserContentBlock::text("Describe this diagram in detail"),
];
let mut stream = query_stream_with_content(content, None).await?;
while let Some(result) = stream.next().await {
match result? {
Message::Assistant(msg) => {
for block in &msg.message.content {
if let ContentBlock::Text(text) = block {
println!("Claude: {}", text.text);
}
}
}
_ => {}
}
}
Ok(())
}