langfuse-cost-tuning

Featured

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".

AI & Automation 2,944 stars 440 forks Updated today MIT

Install

View on GitHub

Quality Score: 99/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Langfuse Cost Tuning ## Overview Track, analyze, and optimize LLM costs using Langfuse's built-in token/cost tracking, the Metrics API for programmatic cost analysis, model routing for cost reduction, and automated budget alerts. ## Prerequisites - Langfuse tracing with token usage captured (via `observeOpenAI` or manual `usage` fields) - For Metrics API: `@langfuse/client` installed - Understanding of LLM pricing models ## How Langfuse Tracks Costs Langfuse automatically calculates costs for supported models (OpenAI, Anthropic, Google) when token usage is captured. For custom models, you can configure pricing in the Langfuse UI under **Settings > Model Definitions**. Cost tracking works on observations of type **generation** and **embedding**. The `observeOpenAI` wrapper captures usage automatically; for manual tracing, include `usage` in your observation updates. ## Instructions ### Step 1: Ensure Token Usage is Captured ```typescript // Automatic: observeOpenAI captures everything import { observeOpenAI } from "@langfuse/openai"; const openai = observeOpenAI(new OpenAI()); // Tokens, model, latency, and cost are all auto-tracked // Manual: include usage in generation observations import { startActiveObservation, updateActiveObservation } from "@langfuse/tracing"; await startActiveObservation( { name: "llm-call", asType: "generation" }, async () => { updateActiveObservation({ model: "gpt-4o" }); // Model required for cost calc const response = await...

Details

Author
jeremylongshore
Repository
jeremylongshore/claude-code-plugins-plus-skills
Created
1 years ago
Last Updated
today
Language
Python
License
MIT

Integrates with

Bundled in these plugins

Similar Skills

Semantically similar based on skill content — not just same category