query_llm_metrics
Query LLM metrics from Langfuse by time range with filters for trace name, user ID, tags, and environment. Retrieve paginated results to monitor and analyze LLM performance.
Instructions
Query LLM metrics
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fromTimestamp | No | Start timestamp in ISO 8601 format | |
| toTimestamp | No | End timestamp in ISO 8601 format | |
| page | No | Page number (default 1) | |
| limit | No | limit (default 100) | |
| traceName | No | Trace name | |
| userId | No | User ID, it's can filter by user | |
| tags | No | Tags | |
| environment | No | Environment |
Implementation Reference
- index.ts:14-23 (schema)Interface defining the input arguments for query_llm_metrics tool (fromTimestamp, toTimestamp, page, limit, traceName, userId, tags, environment).
interface QueryLLMMetricsArgs { fromTimestamp: string; // ISO 8601 format toTimestamp: string; // ISO 8601 format page?: number; // default 1 limit?: number; // default 100 traceName?: string; userId?: string; tags?: string[]; environment?: string[]; } - index.ts:26-74 (registration)Tool definition object for 'query_llm_metrics' including name, description, and inputSchema with property definitions.
const queryLLMMetricsTool: Tool = { name: "query_llm_metrics", description: "Query LLM metrics", inputSchema: { type: "object", properties: { fromTimestamp: { type: "string", description: "Start timestamp in ISO 8601 format", }, toTimestamp: { type: "string", description: "End timestamp in ISO 8601 format", }, page: { type: "number", description: "Page number (default 1)", default: 1, }, limit: { type: "number", description: "limit (default 100)", default: 100, }, traceName: { type: "string", description: "Trace name", }, userId: { type: "string", description: "User ID, it's can filter by user", }, tags: { type: "array", items: { type: "string", }, description: "Tags", }, environment: { type: "array", items: { type: "string", }, description: "Environment", }, }, }, }; - index.ts:97-118 (handler)Handler method 'getLLMMetricsByTimeRange' on LanfuseClient class that performs the actual API call to /api/public/metrics/daily with query parameters.
async getLLMMetricsByTimeRange(payload: QueryLLMMetricsArgs): Promise<any> { const params = new URLSearchParams({ fromTimestamp: payload.fromTimestamp, toTimestamp: payload.toTimestamp, page: payload.page?.toString() || '1', limit: payload.limit?.toString() || '100', traceName: payload.traceName || '', userId: payload.userId || '', tags: payload.tags?.join(',') || '', environment: payload.environment?.join(',') || '', }); const response = await fetch( `${this.domain}/api/public/metrics/daily?${params}`, { headers: this.apiHeader, method: 'GET' } ); return response.json(); } - index.ts:160-169 (handler)Case handler in the CallToolRequest switch that dispatches 'query_llm_metrics', casts arguments, calls getLLMMetricsByTimeRange, and returns JSON response.
case "query_llm_metrics": { const args = request.params .arguments as unknown as QueryLLMMetricsArgs; const response = await slackClient.getLLMMetricsByTimeRange( args, ); return { content: [{ type: "text", text: JSON.stringify(response) }], }; } - index.ts:189-196 (registration)ListToolsRequest handler that registers queryLLMMetricsTool in the list of available tools returned to the client.
server.setRequestHandler(ListToolsRequestSchema, async () => { console.error("Received ListToolsRequest"); return { tools: [ queryLLMMetricsTool, ], }; });