Integrates Anthropic Claude API for chat, tool use, and vision capabilities. Use when building AI-powered features with Claude models including streaming, extended thinking, and multi-turn conversations.
Integrates Anthropic's Claude API for chat, tool use, and vision capabilities. Use this when building AI-powered features that need Claude models with streaming responses, extended thinking, or multi-turn conversations.
/plugin marketplace add mgd34msu/goodvibes-plugin/plugin install goodvibes@goodvibes-marketThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Official TypeScript SDK for Anthropic's Claude AI. Access Claude models for chat, tool use, vision, and extended thinking.
npm install @anthropic-ai/sdk
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-20250514',
max_tokens: 1024,
messages: [
{ role: 'user', content: 'Hello, Claude!' },
],
});
console.log(message.content[0].text);
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
system: 'You are a helpful coding assistant.',
messages: [
{ role: 'user', content: 'Explain async/await in JavaScript' },
],
});
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [
{ role: 'user', content: 'What is TypeScript?' },
{ role: 'assistant', content: 'TypeScript is a typed superset of JavaScript...' },
{ role: 'user', content: 'How do I define an interface?' },
],
});
const stream = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Tell me a story' }],
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);
}
}
const stream = anthropic.messages.stream({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello' }],
});
stream.on('text', (text) => {
process.stdout.write(text);
});
const finalMessage = await stream.finalMessage();
const stream = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello' }],
stream: true,
});
for await (const event of stream) {
switch (event.type) {
case 'message_start':
console.log('Started:', event.message.id);
break;
case 'content_block_start':
console.log('Block started:', event.content_block.type);
break;
case 'content_block_delta':
if (event.delta.type === 'text_delta') {
process.stdout.write(event.delta.text);
}
break;
case 'content_block_stop':
console.log('Block stopped');
break;
case 'message_stop':
console.log('Message complete');
break;
}
}
const tools = [
{
name: 'get_weather',
description: 'Get the current weather for a location',
input_schema: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'City name, e.g., San Francisco',
},
unit: {
type: 'string',
enum: ['celsius', 'fahrenheit'],
},
},
required: ['location'],
},
},
];
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
tools,
messages: [
{ role: 'user', content: 'What is the weather in Tokyo?' },
],
});
// Check for tool use
const toolUse = message.content.find((block) => block.type === 'tool_use');
if (toolUse) {
// Execute the tool
const weatherData = await getWeather(toolUse.input.location);
// Send result back
const finalMessage = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
tools,
messages: [
{ role: 'user', content: 'What is the weather in Tokyo?' },
{ role: 'assistant', content: message.content },
{
role: 'user',
content: [
{
type: 'tool_result',
tool_use_id: toolUse.id,
content: JSON.stringify(weatherData),
},
],
},
],
});
}
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [
{
role: 'user',
content: [
{
type: 'image',
source: {
type: 'url',
url: 'https://example.com/image.jpg',
},
},
{
type: 'text',
text: 'What is in this image?',
},
],
},
],
});
import fs from 'fs';
const imageData = fs.readFileSync('image.jpg').toString('base64');
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [
{
role: 'user',
content: [
{
type: 'image',
source: {
type: 'base64',
media_type: 'image/jpeg',
data: imageData,
},
},
{
type: 'text',
text: 'Describe this image in detail',
},
],
},
],
});
For complex reasoning tasks, enable extended thinking.
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 16000,
thinking: {
type: 'enabled',
budget_tokens: 10000,
},
messages: [
{ role: 'user', content: 'Solve this complex math problem...' },
],
});
// Access thinking blocks
for (const block of message.content) {
if (block.type === 'thinking') {
console.log('Thinking:', block.thinking);
} else if (block.type === 'text') {
console.log('Response:', block.text);
}
}
import fs from 'fs';
const pdfData = fs.readFileSync('document.pdf').toString('base64');
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [
{
role: 'user',
content: [
{
type: 'document',
source: {
type: 'base64',
media_type: 'application/pdf',
data: pdfData,
},
},
{
type: 'text',
text: 'Summarize this document',
},
],
},
],
});
// app/api/chat/route.ts
import Anthropic from '@anthropic-ai/sdk';
import { AnthropicStream, StreamingTextResponse } from 'ai';
const anthropic = new Anthropic();
export async function POST(request: Request) {
const { messages } = await request.json();
const response = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages,
stream: true,
});
const stream = AnthropicStream(response);
return new StreamingTextResponse(stream);
}
// app/api/chat/route.ts
import Anthropic from '@anthropic-ai/sdk';
const anthropic = new Anthropic();
export async function POST(request: Request) {
const { prompt } = await request.json();
const stream = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [{ role: 'user', content: prompt }],
stream: true,
});
const encoder = new TextEncoder();
const readable = new ReadableStream({
async start(controller) {
for await (const event of stream) {
if (event.type === 'content_block_delta' && event.delta.type === 'text_delta') {
controller.enqueue(encoder.encode(event.delta.text));
}
}
controller.close();
},
});
return new Response(readable, {
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
});
}
import Anthropic from '@anthropic-ai/sdk';
try {
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello' }],
});
} catch (error) {
if (error instanceof Anthropic.APIError) {
console.error('Status:', error.status);
console.error('Message:', error.message);
if (error.status === 429) {
// Rate limited
} else if (error.status === 401) {
// Invalid API key
} else if (error.status === 400) {
// Bad request
}
}
}
const tokenCount = await anthropic.messages.countTokens({
model: 'claude-sonnet-4-20250514',
messages: [
{ role: 'user', content: 'Hello, how are you?' },
],
});
console.log('Input tokens:', tokenCount.input_tokens);
| Model | ID | Best For |
|---|---|---|
| Claude Opus 4 | claude-opus-4-20250514 | Complex tasks, research |
| Claude Sonnet 4 | claude-sonnet-4-20250514 | Balanced performance |
| Claude Haiku 4 | claude-haiku-4-20250514 | Fast, simple tasks |
ANTHROPIC_API_KEY=sk-ant-xxxxxxxx
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.