Back to Skills

claude-api

verified

Anthropic Messages API (Claude API) for integrations, streaming, prompt caching, tool use, vision. Use for chatbots, assistants, or encountering rate limits, 429 errors.

View on GitHub

Marketplace

claude-skills

secondsky/claude-skills

Plugin

claude-api

ai

Repository

secondsky/claude-skills
28stars

plugins/claude-api/skills/claude-api/SKILL.md

Last Verified

January 24, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/secondsky/claude-skills/blob/main/plugins/claude-api/skills/claude-api/SKILL.md -a claude-code --skill claude-api

Installation paths:

Claude
.claude/skills/claude-api/
Powered by add-skill CLI

Instructions

# Claude API (Anthropic Messages API)

**Status**: Production Ready | **SDK**: @anthropic-ai/sdk@0.70.1

---

## Quick Start (5 Minutes)

### Node.js

```typescript
import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
  apiKey: process.env.ANTHROPIC_API_KEY,
});

const message = await client.messages.create({
  model: 'claude-sonnet-4-5-20250929',
  max_tokens: 1024,
  messages: [
    { role: 'user', content: 'Hello, Claude!' },
  ],
});

console.log(message.content[0].text);
```

### Cloudflare Workers

```typescript
const response = await fetch('https://api.anthropic.com/v1/messages', {
  method: 'POST',
  headers: {
    'x-api-key': env.ANTHROPIC_API_KEY,
    'anthropic-version': '2023-06-01',
    'content-type': 'application/json',
  },
  body: JSON.stringify({
    model: 'claude-sonnet-4-5-20250929',
    max_tokens: 1024,
    messages: [{ role: 'user', content: 'Hello!' }],
  }),
});

const data = await response.json();
console.log(data.content[0].text);
```

**Load `references/setup-guide.md` for complete setup with streaming, caching, and tools.**

---

## Critical Rules

### Always Do ✅

1. **Use environment variables** for API keys (NEVER hardcode)
2. **Set max_tokens** explicitly (required parameter)
3. **Pin model version** (`claude-sonnet-4-5-20250929`, not `claude-3-5-sonnet-latest`)
4. **Enable prompt caching** for repeated content (90% cost savings)
5. **Stream long responses** (`stream: true`) for better UX
6. **Handle errors** - Implement retry logic for 429, 529 errors
7. **Validate inputs** - Sanitize user messages before sending
8. **Monitor costs** - Track token usage
9. **Set timeouts** - Prevent hanging requests
10. **Use tool use properly** - Return tool_result in follow-up message

### Never Do ❌

1. **Never expose API key** in client-side code
2. **Never skip max_tokens** - API will error without it
3. **Never ignore stop_reason** - Check for `tool_use`, `end_turn`, `max_tokens`
4. **Never assume single content block**

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
12152 chars