claude-api

Implements Anthropic Claude API patterns for Python and TypeScript applications.

Updated Mar 26, 2026
One-click install
npx skills add https://github.com/inuishan/PET --skill claude-api-inuishan
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: claude-api
Source: https://github.com/inuishan/PET/tree/main/.codex/skills/claude-api
Command: npx skills add https://github.com/inuishan/PET --skill claude-api-inuishan

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires anthropic, @anthropic-ai/sdk.

What problem does it solve? Developers building applications with the Anthropic Claude API need correct, up-to-date patterns for the Messages API, streaming, tool use, vision, extended thinking, prompt caching, and batch processing across both Python and TypeScript SDKs. ## Core Features & Use Cases - Messages API & Streaming: Provides working code for basic messages, system prompts, and real-time streaming in both Python (anthropic) and TypeScript (@anthropic-ai/sdk). - Advanced Capabilities: Covers tool use loops, vision with base64 images, extended thinking budgets, prompt caching for cost reduction, and the Batches API for 50% savings on bulk workloads. - Cost & Reliability Guidance: Includes a model selection table (Opus, Sonnet, Haiku), cost optimization strategies, and error handling for rate limits and connection failures. - Use Case: When adding an LLM-based expense categorization feature to a mobile backend, use this Skill to implement a tool-use loop with prompt caching and Haiku for high-volume classification. ## Quick Start Ask the AI to write a Python script that calls the Claude Messages API with streaming and tool use for your application.

Frequently Asked Questions about claude-api

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I call the Claude API in Python?▼

Install the anthropic package with pip, create an anthropic.Anthropic() client that reads ANTHROPIC_API_KEY from the environment, and call client.messages.create with a model, max_tokens, and messages array. The response text is available at message.content[0].text.

How to stream responses from the Claude API?▼

In Python, use client.messages.stream as a context manager and iterate over stream.text_stream. In TypeScript, use client.messages.stream and loop over events, printing text from content_block_delta events with text_delta types.

Which Claude model should I use for my application?▼

Default to Sonnet 4.6 for balanced coding and development tasks. Use Opus 4.6 for complex reasoning and architecture work, and Haiku 4.5 for fast, high-volume, cost-sensitive tasks like classification and extraction.

Does the Claude API support tool use and function calling?▼

Yes, define tools with a name, description, and JSON input_schema, pass them in the tools parameter, and handle tool_use content blocks in the response. Execute the tool locally and send results back as tool_result messages to continue the conversation.

How can I reduce Claude API costs?▼

Use prompt caching for repeated system prompts (up to 90% savings on cached tokens), the Batches API for non-urgent bulk work (50% savings), and Haiku instead of Sonnet for simple tasks (~75% savings). Setting shorter max_tokens also reduces spend.

How do I handle Claude API rate limit errors?▼

Catch RateLimitError from the anthropic package and back off before retrying, typically sleeping around 60 seconds. Also handle APIConnectionError for network issues with retry backoff and APIError for general failures with status codes.