infopibe/everything-claude-code/cost-aware-llm-pipeline
Trust tier 3
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
LLM API 使用成本优化模式 —— 基于任务复杂度的模型路由、预算跟踪、重试逻辑和提示缓存。
Install
npx vskill@latest install infopibe/everything-claude-code/cost-aware-llm-pipelineSKILL.md
The same SKILL.md was published earlier as boyapati13/octo/cost-aware-llm-pipeline.
成本感知型 LLM 流水线
在保持质量的同时控制 LLM API 成本的模式。将模型路由、预算跟踪、重试逻辑和提示词缓存组合成一个可组合的流水线。
何时激活
- 构建调用 LLM API(Claude、GPT 等)的应用程序时
- 处理具有不同复杂度的批量项目时
- 需要将 API 支出控制在预算范围内时
- 需要在复杂任务上优化成本而不牺牲质量时
核心概念
1. 根据任务复杂度进行模型路由
自动为简单任务选择更便宜的模型,为复杂任务保留昂贵的模型。
2. 不可变的成本跟踪
使用冻结的数据类跟踪累计支出。每个 API 调用都会返回一个新的跟踪器 —— 永不改变状态。
3. 窄范围重试逻辑
仅在暂时性错误时重试。对于认证或错误请求错误,快速失败。
4. 提示词缓存
缓存长的系统提示词,以避免在每个请求上重新发送它们。
组合
将所有四种技术组合到一个流水线函数中:
价格参考(2025-2026)
| 模型 | 输入(美元/百万令牌) | 输出(美元/百万令牌) | 相对成本 | |
|---|---|---|---|---|
| Haiku 4.5 | $0.80 | $4.00 | 1x | |
| Sonnet 4.6 | $3.00 | $15.00 | ~4x | |
| Opus 4.5 | $15.00 | $75.00 | ~19x |
最佳实践
- 从最便宜的模型开始,仅在达到复杂度阈值时才路由到昂贵的模型
- 在处理批次之前设置明确的预算限制 —— 尽早失败而不是超支
- 记录模型选择决策,以便您可以根据实际数据调整阈值
- 对于超过 1024 个令牌的系统提示词,使用提示词缓存 —— 既能节省成本,又能降低延迟
- 切勿在认证或验证错误时重试 —— 仅针对暂时性故障(网络、速率限制、服务器错误)重试
应避免的反模式
- 无论复杂度如何,对所有请求都使用最昂贵的模型
- 对所有错误都进行重试(在永久性故障上浪费预算)
- 改变成本跟踪状态(使调试和审计变得困难)
- 在整个代码库中硬编码模型名称(使用常量或配置)
- 对重复的系统提示词忽略提示词缓存
适用场景
- 任何调用 Claude、OpenAI 或类似 LLM API 的应用程序
- 成本快速累积的批处理流水线
- 需要智能路由的多模型架构
- 需要预算护栏的生产系统
Security
- Security scanPassed, 90 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 repositoryCheckingdocs/zh-CN/skills/cost-aware-llm-pipeline/SKILL.md
Popularity
- 7-day trend score
- 0
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/infopibe/everything-claude-code/cost-aware-llm-pipeline)