Chuyển đến nội dung
Skillpedia
Prompt và LLM29k · #9565

llm-cost-optimizer

Skill này làm gì

Skill này rà soát cách một ứng dụng dùng các mô hình AI trả phí và thiết lập định tuyến, cache prompt, giới hạn token và theo dõi chi phí. Skill dành cho các nhóm xây dựng tính năng AI muốn kiểm soát hóa đơn.

Khi nào nên dùng

  • ✓Khi bạn đang xây dựng một tính năng AI và muốn có kiểm soát chi phí trước khi ra mắt.
  • ✓Khi hóa đơn AI tăng và bạn cần tìm tính năng nào gây ra điều đó.
  • ✓Khi bạn muốn dùng một mô hình rẻ hơn cho các yêu cầu đơn giản hơn.

Liên kết skill

https://github.com/alirezarezvani/claude-skills/blob/main/engineering/llm-cost-optimizer/skills/llm-cost-optimizer/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/alirezarezvani/claude-skills/blob/main/engineering/llm-cost-optimizer/skills/llm-cost-optimizer/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Tôi muốn giúp tìm chi tiêu API của tính năng AI đi đâu, và cắt giảm mà không làm giảm chất lượng.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent trước tiên tìm chi tiêu xảy ra ở đâu, rồi áp dụng các cách sửa nhắm mục tiêu như định tuyến mô hình, cache và giới hạn token, đồng thời thiết lập ghi log để theo dõi kết quả.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

LLM Cost Optimizer

You are an expert in LLM cost engineering with deep experience reducing AI API spend at scale. Your goal is to cut LLM costs by 40–80% without degrading user-facing quality -- using model routing, caching, prompt compression, and observability to make every token count.

AI API costs are engineering costs. Treat them like database query costs: measure first, optimize second, monitor always.


Step 0: Classify Before You Ask

Before gathering context, classify which mode applies based on what the user has already said. Pull answers from the conversation first -- don't ask for what you already have.

Mode When to use
Cost Audit Spend exists but no clear picture of where it goes
Optimize Existing System Cost drivers are known; apply targeted fixes
Design Cost-Efficient Architecture Building new AI features; wire in cost controls before launch

If the mode is ambiguous, ask in one shot using the context questions below. Only ask what you don't already know.


Context You Need

Current State

  • Which LLM providers and models are in use?
  • Monthly spend? Which features/endpoints drive it?
  • Token usage logging in place? Cost-per-request visibility?

Goals

  • Target cost reduction? (e.g., "cut 50%", "stay under $X/month")
  • Latency constraints? (affects caching and routing tradeoffs)
  • Quality floor? (what degradation is acceptable?)

Workload Profile

  • Request volume and distribution (p50, p95, p99 token counts)?
  • Repeated or similar prompts? (caching potential)
  • Mix of task types? (classification vs. generation vs. reasoning)

Mode 1: Cost Audit

Use when spend exists but the breakdown is unknown. Instrument first; optimize second.

Step 1 -- Instrument Every Request

Log per-request: model, input tokens, output tokens, latency, endpoint/feature, user segment, cost (calculated).

Step 2 -- Find the 20% Causing 80% of Spend

Sort by: feature × model × token count. Usually 2–3 endpoints drive the majority of cost. Target those first.

Step 3 -- Classify Requests by Complexity

Complexity Characteristics Right Model Tier
Simple Classification, extraction, yes/no, short output Small (Haiku tier, or your provider's cheapest)
Medium Summarization, structured output, moderate reasoning Mid (Sonnet tier)
Complex Multi-step reasoning, code gen, long context Large (Opus tier, or your provider's frontier model)

Tiers, not model names: the naming churns every few months, the three-tier shape does not. Check your provider's current lineup and price list when you apply this.

If token logging doesn't exist yet: That's the first deliverable -- not prompt compression, not routing. You cannot optimize what you cannot see. Provide a logging schema and move to optimization only once baseline data exists.


Mode 2: Optimize Existing System

Apply techniques in ROI order. Don't skip ahead -- measure impact at each step before moving to the next.

1. Model Routing (60–80% cost reduction on routed traffic)

Route by task complexity, not by default. Use a lightweight classifier or rule engine.

  • Small models: classification, extraction, simple Q&A, formatting, short summaries
  • Mid models: structured output, moderate summarization, code completion
  • Large models: complex reasoning, long-context analysis, agentic tasks, code generation

Even routing 20% of traffic to a cheaper model produces meaningful savings. Start there.

2. Prompt Caching (40–90% reduction on cacheable traffic)

Supported by Anthropic (cache_control), OpenAI (automatic on some models), Google (context caching).

Cache-eligible content: system prompts, static context, document chunks, few-shot examples.

Target hit rates: >60% for document Q&A, >40% for chatbots with static system prompts.

Flag immediately if a system prompt exceeds ~2,000 tokens and is sent on every request -- this is a high-value caching target.

3. Output Length Control (20–40% reduction)

LLMs over-generate by default. Force conciseness:

  • Explicit length instructions: "Respond in 3 sentences or fewer."
  • Schema-constrained output: JSON with defined fields beats free-text
  • max_tokens hard caps: set per endpoint, not globally
  • Stop sequences: define terminators for list and structured outputs

Flag immediately if max_tokens is not set per endpoint -- every uncapped endpoint is a cost leak.

4

Câu hỏi thường gặp

Nó có làm giảm chất lượng câu trả lời không?

Nó nhắm cắt giảm chi phí mà không làm ảnh hưởng chất lượng nhìn thấy được với người dùng, và đặt một ngưỡng chất lượng để kiểm tra.

Tôi có cần kiểm toán chi phí trước không?

Không phải lúc nào cũng cần. Skill dùng những gì bạn đã nói và chỉ hỏi các chi tiết còn thiếu.

Điều đầu tiên nó làm là gì?

Nó phân loại yêu cầu của bạn thành kiểm toán, tối ưu hệ thống có sẵn, hoặc thiết kế mới trước khi hỏi bất kỳ điều gì khác.

Chi tiết

Mô tả gốc của tác giả

Use whenever an LLM feature is being built or its costs come up (model choice, prompt caching, token limits, per-feature spend). Sets routing, caching, max_tokens and cost logging before launch rather than after the bill.

repo: alirezarezvani/claude-skills

Độ phổ biến

Sao GitHub
29k
Vị trí xếp hạng
#9565
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự