| name | anth-sdk-patterns |
| description | Apply production-ready Anthropic SDK patterns for TypeScript and Python.
Use when implementing Claude integrations, building reusable wrappers,
or establishing team coding standards for the Messages API.
Trigger with phrases like "anthropic SDK patterns", "claude best practices",
"anthropic code patterns", "production claude code".
|
| allowed-tools | Read, Write, Edit |
| version | 1.6.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","ai","anthropic"] |
| compatibility | Designed for Claude Code |
Anthropic SDK Patterns
Overview
Production-ready patterns for the Anthropic SDK covering client management, error handling, type safety, and multi-tenant configurations.
Prerequisites
- Completed
anth-install-auth setup
- Familiarity with async/await patterns
- TypeScript 5+ or Python 3.10+
Pattern 1: Typed Wrapper with Retry
import Anthropic from '@anthropic-ai/sdk';
import type { Message, MessageCreateParams } from '@anthropic-ai/sdk/resources/messages';
class ClaudeService {
private client: Anthropic;
constructor(apiKey?: string) {
this.client = new Anthropic({
apiKey: apiKey || process.env.ANTHROPIC_API_KEY,
maxRetries: 3,
timeout: 60_000,
});
}
async complete(
prompt: string,
options: Partial<MessageCreateParams> = {}
): Promise<string> {
const message = await ...({
: options. || ,
: options. || ,
: [{ : , : prompt }],
...options,
});
textBlock = message..( b. === );
(!textBlock || textBlock. !== ) {
();
}
textBlock.;
}
*(: , model = ): <> {
stream = ...({
model,
: ,
: [{ : , : prompt }],
});
( event stream) {
(event. === && event.. === ) {
event..;
}
}
}
}