← 返回 Skills 市场
claude-api-cost-optimizer
作者
Deonte Cooper
· GitHub ↗
· v1.0.3
· MIT-0
183
总下载
0
收藏
0
当前安装
4
版本数
在 OpenClaw 中安装
/install 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...
使用说明 (SKILL.md)
Claude API Cost Optimizer
Cut Claude API costs by 70–90% using intelligent model selection, caching, and batching.
Quick Start
- 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.
- Pick the cheapest model tier for each task: Haiku (cheapest) → Sonnet (mid) → Opus (most expensive, use sparingly). See
references/pricing.mdfor current rates. - Enable prompt caching for repeated context (system prompts, codebases) by adding
"cache_control": {"type": "ephemeral"}to message blocks - 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.mdfor 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-patternsreferences/pricing.md— Current pricing, cache cost math, savings calculations, and batch API details
安全使用建议
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.
功能分析
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.
能力标签
能力评估
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.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install claude-api-cost-optimizer - 安装完成后,直接呼叫该 Skill 的名称或使用
/claude-api-cost-optimizer触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
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%
元数据
常见问题
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... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 183 次。
如何安装 claude-api-cost-optimizer?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install claude-api-cost-optimizer」即可一键安装,无需额外配置。
claude-api-cost-optimizer 是免费的吗?
是的,claude-api-cost-optimizer 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
claude-api-cost-optimizer 支持哪些平台?
claude-api-cost-optimizer 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(linux, darwin, win32)。
谁开发了 claude-api-cost-optimizer?
由 Deonte Cooper(@djc00p)开发并维护,当前版本 v1.0.3。
推荐 Skills