← Back to Skills Marketplace
djc00p

claude-api-cost-optimizer

by Deonte Cooper · GitHub ↗ · v1.0.3 · MIT-0
linuxdarwinwin32 ⚠ suspicious
183
Downloads
0
Stars
0
Active Installs
4
Versions
Install in OpenClaw
/install claude-api-cost-optimizer
Description
Minimize Anthropic Claude API costs through model selection, prompt caching, batching, and cost tracking. Trigger phrases: reduce API costs, optimize Claude...
README (SKILL.md)

Claude API Cost Optimizer

Cut Claude API costs by 70–90% using intelligent model selection, caching, and batching.

Quick Start

  1. Audit your current API calls — identify which tasks use Opus or Sonnet that could use Haiku. Model selection alone saves 10–18x on simple tasks.
  2. Pick the cheapest model tier for each task: Haiku (cheapest) → Sonnet (mid) → Opus (most expensive, use sparingly). See references/pricing.md for current rates.
  3. Enable prompt caching for repeated context (system prompts, codebases) by adding "cache_control": {"type": "ephemeral"} to message blocks
  4. Implement cost reporting — track input_tokens, output_tokens, and cache metrics from API responses

Key Concepts

  • Model selection — Haiku for simple tasks (formatting, comments) — cheapest tier. Sonnet for medium (refactoring, debugging) — mid tier. Opus for complex only (architecture, security) — most expensive, use sparingly. See references/pricing.md for current rates.
  • Prompt caching — Cache large static content (system prompts, codebase context). Cache reads cost 90% less; writes pay off after 1–2 reuses.
  • Batching — Combine multiple requests into one API call to eliminate per-request overhead. 80% fewer calls ≈ 80% lower cost.
  • Local caching — Cache identical responses locally to skip redundant API calls entirely.
  • Context extraction — Send only relevant snippets, not whole files. Smaller inputs = lower costs.
  • max_tokens discipline — Set realistic limits; unused token budget is wasted money.

Common Usage

Code examples are in Python but concepts apply to any language or SDK.

Model selection pattern:

def select_model(task_type: str) -> str:
    simple_tasks = ["formatting", "comments", "explanation", "rename"]
    complex_tasks = ["architecture", "algorithm", "security_audit"]
    return ("claude-haiku-4-5-20251001" if task_type in simple_tasks else
            "claude-opus-4-6" if task_type in complex_tasks else
            "claude-sonnet-4-6")

Prompt caching:

response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    system=[{
        "type": "text",
        "text": system_prompt,
        "cache_control": {"type": "ephemeral"}
    }],
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": f"Code:\
{source_code}", 
             "cache_control": {"type": "ephemeral"}},
            {"type": "text", "text": query}
        ]
    }]
)

Cost tracking:

usage = response.usage
cost = (usage.input_tokens * INPUT_RATE +
        usage.cache_creation_input_tokens * CACHE_WRITE_RATE +
        usage.cache_read_input_tokens * CACHE_READ_RATE +
        usage.output_tokens * OUTPUT_RATE)

References

  • references/implementation.md — Full implementation patterns, model routing, caching setup, batching, retry logic, and anti-patterns
  • references/pricing.md — Current pricing, cache cost math, savings calculations, and batch API details
Usage Guidance
This skill appears to be a legitimate Claude cost-optimizer, but review the following before installing or running it: - Registry vs runtime mismatch: The SKILL.md expects ANTHROPIC_API_KEY (used in code examples) but the registry metadata lists no required env vars. Verify which is correct — the skill will need your Anthropic key to function. - Local caching & logs: The instructions create ~/.claude_cache/, costs.log, and batch_results.jsonl which may contain code, prompts, and responses. Those files can include sensitive data (source code, PII, or parts of prompts). Only enable local caching if you accept that risk. Consider using an encrypted cache, stricter file permissions, or a segregated machine/account. - Don’t cache secrets: The docs warn not to cache secrets, but enforcement is manual. Audit any integration that feeds code or config into the cache to ensure it does not include API keys, passwords, or tokens. - File permissions and safety: The docs recommend chmod 600; confirm your environment enforces this and consider atomic writes to avoid partial writes. If you run this on shared CI runners, the cache/log files could persist across jobs. - Source provenance: The skill lists a homepage but the source is 'unknown' in the registry. If you plan to supply credentials, verify the skill’s source (review the full implementation) or run on an isolated environment/VM. - Minimal test first: Run the patterns locally with a disposable Anthropic key and review what is written to disk before integrating into production workflows. Consider disabling local cache or pointing the cache to an encrypted/ephemeral volume. If you want, I can: (1) extract and show the exact places the SKILL.md and references mention ANTHROPIC_API_KEY and local file writes; (2) suggest hardened code snippets for encrypted/safer caching; or (3) draft a checklist to safely evaluate and run this skill in CI or locally.
Capability Analysis
Type: OpenClaw Skill Name: claude-api-cost-optimizer Version: 1.0.3 The skill bundle provides documentation and Python code templates for optimizing Anthropic Claude API costs via model selection, prompt caching, and batching. While it includes a local caching mechanism that writes to `~/.claude_cache/` (references/implementation.md), it provides explicit security warnings regarding file permissions and the handling of sensitive data. No evidence of data exfiltration, malicious execution, or prompt injection was found; the code and instructions are consistent with the stated purpose of cost optimization.
Capability Tags
cryptocan-make-purchases
Capability Assessment
Purpose & Capability
The name/description (minimize Claude API costs) align with the instructions (model selection, caching, batching, cost tracking). However the SKILL.md metadata declares it uses ANTHROPIC_API_KEY while the registry metadata lists no required env vars — an inconsistency in what the skill says it needs vs what the registry claims.
Instruction Scope
The runtime instructions explicitly instruct the agent to create local caches and logs (e.g. ~/.claude_cache/, costs.log, batch_results.jsonl) and give code examples that read and write those files. Those files may contain source code, API responses, or other sensitive data. The SKILL.md tells you not to cache secrets, but the examples do not enforce filtering or encryption; they create persistent files in the user's home directory. The instructions also recommend batching/polling and long-running batch retrievals (external network activity), which is coherent for the purpose but increases the attack/accidental-exfil surface if cache/log contents are sensitive.
Install Mechanism
This is an instruction-only skill with no install spec and no code files to be written by the registry installer — the lowest-risk install model. There is no third-party download or package install step.
Credentials
The SKILL.md metadata and examples use the Anthropic client and reference ANTHROPIC_API_KEY, which is proportional to the skill's purpose. However the declared registry requirements list no required env vars, so the registry metadata does not match the runtime instructions. Also the instructions encourage logging request/response usage — combined with an API key this could expose billing-sensitive or prompt content if logs are shared or misconfigured.
Persistence & Privilege
The skill does not request forced persistent inclusion (always:false) and does not claim elevated platform privileges. But it explicitly instructs creating persistent local files in the user's home directory and adding them to .gitignore. That results in persistent on-disk artifacts controlled by the user’s environment and should be considered when deciding where/when to run the skill.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install claude-api-cost-optimizer
  3. After installation, invoke the skill by name or use /claude-api-cost-optimizer
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.3
Verified metadata: ANTHROPIC_API_KEY correctly declared in requires.env
v1.0.2
Fix: replace bare code blocks with ```text for consistent rendering
v1.0.1
Fix vetter findings: add homepage to metadata, add security note about local cache file permissions and what not to cache
v1.0.0
Initial release — model selection, prompt caching, batching, and cost tracking patterns to cut Claude API costs 70-90%
Metadata
Slug claude-api-cost-optimizer
Version 1.0.3
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 4
Frequently Asked Questions

What is claude-api-cost-optimizer?

Minimize Anthropic Claude API costs through model selection, prompt caching, batching, and cost tracking. Trigger phrases: reduce API costs, optimize Claude... It is an AI Agent Skill for Claude Code / OpenClaw, with 183 downloads so far.

How do I install claude-api-cost-optimizer?

Run "/install claude-api-cost-optimizer" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is claude-api-cost-optimizer free?

Yes, claude-api-cost-optimizer is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does claude-api-cost-optimizer support?

claude-api-cost-optimizer is cross-platform and runs anywhere OpenClaw / Claude Code is available (linux, darwin, win32).

Who created claude-api-cost-optimizer?

It is built and maintained by Deonte Cooper (@djc00p); the current version is v1.0.3.

💬 Comments