Skip to main content
Glama
wn01011

llm-token-tracker

get_usage

Track and monitor token usage across OpenAI and Claude APIs to manage costs and optimize API consumption.

Instructions

Get usage summary

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
user_idNoUser ID (optional)

Implementation Reference

  • The main handler function for the 'get_usage' tool. Retrieves and formats usage summary for a specific user_id or all users if not provided.
    private getUsage(args: any) { const { user_id } = args; if (user_id) { const usage = this.tracker.getUserUsage(user_id); if (!usage) { return { content: [{ type: 'text', text: `No usage data for ${user_id}` }] }; } let summary = `πŸ“Š Usage Summary for ${user_id}\n`; summary += `Total: ${usage.totalTokens} tokens (${formatCost(usage.totalCost)})\n\n`; Object.entries(usage.usageByModel).forEach(([model, data]) => { summary += `${model}: ${data.tokens} tokens (${formatCost(data.cost)})\n`; }); return { content: [{ type: 'text', text: summary }] }; } else { const allUsage = this.tracker.getAllUsersUsage(); let summary = 'πŸ“Š All Users:\n'; allUsage.forEach(user => { summary += `${user.userId}: ${user.totalTokens} tokens (${formatCost(user.totalCost)})\n`; }); return { content: [{ type: 'text', text: summary || 'No usage data' }] }; } }
  • Defines the tool name, description, and input schema (optional user_id) for 'get_usage' in the ListTools response.
    { name: 'get_usage', description: 'Get usage summary', inputSchema: { type: 'object', properties: { user_id: { type: 'string', description: 'User ID (optional)' } } } },
  • Dispatches to the getUsage handler method in the CallToolRequestHandler switch statement.
    case 'get_usage': return this.getUsage(request.params.arguments);

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/wn01011/llm-token-tracker'

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