Skip to main content
Glama

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
NameRequiredDescriptionDefault
periodNoTime periodmonth

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
periodYes
requestsYes
topModelsNo
inputTokensNo
cacheHitRateNo
outputTokensNo
totalSpendUsdYes
cacheReadTokensNo

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 },
      },
  • Registration of llmkit_usage_stats in the HANDLER_MAP to associate it with handleUsageStats.
    llmkit_usage_stats: handleUsageStats,

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/smigolsmigol/llmkit-mcp-server'

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