$npx -y skills add jackspace/ClaudeSkillz --skill claude-apiThis skill provides comprehensive knowledge for working with the Anthropic Messages API (Claude API). It should be used when integrating Claude models into applications, implementing streaming responses, enabling prompt caching for cost savings, adding tool use (function calling)
| 1 | # Claude API (Anthropic Messages API) |
| 2 | |
| 3 | **Status**: Production Ready |
| 4 | **Last Updated**: 2025-10-25 |
| 5 | **Dependencies**: None (standalone API skill) |
| 6 | **Latest Versions**: @anthropic-ai/sdk@0.67.0 |
| 7 | |
| 8 | --- |
| 9 | |
| 10 | ## Quick Start (5 Minutes) |
| 11 | |
| 12 | ### 1. Get API Key |
| 13 | |
| 14 | ```bash |
| 15 | # Sign up at https://console.anthropic.com/ |
| 16 | # Navigate to API Keys section |
| 17 | # Create new key and save securely |
| 18 | export ANTHROPIC_API_KEY="sk-ant-..." |
| 19 | ``` |
| 20 | |
| 21 | **Why this matters:** |
| 22 | - API key required for all requests |
| 23 | - Keep secure (never commit to git) |
| 24 | - Use environment variables |
| 25 | |
| 26 | ### 2. Install SDK (Node.js) |
| 27 | |
| 28 | ```bash |
| 29 | npm install @anthropic-ai/sdk |
| 30 | ``` |
| 31 | |
| 32 | ```typescript |
| 33 | import Anthropic from '@anthropic-ai/sdk'; |
| 34 | |
| 35 | const anthropic = new Anthropic({ |
| 36 | apiKey: process.env.ANTHROPIC_API_KEY, |
| 37 | }); |
| 38 | |
| 39 | const message = await anthropic.messages.create({ |
| 40 | model: 'claude-sonnet-4-5-20250929', |
| 41 | max_tokens: 1024, |
| 42 | messages: [{ role: 'user', content: 'Hello, Claude!' }], |
| 43 | }); |
| 44 | |
| 45 | console.log(message.content[0].text); |
| 46 | ``` |
| 47 | |
| 48 | **CRITICAL:** |
| 49 | - Always use server-side (never expose API key in client code) |
| 50 | - Set `max_tokens` (required parameter) |
| 51 | - Model names are versioned (use latest stable) |
| 52 | |
| 53 | ### 3. Or Use Direct API (Cloudflare Workers) |
| 54 | |
| 55 | ```typescript |
| 56 | // No SDK needed - use fetch() |
| 57 | const response = await fetch('https://api.anthropic.com/v1/messages', { |
| 58 | method: 'POST', |
| 59 | headers: { |
| 60 | 'x-api-key': env.ANTHROPIC_API_KEY, |
| 61 | 'anthropic-version': '2023-06-01', |
| 62 | 'content-type': 'application/json', |
| 63 | }, |
| 64 | body: JSON.stringify({ |
| 65 | model: 'claude-sonnet-4-5-20250929', |
| 66 | max_tokens: 1024, |
| 67 | messages: [{ role: 'user', content: 'Hello!' }], |
| 68 | }), |
| 69 | }); |
| 70 | |
| 71 | const data = await response.json(); |
| 72 | ``` |
| 73 | |
| 74 | --- |
| 75 | |
| 76 | ## The Complete Claude API Reference |
| 77 | |
| 78 | ## Table of Contents |
| 79 | |
| 80 | 1. [Core API](#core-api-messages-api) |
| 81 | 2. [Streaming Responses](#streaming-responses-sse) |
| 82 | 3. [Prompt Caching](#prompt-caching--90-cost-savings) |
| 83 | 4. [Tool Use (Function Calling)](#tool-use-function-calling) |
| 84 | 5. [Vision (Image Understanding)](#vision-image-understanding) |
| 85 | 6. [Extended Thinking Mode](#extended-thinking-mode) |
| 86 | 7. [Rate Limits](#rate-limits) |
| 87 | 8. [Error Handling](#error-handling) |
| 88 | 9. [Platform Integrations](#platform-integrations) |
| 89 | 10. [Known Issues](#known-issues-prevention) |
| 90 | |
| 91 | --- |
| 92 | |
| 93 | ## Core API (Messages API) |
| 94 | |
| 95 | ### Available Models (October 2025) |
| 96 | |
| 97 | | Model | ID | Context | Best For | Cost (per MTok) | |
| 98 | |-------|-----|---------|----------|-----------------| |
| 99 | | **Claude Sonnet 4.5** | claude-sonnet-4-5-20250929 | 200k tokens | Balanced performance | $3/$15 (in/out) | |
| 100 | | **Claude 3.7 Sonnet** | claude-3-7-sonnet-20250228 | 2M tokens | Extended thinking | $3/$15 | |
| 101 | | **Claude Opus 4** | claude-opus-4-20250514 | 200k tokens | Highest capability | $15/$75 | |
| 102 | | **Claude 3.5 Haiku** | claude-3-5-haiku-20241022 | 200k tokens | Fast, cost-effective | $1/$5 | |
| 103 | |
| 104 | ### Basic Message Creation |
| 105 | |
| 106 | ```typescript |
| 107 | import Anthropic from '@anthropic-ai/sdk'; |
| 108 | |
| 109 | const anthropic = new Anthropic({ |
| 110 | apiKey: process.env.ANTHROPIC_API_KEY, |
| 111 | }); |
| 112 | |
| 113 | const message = await anthropic.messages.create({ |
| 114 | model: 'claude-sonnet-4-5-20250929', |
| 115 | max_tokens: 1024, |
| 116 | messages: [ |
| 117 | { role: 'user', content: 'Explain quantum computing in simple terms' } |
| 118 | ], |
| 119 | }); |
| 120 | |
| 121 | console.log(message.content[0].text); |
| 122 | ``` |
| 123 | |
| 124 | ### Multi-Turn Conversations |
| 125 | |
| 126 | ```typescript |
| 127 | const messages = [ |
| 128 | { role: 'user', content: 'What is the capital of France?' }, |
| 129 | { role: 'assistant', content: 'The capital of France is Paris.' }, |
| 130 | { role: 'user', content: 'What is its population?' }, |
| 131 | ]; |
| 132 | |
| 133 | const message = await anthropic.messages.create({ |
| 134 | model: 'claude-sonnet-4-5-20250929', |
| 135 | max_tokens: 1024, |
| 136 | messages, |
| 137 | }); |
| 138 | ``` |
| 139 | |
| 140 | ### System Prompts |
| 141 | |
| 142 | ```typescript |
| 143 | const message = await anthropic.messages.create({ |
| 144 | model: 'claude-sonnet-4-5-20250929', |
| 145 | max_tokens: 1024, |
| 146 | system: 'You are a helpful Python coding assistant. Always provide type hints and docstrings.', |
| 147 | messages: [ |
| 148 | { role: 'user', content: 'Write a function to sort a list' } |
| 149 | ], |
| 150 | }); |
| 151 | ``` |
| 152 | |
| 153 | **CRITICAL:** |
| 154 | - System prompt MUST come before messages array |
| 155 | - System prompt sets behavior for entire conversation |
| 156 | - Can be 1-10k tokens (affects context window) |
| 157 | |
| 158 | --- |
| 159 | |
| 160 | ## Streaming Responses (SSE) |
| 161 | |
| 162 | ### Using |