AgentStack
SKILL verified MIT Self-run

Claude Api Cost Optimization

skill-louishin-claude-api-cost-optimization-claude-api-cost-optimization · by Louishin

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

No reviews yet
0 installs
12 views
0.0% view→install

Install

$ agentstack add skill-louishin-claude-api-cost-optimization-claude-api-cost-optimization

✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

Are you the author of Claude Api Cost Optimization? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

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

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 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

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


Made with 🐾 by Washin Village - Verified against official Anthropic documentation

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet — be the first.

Versions

  • v0.1.0 Imported from the upstream source.