anthropic-streaming-patterns

Stream Claude API responses with in-stream tool execution and cost tracking.

3|1|Updated Nov 1, 2025
One-click install
npx skills add https://github.com/krzemienski/claude-mobile-expo --skill anthropic-streaming-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: anthropic-streaming-patterns
Source: https://github.com/krzemienski/claude-mobile-expo/tree/main/.claude/skills/anthropic-streaming-patterns
Command: npx skills add https://github.com/krzemienski/claude-mobile-expo --skill anthropic-streaming-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Integrating Claude API streaming responses, tool execution, and mandatory cost tracking can be complex and error-prone. This Skill provides proven patterns to ensure correct, efficient, and cost-aware API usage, saving development time and preventing unexpected bills.

Core Features & Use Cases

  • Efficient Streaming: Implement real-time, non-buffered Claude API responses for a superior, responsive user experience.
  • Robust Tool Execution: Seamlessly integrate and manage tool calls within the streaming flow, ensuring reliable automation.
  • Mandatory Cost Monitoring: Automatically track and calculate API token usage and costs for every interaction, providing transparency and control.
  • Use Case: Build a responsive AI chat application where Claude's responses stream in real-time, tools execute seamlessly, and users can always see their session's API cost, fostering trust and preventing surprise bills.

Quick Start

Use the anthropic-streaming-patterns skill to implement a streaming Claude API integration with tool execution and cost tracking for the new chat service.

Frequently Asked Questions about anthropic-streaming-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I stream Claude API responses without buffering?

Streaming Claude API responses enables real-time text delivery without buffering. This Skill implements non-buffered streaming patterns using the Anthropic SDK, processing text deltas via contentBlockDelta events to display Claude's output as it generates, creating responsive user experiences for chat applications and real-time integrations.

Can I execute tool calls while streaming Claude API responses?

Yes. This Skill handles tool execution within streaming flows using event-driven orchestration via contentBlockStart, contentBlockDelta, and contentBlockStop events. Tools accumulate inputs during streaming and execute seamlessly, enabling reliable automation without interrupting the response stream.

How do I track API costs across Claude streaming sessions?

Cost tracking calculates token usage and API expenses per message and per session. This Skill provides patterns for mandatory cost accounting integrated with the Anthropic SDK, enabling transparent logging of spending for debugging and production use, preventing unexpected billing surprises.

What's the best way to handle errors in Claude API streaming with tool use?

Robust error handling within streaming tool orchestration requires managing failures across text deltas, tool accumulation, and execution phases. This Skill covers SDK integration patterns for catching and responding to errors while maintaining stream integrity and cost visibility.

Do I need the Anthropic SDK to implement streaming with tool execution and cost tracking?

Yes. This Skill uses the Anthropic SDK to handle streaming initialization, event processing, tool orchestration, and cost calculation. The SDK integration provides the necessary APIs for contentBlockStart/Delta/Stop events and token usage metadata required for production-grade streaming implementations.

Can streaming patterns scale for production AI chat applications?

Streaming patterns scale for production by combining non-buffered response delivery, event-driven tool management, and per-session cost accounting. This Skill provides proven patterns tested for real-time chat services where responsiveness, reliability, and cost visibility are critical requirements.