claude-stream
Parse Anthropic's Server-Sent Events stream into typed events. No SDK dependency, no async runtime lock-in — feed it bytes, drain typed events.
[]
= "0.1"
Why
There is no official Rust SDK for Anthropic. Community SDKs exist but couple you to a particular HTTP client + async runtime. claude-stream is the smallest possible primitive: an incremental SSE parser that knows the Anthropic event vocabulary (message_start, content_block_delta, tool_use, thinking, ping, …) and produces a typed Event enum. Wire it to whatever transport you already have.
Quick start
use ;
let mut parser = new;
// As bytes arrive (sync or async — your call):
loop
#
For the simple "I have the full body in a String" case:
use ;
let body: &str = /* full SSE response */ "";
let events = parse_all;
Events covered
message_start— message shell + initial usagecontent_block_start— text / tool_use / thinking / server_tool_usecontent_block_delta— text_delta / input_json_delta / thinking_delta / signature_deltacontent_block_stopmessage_delta— stop_reason, cumulative usagemessage_stoppingerror
Unknown event types fall through to Event::Unknown so the parser never panics on a new variant Anthropic adds.
What it doesn't do
- Doesn't make HTTP requests. Use
reqwest,hyper, or whatever you have. - Doesn't reassemble streaming
tool_use.inputpartial JSON into a finalserde_json::Value. Concatenate thepartial_jsonstrings yourself, thenserde_json::from_stronce the block stops. - Doesn't validate against any schema. Forward-compat over strictness.
License
MIT