en un clic
api-integration
This skill should be used when the user asks to 'integrate an API', 'handle streaming responses', 'add authentication', or 'manage API calls'. Covers Claude API integration and streaming patterns.
Menu
This skill should be used when the user asks to 'integrate an API', 'handle streaming responses', 'add authentication', or 'manage API calls'. Covers Claude API integration and streaming patterns.
This skill should be used when the user asks to 'create an agent', 'add tool calling', 'build workflows', or 'orchestrate AI tasks'. Guides agentic AI patterns and multi-step reasoning.
This skill should be used when the user asks to 'add a command', 'parse arguments', 'improve CLI output', or 'add interactive features'. Covers command routing, argument parsing, and stdio handling.
This skill should be used when the user asks to 'scan directories', 'read files', 'parse JSON or Markdown', or 'traverse the file system'. Guides safe file I/O patterns and recursive directory operations.
This skill should be used when the user asks to 'generate Markdown', 'create documentation', 'structure content', or 'format skill definitions'. Covers Markdown generation and structured documentation patterns.
This skill should be used when the user asks to 'create a CLI tool', 'handle file system operations', 'manage processes', or 'configure runtime behavior'. Guides Node.js 20.x patterns and native APIs.
This skill should be used when the user asks to 'add types', 'fix type errors', 'create interfaces', 'improve type safety', or 'configure TypeScript'. Provides TypeScript strict mode patterns and ESM configuration for Node.js projects.
| name | api-integration |
| description | This skill should be used when the user asks to 'integrate an API', 'handle streaming responses', 'add authentication', or 'manage API calls'. Covers Claude API integration and streaming patterns. |
| version | 1.0.0 |
| metadata | {"internal":false} |
Patterns for integrating with the Anthropic Claude API using native fetch and streaming responses.
ANTHROPIC_API_KEY environment variable (required)import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
});
export async function callClaude(
systemPrompt: string,
userContext: string,
verbose: boolean = false
): Promise<string> {
const stream = await client.messages.create({
model: "claude-sonnet-4-5-20250929",
max_tokens: 16000,
temperature: 1,
system: systemPrompt,
messages: [{ role: "user", content: userContext }],
stream: true,
});
let fullResponse = "";
for await (const event of stream) {
if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
fullResponse += event.delta.text;
if (!verbose) {
process.stdout.write(event.delta.text);
}
}
}
return fullResponse;
}
When --verbose flag is used, output raw stream events:
if (verbose) {
// Inherit stdio for real-time stream-json output
const result = await callClaude(PROMPT, context, true);
} else {
// Buffer and return clean text
const result = await callClaude(PROMPT, context, false);
}
Separate system prompt from user context:
// src/prompts/my-feature.ts
export const MY_FEATURE_PROMPT = `
You are a Senior Technical Writer generating...
## GUIDELINES
- Guideline 1
- Guideline 2
`;
// src/generators/my-feature.ts
import { callClaude } from "../utils/claude.js";
import { MY_FEATURE_PROMPT } from "../prompts/my-feature.js";
export async function generateMyFeature(): Promise<string> {
const userContext = await gatherProjectContext();
return await callClaude(MY_FEATURE_PROMPT, userContext);
}
Always use environment variable, never hardcode:
const client = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY, // Required
});
// Validate before making calls
if (!process.env.ANTHROPIC_API_KEY) {
throw new Error("ANTHROPIC_API_KEY environment variable required");
}
stream: true for all generation tasks to provide real-time feedbacksrc/prompts/ as version-controlled constantsmax_tokens: 16000 for documentation generation (adjust per use case)content_block_delta with text_delta typefor await with stream events