AGENT SKILL

langfuse-cost-tuning

Monitor and optimize LLM costs using Langfuse analytics and dashboards. Use when tracking LLM spending, identifying cost anomalies, or implementing cost controls for AI applications. Trigger with phrases like "langfuse costs", "LLM spending", "track AI costs", "langfuse token usage", "optimize LLM budget".

License 许可
MIT
最近更新
2026-05-26
Stars
★ 0
Forks
0

01 前言 Front Matter

name
langfuse-cost-tuning
author
Jeremy Longshore <jeremy@intentsolutions.io>
license
MIT
version
1.0.0
description
Monitor and optimize LLM costs using Langfuse analytics and dashboards. Use when tracking LLM spending, identifying cost anomalies, or implementing cost controls for AI applications. Trigger with phrases like "langfuse costs", "LLM spending", "track AI costs", "langfuse token usage", "optimize LLM budget".
allowed-tools
Read, Write, Edit
compatible-with
claude-code, codex, openclaw

02 资源文件 1

03 SKILL.md 正文

Langfuse Cost Tuning

Contents

Overview

Track, analyze, and optimize LLM costs using Langfuse observability data with token tracking, cost alerts, model selection optimization, and automated reporting.

Prerequisites

  • Langfuse tracing with token usage
  • Understanding of LLM pricing models
  • Access to Langfuse analytics dashboard

Instructions

Step 1: Track Token Usage in Generations

Record prompt and completion tokens on each generation.end() call. Calculate cost using per-model pricing tables and store as metadata.

Step 2: Create Cost Dashboard Queries

Fetch generations from Langfuse and aggregate costs by model, by day, and by token type. Calculate total cost and generation count.

Step 3: Implement Cost Alerts

Build a CostMonitor that tracks hourly and daily spend. Define thresholds (e.g., $100/day warn, $500/day notify, $1/request warn). Send Slack/PagerDuty notifications on breaches.

Step 4: Optimize Model Selection

Route simple tasks (summarize, classify, extract) and short inputs to cheaper models (GPT-4o-mini). Reserve expensive models for complex tasks (analyze, reason, code).

Step 5: Add Caching and Prompt Optimization

Cache LLM responses with TTL. Strip redundant whitespace and filler words from prompts to reduce token count.

See detailed implementation for advanced patterns.

Output

  • Token usage tracking per generation
  • Cost analytics aggregation
  • Real-time cost alerts
  • Smart model selection
  • Response caching and prompt optimization

Error Handling

Issue Cause Solution
Missing usage data SDK not capturing Verify generation.end() includes usage
Inaccurate costs Wrong pricing Update MODEL_PRICING regularly
Budget exceeded No alerts Implement cost alerts
Report failures API limits Add pagination to fetchGenerations

Examples

LLM Cost Reference

Model Input (per 1M) Output (per 1M)
GPT-4 Turbo $10.00 $30.00
GPT-4o $5.00 $15.00
GPT-4o-mini $0.15 $0.60
Claude 3 Opus $15.00 $75.00
Claude 3 Sonnet $3.00 $15.00
Claude 3 Haiku $0.25 $1.25

Cost Optimization Strategies

Strategy Potential Savings Effort
Model downgrade 50-90% Low
Prompt optimization 10-30% Low
Response caching 20-60% Medium
Batch processing 10-20% Medium

Resources

04 同仓库更多 Skills

SamuelChien
SamuelChien/mega-skills-collection

zustand-store-ts

Create Zustand stores with TypeScript, subscribeWithSelector middleware, and proper state/action separation. Use when building React state management, creating global stores, or implementing reactive state patterns with Zustand.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

zustand-store-creator

Zustand Store Creator - Auto-activating skill for Frontend Development. Triggers on: zustand store creator, zustand store creator Part of the Frontend Development skill category.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

zero-trust-config-helper

Zero Trust Config Helper - Auto-activating skill for Security Advanced. Triggers on: zero trust config helper, zero trust config helper Part of the Security Advanced skill category.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

zapier-integration-helper

Zapier Integration Helper - Auto-activating skill for Business Automation. Triggers on: zapier integration helper, zapier integration helper Part of the Business Automation skill category.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

zai-cli

Execute z.AI CLI providing vision, search, reader, and GitHub exploration via CLI and MCP. Use when user needs image/video analysis, OCR, UI-to-code conversion, error diagnosis, real-time web search, web page to markdown extraction, or GitHub code exploration. Trigger with phrases like "analyze this image", "search the web for", "read this page", "explore this repo", or "use zai". Requires Z_AI_API_KEY.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

yt-research

Research competitor YouTube channels, niches, and trending topics for your content strategy. Use this skill whenever the user says "research channels", "analyze competitors", "find trending topics", "niche analysis", "competitive research", "what are other creators doing", "scrape YouTube channels", or wants to understand the competitive landscape for a specific tool or topic area. Use when working with yt research. Trigger with 'yt', 'research'.

★ 0