kid-sid/claude-spellbook/claude-api
Claude Code and agent skill by kid-sid/claude-spellbook
- community
Checking that the SKILL.md file is still in the repository.
Use when building or debugging apps that call the Claude API — implementing tool use, streaming, vision, prompt caching, batch processing, extended thinking, or an agentic loop with the Anthropic SDK.
Install
npx vskill@latest install kid-sid/claude-spellbook/claude-apiSKILL.md
Claude API
Build applications with the Anthropic Claude API and SDKs.
When to Activate
- Building applications that call the Claude API
- Code imports
anthropic(Python) or@anthropic-ai/sdk(TypeScript) - User asks about Claude API patterns, tool use, streaming, or vision
- Implementing agent workflows with Claude Agent SDK
- Optimizing API costs, token usage, or latency
Model Selection
| Model | ID | Best For | |
|---|---|---|---|
| Opus 4.1 | claude-opus-4-1 | Complex reasoning, architecture, research | |
| Sonnet 4 | claude-sonnet-4-0 | Balanced coding, most development tasks | |
| Haiku 3.5 | claude-3-5-haiku-latest | Fast responses, high-volume, cost-sensitive |
Default to Sonnet 4 unless the task requires deep reasoning (Opus) or speed/cost optimization (Haiku). For production, prefer pinned snapshot IDs over aliases.
Python SDK
Installation
Basic Message
Streaming
System Prompt
TypeScript SDK
Installation
Basic Message
Streaming
Tool Use
Define tools and let Claude call them:
Vision
Send images for analysis:
Extended Thinking
For complex reasoning tasks:
Prompt Caching
Cache large system prompts or context to reduce costs:
Batches API
Process large volumes asynchronously at 50% cost reduction:
Claude Agent SDK
Build multi-step agents:
Cost Optimization
| Strategy | Savings | When to Use | |
|---|---|---|---|
| Prompt caching | Up to 90% on cached tokens | Repeated system prompts or context | |
| Batches API | 50% | Non-time-sensitive bulk processing | |
| Haiku instead of Sonnet | ~75% | Simple tasks, classification, extraction | |
| Shorter max_tokens | Variable | When you know output will be short | |
| Streaming | None (same cost) | Better UX, same price |
Error Handling
Environment Setup
Never hardcode API keys. Always use environment variables.
Red Flags
- Not setting `max_tokens` explicitly — omitting it uses the SDK default which may be far too low for your use case, causing truncated responses with no error raised
- Using `client.messages.create()` in a tight loop without backoff — hitting rate limits with immediate retries amplifies the problem; use the SDK's built-in retry config or
tenacitywith exponential backoff - Passing raw user input directly as the user message — prompt injection can redirect the model's behavior; sanitize or structure user input within a constrained template
- Enabling extended thinking (`budget_tokens`) without raising `max_tokens` — thinking tokens count against
max_tokens; a smallmax_tokenscauses the request to error before the model produces output - Polling the Batches API in a tight `while True` loop with `time.sleep(1)` — batches can take minutes to hours; use
time.sleep(30)at minimum, or a webhook/callback if available - Caching the `Anthropic` client instance across forked processes — the underlying httpx session is not fork-safe; instantiate a new client per process in multiprocessing scenarios
- Using an alias model ID (e.g., `claude-sonnet-4-0`) in production — aliases can be remapped to a new model version without warning, changing behavior; pin to a dated snapshot ID for reproducible production behavior
- Logging the full request/response payload — responses may echo back sensitive user data; log only metadata (model, token counts, stop reason), never message content
Checklist
- [ ] API key loaded from environment variable, not hardcoded
- [ ] Model pinned to a specific version (not
latest) - [ ]
max_tokensset explicitly for every request - [ ] Rate limit and API errors caught and retried with backoff
- [ ] Streaming used for long responses to avoid timeout
- [ ] Tool schemas validated;
requiredfields listed explicitly - [ ] Prompt caching headers set for repeated system prompts
- [ ] Costs estimated before running batch or high-volume jobs
- [ ] Response content checked for
stop_reasonbefore use - [ ] No sensitive data logged from request/response payloads
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/claude-api/skill.md
Popularity
- Repository stars
- 186
- Repository forks
- 15
- 7-day trend score
- 26
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
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
[](https://verified-skill.com/skills/kid-sid/claude-spellbook/claude-api)