| name | anth-core-workflow-b |
| description | Build Claude streaming and Message Batches API workflows.
Use when implementing real-time streaming responses, SSE event handling,
or processing bulk requests with the 50% cheaper Batches API.
Trigger with phrases like "claude streaming", "anthropic batch",
"message batches api", "SSE events anthropic", "stream claude response".
|
| allowed-tools | Read, Write, Edit, Bash(npm:*), Grep |
| version | 1.6.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","ai","anthropic"] |
| compatibility | Designed for Claude Code |
Anthropic Core Workflow B — Streaming & Batches
Overview
Two complementary patterns: real-time streaming for interactive UIs (SSE events via POST /v1/messages with stream: true) and the Message Batches API (POST /v1/messages/batches) for processing up to 100,000 requests asynchronously at 50% cost reduction.
Prerequisites
- Completed
anth-install-auth setup
- Familiarity with
anth-core-workflow-a (Messages API basics)
- For batches: understanding of async/polling patterns
Instructions
Streaming — Python SDK
import anthropic
client = anthropic.Anthropic()
with client.messages.stream(
model="claude-sonnet-4-20250514",
max_tokens=2048,
messages=[{"role": "user", "content": "Write a short story about a robot."}]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
final_message = stream.get_final_message()
print(f"\nUsage: {final_message.usage.input_tokens}+{final_message.usage.output_tokens}")
with client.messages.stream(
model="claude-sonnet-4-20250514",
max_tokens=2048,
messages=[{"role": "user", "content": "Explain REST APIs."}]
) as stream:
for event in stream:
event. == :
event.delta. == :
(event.delta.text, end=)
event. == :
()