llm-cost-optimization
Fungsinya
Tool ini membantu menurunkan biaya penggunaan kecerdasan buatan (AI). Tool ini memberikan saran cara memakai model AI dengan lebih murah, seperti memilih model yang tepat untuk setiap tugas, menyimpan jawaban yang sering dipakai agar tidak perlu ditanyakan lagi (caching), dan mengelompokkan beberapa permintaan agar dijawab sekaligus.
Kapan dipakai
- βSaat pengeluaran untuk AI meningkat dengan cepat.
- βJika Anda perlu melacak biaya AI per tim atau per produk.
- βSaat ingin menghindari pertanyaan yang sama berulang kali ke AI.
Link skill
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/llm-cost-optimization/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βBagaimana cara memakai model AI yang lebih murah untuk pertanyaan sederhana?β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Tool ini menganalisis cara Anda menggunakan AI dan memberikan saran optimasi. Ini mencakup penggunaan model yang lebih kecil dan lebih murah untuk tugas-tugas mudah, menyimpan jawaban agar tidak perlu dibuat ulang, dan mengelompokkan tugas untuk diproses sekaligus (batch processing).
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
LLM Cost Optimization
Cut LLM costs by 50β90% with the right combination of caching, model selection, prompt optimization, and self-hosting.
When to Use This Skill
Use this skill when:
- LLM API spend is growing faster than revenue
- You need to attribute AI costs to teams, products, or customers
- Implementing caching to avoid redundant LLM calls
- Deciding when to switch from API providers to self-hosted models
- Optimizing prompt length without sacrificing quality
Cost Levers by Impact
| Strategy | Typical Savings | Effort |
|---|---|---|
| Semantic caching | 20β50% | Low |
| Model right-sizing | 30β70% | Low |
| Prompt compression | 10β30% | Medium |
| Provider caching (prompt cache) | 10β25% | Low |
| Batching offline workloads | 50% (Batch API) | Medium |
| Self-hosting 7β8B models | 80β95% at scale | High |
| Quantization | 30β50% VRAM cost | Medium |
Track Costs First
# Use LiteLLM's cost tracking (automatic per-model pricing)
import litellm
response = litellm.completion(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello"}],
)
cost = litellm.completion_cost(response)
print(f"Cost: ${cost:.6f}")
# Add custom cost callbacks
def log_cost(kwargs, completion_response, start_time, end_time):
cost = kwargs.get("response_cost", 0)
model = kwargs.get("model")
user = kwargs.get("user")
# Send to your analytics DB
db.record_cost(user=user, model=model, cost=cost)
litellm.success_callback = [log_cost]
Model Right-Sizing
# Route by task complexity β don't use GPT-4o for everything
def get_model_for_task(task_type: str) -> str:
routing = {
"classification": "gpt-4o-mini", # ~30Γ cheaper than gpt-4o
"summarization": "gpt-4o-mini",
"extraction": "gpt-4o-mini",
"simple_qa": "gpt-4o-mini",
"complex_reasoning": "gpt-4o",
"code_generation": "claude-sonnet-4-6",
"creative_writing": "claude-opus-4-6",
}
return routing.get(task_type, "gpt-4o-mini")
# Cost comparison (per 1M tokens, 2025 approx.)
# gpt-4o-mini: input $0.15 / output $0.60
# gpt-4o: input $2.50 / output $10.00
# claude-sonnet-4-6: input $3.00 / output $15.00
# llama-3.1-8b (self): ~$0.05β0.10 all-in (GPU amortized)
Prompt Caching (Provider-Side)
# Anthropic β cache long system prompts (saves 90% on cached tokens)
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
system=[
{
"type": "text",
"text": "You are a helpful assistant.",
},
{
"type": "text",
"text": open("large-context.txt").read(), # large doc
"cache_control": {"type": "ephemeral"}, # cache this!
}
],
messages=[{"role": "user", "content": "Summarize the key points."}],
)
# First call: full price. Subsequent calls: 90% discount on cached part.
print(f"Cache read tokens: {response.usage.cache_read_input_tokens}")
# OpenAI β prompt caching is automatic for repeated prefixes >1024 tokens
# No code change needed; check usage.prompt_tokens_details.cached_tokens
Batching with OpenAI Batch API (50% Discount)
import json
from openai import OpenAI
client = OpenAI()
# Prepare batch requests
requests = [
{
"custom_id": f"task-{i}",
"method": "POST",
"url": "/v1/chat/completions",
"body": {
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": f"Classify: {text}"}],
"max_tokens": 50,
}
}
for i, text in enumerate(texts)
]
# Write JSONL file
with open("batch.jsonl", "w") as f:
for req in requests:
f.write(json.dumps(req) + "\n")
# Upload and create batch
batch_file = client.files.create(file=open("batch.jsonl", "rb"), purpose="batch")
batch = client.batches.create(
input_file_id=batch_file.id,
endpoint="/v1/chat/completions",
completion_window="24h",
)
print(f"Batch ID: {batch.id}") # poll status with client.batches.retrieve(batch.id)
Semantic Caching
import hashlib
import json
import redis
import numpy as np
from sentence_transformers import SentenceTransformer
r = redis.Redis(host="localhost", port=6379)
embed_model = SentenceTransformer("BAAI/bge-small-en-v1.5")
SIMILARITY_THRESHOLD = 0.92
β¦
Pertanyaan umum
Apa itu 'caching'?
Caching seperti memori cepat. Jika AI pernah menjawab sebuah pertanyaan, ia bisa memakai jawaban yang sudah tersimpan itu alih-alih berpikir ulang, sehingga menghemat waktu dan biaya.
Apa itu 'model right-sizing'?
Artinya memilih model AI yang tepat untuk pekerjaan tersebut. Menggunakan model yang sangat canggih untuk tugas sederhana ibarat memakai truk untuk membeli roti: biayanya lebih mahal dari yang diperlukan. Tool ini membantu memilih 'ukuran' yang pas.
Apa itu 'batching'?
Batching adalah mengelompokkan beberapa tugas atau permintaan menjadi satu paket untuk diproses bersama. Cara ini lebih efisien dibanding memproses satu per satu, seperti mengirim sekumpulan surat sekaligus, bukan satu per satu.
Detail
Deskripsi asli dari pembuat
Reduce LLM API and infrastructure costs through model selection, prompt caching, batching, caching, quantization, and self-hosting strategies.
Popularitas
- Bintang GitHub
- 48k
- Peringkat
- #5082
- Lisensi
- MIT
- Diperbarui
- 15/10/2026
Komentar
- β¦
Skill lain dari repositori ini
00-andruia-consultant
48kMembantu agent Anda memulai atau meningkatkan proyek AI. Agent menganalisis kode, menyarankan tools, dan membuat rencana aksi dalam bahasa Spanyol.
007
48kMemungkinkan agent Anda melakukan audit keamanan dan threat modeling. Berguna untuk melindungi proyek dari serangan dan celah keamanan.
10-andruia-skill-smith
48kMembantu agent Anda membuat atau meningkatkan tools AI. Agent mendefinisikan cara kerja tools, menulis dokumentasi, dan memvalidasi strukturnya.
20-andruia-niche-intelligence
48kMemungkinkan agent Anda membuat ringkasan industri tertentu. Berguna untuk memahami konteks, aturan, pola penggunaan, dan risiko proyek dengan sumber terpercaya.
Skill serupa
add-model-provider
394kMemungkinkan agent Anda menghubungkan penyedia model AI baru ke OpenClaw dengan perintah pengaturan yang aman, menjaga kunci API tetap di luar teks biasa, dan menjalankan uji langsung.
acp-router
394kMembantu agent Anda mengirim tugas ke asisten pemrograman seperti Claude Code atau Cursor lewat OpenClaw, sehingga pekerjaan dijalankan di alat tersebut.
browser-automation
394kMengajari agent Anda mengendalikan halaman web langkah demi langkah, termasuk login, tab, dan pemulihan saat halaman berhenti merespons.