jackspace/claudeskillz/claude-api

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

This 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), processing images with vision capabilities, or using extended thinking mode. Use when building chatbots, AI assistants, content generation tools, or any application requiring Claude's language understanding. Covers both server-side implementations (Node.js, Cloudflare Workers, Next.js) and direct API access. Keywords: claude api, anthropic api, messages api, @anthropic-ai/sdk, claude streaming, prompt caching, tool use, vision, extended thinking, claude 3.5 sonnet, claude 3.7 sonnet, claude sonnet 4, function calling, SSE, rate limits, 429 errors

Install

npx vskill@latest install jackspace/claudeskillz/claude-api

SKILL.md

Claude API (Anthropic Messages API)

Status: Production Ready Last Updated: 2025-10-25 Dependencies: None (standalone API skill) Latest Versions: @anthropic-ai/sdk@0.67.0


Quick Start (5 Minutes)

1. Get API Key
bash
# Sign up at https://console.anthropic.com/
# Navigate to API Keys section
# Create new key and save securely
export ANTHROPIC_API_KEY="sk-ant-..."

Why this matters:

  • API key required for all requests
  • Keep secure (never commit to git)
  • Use environment variables
2. Install SDK (Node.js)
bash
npm install @anthropic-ai/sdk
typescript
import Anthropic from '@anthropic-ai/sdk';
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
});
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Claude!' }],
});
console.log(message.content[0].text);

CRITICAL:

  • Always use server-side (never expose API key in client code)
  • Set max_tokens (required parameter)
  • Model names are versioned (use latest stable)
3. Or Use Direct API (Cloudflare Workers)
typescript
// No SDK needed - use fetch()
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();

The Complete Claude API Reference

Table of Contents

  1. Core API
  2. Streaming Responses
  3. Prompt Caching
  4. Tool Use (Function Calling)
  5. Vision (Image Understanding)
  6. Extended Thinking Mode
  7. Rate Limits
  8. Error Handling
  9. Platform Integrations
  10. Known Issues

Core API (Messages API)

Available Models (October 2025)
ModelIDContextBest ForCost (per MTok)
Claude Sonnet 4.5claude-sonnet-4-5-20250929200k tokensBalanced performance$3/$15 (in/out)
Claude 3.7 Sonnetclaude-3-7-sonnet-202502282M tokensExtended thinking$3/$15
Claude Opus 4claude-opus-4-20250514200k tokensHighest capability$15/$75
Claude 3.5 Haikuclaude-3-5-haiku-20241022200k tokensFast, cost-effective$1/$5
Basic Message Creation
typescript
import Anthropic from '@anthropic-ai/sdk';
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
});
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 1024,
messages: [
{ role: 'user', content: 'Explain quantum computing in simple terms' }
],
});
console.log(message.content[0].text);
Multi-Turn Conversations
typescript
const messages = [
{ role: 'user', content: 'What is the capital of France?' },
{ role: 'assistant', content: 'The capital of France is Paris.' },
{ role: 'user', content: 'What is its population?' },
];
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 1024,
messages,
});
System Prompts
typescript
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 1024,
system: 'You are a helpful Python coding assistant. Always provide type hints and docstrings.',
messages: [
{ role: 'user', content: 'Write a function to sort a list' }
],
});

CRITICAL:

  • System prompt MUST come before messages array
  • System prompt sets behavior for entire conversation
  • Can be 1-10k tokens (affects context window)

Streaming Responses (SSE)

Using SDK Stream Helper
typescript
const stream = anthropic.messages.stream({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Write a short story' }],
});
// Method 1: Event listeners
stream
.on('text', (text) => {
process.stdout.write(text);
})
.on('message', (message) => {
console.log('\n\nFinal message:', message);
})
.on('error', (error) => {
console.error('Stream error:', error);
});
// Wait for completion
await stream.finalMessage();
Streaming with Manual Iteration
typescript
const stream = await anthropic.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Explain AI' }],
stream: true,
});
for await (const event of stream) {
if (event.type === 'content_block_delta' && event.delta.type === 'text_delta') {
process.stdout.write(event.delta.text);
}
}
Streaming Event Types
EventWhenUse Case
message_startMessage beginsInitialize UI
content_block_startNew content blockTrack blocks
content_block_deltaText chunk receivedDisplay text
content_block_stopBlock completeFormat block
message_deltaMetadata updateUpdate stop reason
message_stopMessage completeFinalize UI
Cloudflare Workers Streaming
typescript
export default {
async fetch(request: Request, env: Env): Promise<Response> {
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!' }],
stream: true,
}),
});
// Return SSE stream directly
return new Response(response.body, {
headers: {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
},
});
},
};

CRITICAL:

  • Errors can occur AFTER initial 200 response
  • Always implement error event handlers
  • Use stream.abort() to cancel
  • Set proper Content-Type headers

Prompt Caching (⭐ 90% Cost Savings)

Overview

Prompt caching allows you to cache frequently used context (system prompts, documents, codebases) to:

  • Reduce costs by 90% (cache reads = 10% of input token price)
  • Reduce latency by 85% (time to first token)
  • Cache lifetime: 5 minutes (default) or 1 hour (configurable)
Minimum Requirements
  • Claude 3.5 Sonnet: 1,024 tokens minimum
  • Claude 3.5 Haiku: 2,048 tokens minimum
Basic Prompt Caching
typescript
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 1024,
system: [
{
type: 'text',
text: 'You are an AI assistant analyzing the following codebase...',
},
{
type: 'text',
text: LARGE_CODEBASE_CONTENT, // 50k tokens
cache_control: { type: 'ephemeral' },
},
],
messages: [
{ role: 'user', content: 'Explain the auth module' }
],
});
// Check cache usage
console.log('Cache read tokens:', message.usage.cache_read_input_tokens);
console.log('Cache creation tokens:', message.usage.cache_creation_input_tokens);
Caching in Messages
typescript
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 1024,
messages: [
{
role: 'user',
content: [
{
type: 'text',
text: 'Analyze this documentation:',
},
{
type: 'text',
text: LONG_DOCUMENTATION, // 20k tokens
cache_control: { type: 'ephemeral' },
},
{
type: 'text',
text: 'What are the main API endpoints?',
},
],
},
],
});
Multi-Turn Caching (Chatbot Pattern)
typescript
// First request - creates cache
const message1 = await anthropic.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 1024,
system: [
{
type: 'text',
text: SYSTEM_INSTRUCTIONS,
cache_control: { type: 'ephemeral' },
},
],
messages: [
{ role: 'user', content: 'Hello!' }
],
});
// Second request - hits cache (within 5 minutes)
const message2 = await anthropic.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 1024,
system: [
{
type: 'text',
text: SYSTEM_INSTRUCTIONS, // Same content = cache hit
cache_control: { type: 'ephemeral' },
},
],
messages: [
{ role: 'user', content: 'Hello!' },
{ role: 'assistant', content: message1.content[0].text },
{ role: 'user', content: 'Tell me a joke' },
],
});
Cost Comparison
Without Caching:
- 100k input tokens = 100k × $3/MTok = $0.30
With Caching (after first request):
- Cache write: 100k × $3.75/MTok = $0.375 (first request)
- Cache read: 100k × $0.30/MTok = $0.03 (subsequent requests)
- Savings: 90% per request after first

CRITICAL:

  • cache_control MUST be on LAST block of cacheable content
  • Cache shared across requests with IDENTICAL content
  • Monitor cache_creation_input_tokens vs cache_read_input_tokens
  • 5-minute TTL refreshes on each use

Tool Use (Function Calling)

Basic Tool Definition
typescript
const tools = [
{
name: 'get_weather',
description: 'Get the current weather in a given location',
input_schema: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'City name, e.g. San Francisco, CA',
},
unit: {
type: 'string',
enum: ['celsius', 'fahrenheit'],
description: 'Temperature unit',
},
},
required: ['location'],
},
},
];
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 1024,
tools,
messages: [{ role: 'user', content: 'What is the weather in NYC?' }],
});
if (message.stop_reason === 'tool_use') {
const toolUse = message.content.find(block => block.type === 'tool_use');
console.log('Claude wants to use:', toolUse.name);
console.log('With parameters:', toolUse.input);
}
Tool Execution Loop
typescript
async function chatWithTools(userMessage: string) {
const messages = [{ role: 'user', content: userMessage }];
while (true) {
const response = await anthropic.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 1024,
tools,
messages,
});
// Add assistant response
messages.push({
role: 'assistant',
content: response.content,
});
// Check if tools need to be executed
if (response.stop_reason === 'tool_use') {
const toolResults = [];
for (const block of response.content) {
if (block.type === 'tool_use') {
// Execute tool
const result = await executeToolFunction(block.name, block.input);
toolResults.push({
type: 'tool_result',
tool_use_id: block.id,
content: JSON.stringify(result),
});
}
}
// Add tool results
messages.push({
role: 'user',
content: toolResults,
});
} else {
// Final response
return response.content.find(block => block.type === 'text')?.text;
}
}
}
Beta Tool Runner (SDK Helper)
typescript
import { betaZodTool } from '@anthropic-ai/sdk/helpers/zod';
import { z } from 'zod';

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 92 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
12
Repository forks
4
7-day trend score
13

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 2 Apr 2026, 6 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/jackspace/claudeskillz/claude-api/badge)](https://verified-skill.com/skills/jackspace/claudeskillz/claude-api)

Something wrong with this skill or its page? Tell us.