## Getting Started with the Claude API
Anthropic's Claude API offers powerful language models with a focus on safety, long context, and reliable outputs.
### Installation & Authentication
```bash npm install @anthropic-ai/sdk ```
```typescript import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY, }); ```
### The Messages API
Claude uses a messages-based API similar to but distinct from OpenAI:
```typescript const message = await client.messages.create({ model: "claude-sonnet-4-20250514", max_tokens: 1024, system: "You are a helpful coding assistant.", messages: [ { role: "user", content: "Write a TypeScript function to debounce." } ], }); console.log(message.content[0].text); ```
### Model Selection
| Model | Strengths | Context | Speed | |-------|-----------|---------|-------| | Claude Opus 4 | Deepest reasoning, complex tasks | 200K | Slower | | Claude Sonnet 4 | Balanced performance and speed | 200K | Fast | | Claude Haiku 3.5 | Fastest, most cost-effective | 200K | Fastest |
### Key Differences from Other APIs
- System prompt is a separate parameter, not a message role
- max_tokens is required — you must always specify it
- Content blocks — responses are arrays of content blocks, not strings
- Stop reasons — `end_turn`, `max_tokens`, `stop_sequence`, `tool_use`