1.6 KiB
1.6 KiB
Advanced Features Examples
This directory contains examples demonstrating the advanced features of the Claude Code SDK.
Examples
1. Token Streaming (token-streaming.js)
Demonstrates real-time token streaming capabilities:
- Basic token streaming
- Pause/resume control
- Progress indicators
- Stream metrics
Run:
node token-streaming.js
2. Error Handling (error-handling.js)
Shows advanced error handling patterns:
- Typed error detection
- Retry logic for rate limits
- Graceful degradation
- Error logging strategies
- Custom error handlers
Run:
node error-handling.js
3. Retry Strategies (retry-strategies.js)
Explores various retry patterns:
- Exponential backoff
- Linear retry
- Fibonacci sequence retry
- Circuit breaker pattern
- Retry with telemetry
Run:
node retry-strategies.js
Prerequisites
Make sure you have the SDK installed:
npm install @instantlyeasy/claude-code-sdk-ts
And Claude Code CLI configured:
claude --help
Best Practices
These examples demonstrate production-ready patterns:
-
Error Handling: Always wrap your queries in try-catch blocks and handle specific error types appropriately.
-
Retry Logic: Use exponential backoff for transient failures and respect rate limits.
-
Streaming: Use token streaming for better UX in interactive applications.
-
Telemetry: Track metrics to understand your application's behavior and performance.