Skip to content
Back to skills

claude-api-cost-optimization

ASecurity

Save 50-90% on Claude API costs with Batch API, Prompt Caching & Extended Thinking. Official techniques, verified.

  • 19 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added February 6, 2026
data-aipythonapidocumentation

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 16 files and shows the line behind each finding

Scanned February 12, 2026

npx -y skills add sstklen/claude-api-cost-optimization --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of claude-api-cost-optimization?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for claude-api-cost-optimization
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/sstklen-claude-api-cost-optimization/badge)](https://www.skillsdirectory.com/skills/sstklen-claude-api-cost-optimization)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: claude-api-cost-optimization
description: Save 50-90% on Claude API costs with Batch API, Prompt Caching & Extended Thinking. Official techniques, verified.
triggers:
  - "/api-cost"
  - "save money"
  - "reduce cost"
  - "API pricing"
  - "batch api"
  - "prompt caching"
---

# Claude API Cost Optimization

> Save 50-90% on Claude API costs with three officially verified techniques

## Quick Reference

| Technique | Savings | Use When |
|-----------|---------|----------|
| **Batch API** | 50% | Tasks can wait up to 24h |
| **Prompt Caching** | 90% | Repeated system prompts (>1K tokens) |
| **Extended Thinking** | ~80% | Complex reasoning tasks |
| **Batch + Cache** | ~95% | Bulk tasks with shared context |

---

## 1. Batch API (50% Off)

### When to Use
- Bulk translations
- Daily content generation
- Overnight report processing
- NOT for real-time chat

### Code Example
```python
import anthropic

client = anthropic.Anthropic()

batch = client.messages.batches.create(
    requests=[
        {
            "custom_id": "task-001",
            "params": {
                "model": "claude-sonnet-4-5",
                "max_tokens": 1024,
                "messages": [{"role": "user", "content": "Task 1"}]
            }
        }
    ]
)

# Results available within 24h (usually <1h)
for result in client.messages.batches.results(batch.id):
    print(f"{result.custom_id}: {result.result.message.content[0].text}")
```

### Key Finding: Bigger Batches = Faster!
| Batch Size | Time/Request |
|------------|--------------|
| Large (294) | **0.45 min** |
| Small (10) | 9.84 min |

**22x efficiency difference!** Always batch 100+ requests together.

---

## 2. Prompt Caching (90% Off)

### When to Use
- Long system prompts (>1K tokens)
- Repeated instructions
- RAG with large context

### Code Example
```python
response = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=1024,
    system=[{
        "type": "text",
        "text": "Your long system prompt here...",
        "cache_control": {"type": "ephemeral"}  # Enable caching!
    }],
    messages=[{"role": "user", "content": "User question"}]
)
# First call: +25% (cache write)
# Subsequent: -90% (cache read!)
```

### Cache Rules
- Minimum: 1,024 tokens (Sonnet)
- TTL: 5 minutes (refreshes on use)

---

## 3. Extended Thinking (~80% Off)

### When to Use
- Complex code architecture
- Strategic planning
- Mathematical reasoning

### Code Example
```python
response = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=16000,
    thinking={
        "type": "enabled",
        "budget_tokens": 10000
    },
    messages=[{"role": "user", "content": "Design architecture for..."}]
)
```

---

## Decision Flowchart

```
Can wait 24h? → Yes → Batch API (50% off)
                 ↓ No
Repeated prompts >1K? → Yes → Prompt Caching (90% off)
                         ↓ No
Complex reasoning? → Yes → Extended Thinking
                      ↓ No
Use normal API
```

---

## Official Docs

- [Batch Processing](https://docs.anthropic.com/en/docs/build-with-claude/batch-processing)
- [Prompt Caching](https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching)
- [Extended Thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)

---

*Made with 🐾 by [Washin Village](https://washinmura.jp) - Verified against official Anthropic documentation*

Files in this skill

  • SKILL.md3.3 KB
  • STORY.md6.6 KB
  • assets/preview.png80.8 KB
  • claude-api-cost-optimization.skill.md13.9 KB
  • examples/GAIA-savings-report.md3.4 KB
  • examples/batch-294-videos-case-study.md4.3 KB
  • examples/billing-data-analysis.md3.3 KB
  • examples/jelly-294-gaia-tagging-batch.md7.2 KB
  • examples/real-batch-results.md2.9 KB
  • references/README.md860 B
  • references/batch-api.md1.8 KB
  • references/extended-thinking.md1.9 KB
  • references/prompt-caching.md1.9 KB
  • scripts/batch_example.py3.7 KB
  • scripts/cache_example.py7.2 KB
  • scripts/calculate_savings.py7.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.