llmkit_usage_stats
Read-onlyIdempotent
Track AI spending, analyze request patterns, and monitor top models across multiple providers for specified time periods.
Instructions
Get usage statistics (spend, requests, top models) for a time period
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| period | No | Time period | month |
Output Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| period | Yes | ||
| requests | Yes | ||
| topModels | No | ||
| inputTokens | No | ||
| cacheHitRate | No | ||
| outputTokens | No | ||
| totalSpendUsd | Yes | ||
| cacheReadTokens | No |
Implementation Reference
- Handler function for llmkit_usage_stats that calculates and formats usage statistics.
export async function handleUsageStats(args: Record<string, unknown> | undefined) { const period = (args?.period as string) || 'month'; const usage = await getUsage(period); const spend = cents(usage.totalCostCents); return ok([ `LLMKit Usage (${period})`, '\u2500'.repeat(25), `Requests: ${usage.requests}`, `Total spend: $${spend.toFixed(2)}`, `Input tokens: ${usage.totalInputTokens.toLocaleString()}`, `Output tokens: ${usage.totalOutputTokens.toLocaleString()}`, `Cache read tokens: ${usage.totalCacheReadTokens.toLocaleString()}`, `Cache hit rate: ${usage.cacheHitRate}%`, '', 'Top models:', ...usage.topModels.map(m => ` ${m.model}: ${m.requests} requests`), ].join('\n'), { period, requests: usage.requests, totalSpendUsd: spend, inputTokens: usage.totalInputTokens, outputTokens: usage.totalOutputTokens, cacheReadTokens: usage.totalCacheReadTokens, cacheHitRate: usage.cacheHitRate, topModels: usage.topModels, }); } - Definition of llmkit_usage_stats tool schema including name, description, input/output schemas, and annotations.
const PROXY_TOOLS = [ { name: 'llmkit_usage_stats', description: 'Get usage statistics (spend, requests, top models) for a time period', inputSchema: { type: 'object' as const, properties: { period: { type: 'string', enum: ['today', 'week', 'month'], description: 'Time period', default: 'month' }, }, }, outputSchema: { type: 'object' as const, properties: { period: { type: 'string' }, requests: { type: 'number' }, totalSpendUsd: { type: 'number' }, inputTokens: { type: 'number' }, outputTokens: { type: 'number' }, cacheReadTokens: { type: 'number' }, cacheHitRate: { type: 'number' }, topModels: { type: 'array', items: { type: 'object', properties: { model: { type: 'string' }, requests: { type: 'number' } } } }, }, required: ['period', 'requests', 'totalSpendUsd'], }, annotations: { title: 'Usage Stats', ...HINTS }, }, - packages/mcp-server/src/tools.ts:292-292 (registration)Registration of llmkit_usage_stats in the HANDLER_MAP to associate it with handleUsageStats.
llmkit_usage_stats: handleUsageStats,