Skip to main content
Glama
Log-LogN

langfuse-mcp-java

get_cost_metrics

get_cost_metrics
Destructive

Query Langfuse cost, token, latency, and usage analytics via the Metrics API to monitor and analyze LLM application performance.

Instructions

Query Langfuse cost, token, latency, and usage analytics via the Metrics API. Mirrors: GET /api/public/metrics?query=

Pass the full query as a JSON string. All aggregation is server-side.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ QUERY STRUCTURE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ { "view": string, // REQUIRED. traces | observations | scores-numeric | scores-categorical "metrics": [...], // REQUIRED. At least one { measure, aggregation, alias? } "fromTimestamp": string, // REQUIRED. ISO-8601 e.g. "2026-03-18T00:00:00Z" "toTimestamp": string, // REQUIRED. ISO-8601 e.g. "2026-03-25T23:59:59Z" "dimensions": [...], // Optional. [{ "field": "..." }] "filters": [...], // Optional. [{ "column", "operator", "value", "type", "key"? }] "timeDimension": {...}, // Optional. { "granularity": "hour|day|week|month|auto" } "config": {...} // Optional. { "bins": 10, "row_limit": 100 } }

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ VIEW ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ traces → end-to-end cost, tokens, latency per request observations → per LLM call; USE for model breakdowns (providedModelName) scores-numeric → numeric/boolean evaluation scores scores-categorical → categorical evaluation scores

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ MEASURES (by view) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ traces: count | observationsCount | scoresCount | latency | totalTokens | totalCost observations: count | latency | totalTokens | totalCost | timeToFirstToken | countScores scores-numeric: count | value scores-categorical: count ⚠ NEVER use inputTokens / outputTokens / promptTokens / completionTokens → 400 error. Use totalTokens.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ AGGREGATIONS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ sum | avg | count | max | min | p50 | p75 | p90 | p95 | p99 sum → cost/token totals avg/p95/p99 → latency count → record counts

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ DIMENSIONS (group-by, by view) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ traces: name | tags | userId | sessionId | release | version | environment | observationName | scoreName observations: providedModelName | type | name | level | version | environment | userId | sessionId | traceName | traceRelease | traceVersion | promptName | promptVersion | scoreName ⚠ HIGH CARDINALITY — use in filters only, not dimensions: id | traceId | observationId

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ FILTERS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Each filter: { "column", "operator", "value", "type", "key"? } type string/stringObject/boolean → operator: = | contains | does not contain | starts with | ends with type number/datetime → operator: = | < | > | <= | >= ⚠ NEVER use != / not_contains / not_equals for string fields → 400 error.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ EXAMPLES ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Total cost last 7 days: {"view":"traces","metrics":[{"measure":"totalCost","aggregation":"sum"}], "fromTimestamp":"2026-03-18T00:00:00Z","toTimestamp":"2026-03-25T23:59:59Z"}

Daily cost trend this week: {"view":"traces","metrics":[{"measure":"totalCost","aggregation":"sum"},{"measure":"count","aggregation":"count"}], "timeDimension":{"granularity":"day"}, "fromTimestamp":"2026-03-18T00:00:00Z","toTimestamp":"2026-03-25T23:59:59Z"}

Cost by model: {"view":"observations","dimensions":[{"field":"providedModelName"}], "metrics":[{"measure":"totalCost","aggregation":"sum"},{"measure":"totalTokens","aggregation":"sum"}], "fromTimestamp":"2026-03-18T00:00:00Z","toTimestamp":"2026-03-25T23:59:59Z"}

Cost for a specific user: {"view":"traces","metrics":[{"measure":"totalCost","aggregation":"sum"}], "filters":[{"column":"userId","operator":"=","value":"user-123","type":"string"}], "fromTimestamp":"2026-03-18T00:00:00Z","toTimestamp":"2026-03-25T23:59:59Z"}

Production environment only: filters: [{"column":"environment","operator":"=","value":"production","type":"string"}]

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesFull metrics query as a JSON string. Required. Structure: { "view", "metrics", "fromTimestamp", "toTimestamp", "dimensions"?, "filters"?, "timeDimension"?, "config"? } See tool description for allowed values per field. Example: {"view":"traces","metrics":[{"measure":"totalCost","aggregation":"sum"}],"fromTimestamp":"2026-03-18T00:00:00Z","toTimestamp":"2026-03-25T23:59:59Z"}
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Description states 'Mirrors: GET /api/public/metrics' and frames as a read query, but annotations declare destructiveHint=true and readOnlyHint=false. This is a direct contradiction regarding the safety profile of the operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Extremely verbose with heavy ASCII art separators consuming tokens. While the detailed examples and field documentation are necessary for the complex JSON DSL, the formatting is inefficient for LLM context windows and could be compressed.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite rich input documentation, there is zero description of return values or response structure, and no output schema is present. For a metrics aggregation tool, this omission leaves the agent blind to what data structure will be returned.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Despite 100% schema coverage for the single 'query' parameter, the description adds massive value by detailing the JSON structure's internal semantics: valid enums for views, measures by view type, aggregation functions, dimension fields, and filter operators with explicit constraints.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with specific verb 'Query' and precise resource 'Langfuse cost, token, latency, and usage analytics via the Metrics API', clearly distinguishing this aggregation-focused tool from sibling fetch/get tools that retrieve raw records.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Extensive internal guidance provided: explicit view selection guidance ('USE for model breakdowns'), measure/aggregation mapping ('sum → cost/token totals'), and critical constraints ('⚠ NEVER use inputTokens...'). Lacks explicit comparison to siblings like fetch_traces.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Log-LogN/langfuse-mcp-java'

If you have feedback or need assistance with the MCP directory API, please join our Discord server