Skip to main content
Glama
wn01011

llm-token-tracker

compare_costs

Compare token costs across AI models to analyze pricing differences and optimize API usage for budget management.

Instructions

Compare costs between models

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tokensYesNumber of tokens to compare

Implementation Reference

  • The handler function that executes the compare_costs tool. It simulates token usage for various models using the TokenTracker and compares their costs, returning a formatted comparison string.
    private compareCosts(args: any) { const { tokens } = args; const models = [ { provider: 'openai' as const, model: 'gpt-3.5-turbo', name: 'GPT-3.5' }, { provider: 'openai' as const, model: 'gpt-4', name: 'GPT-4' }, { provider: 'anthropic' as const, model: 'claude-3-haiku-20240307', name: 'Claude Haiku' }, { provider: 'anthropic' as const, model: 'claude-3-sonnet-20240229', name: 'Claude Sonnet' }, { provider: 'anthropic' as const, model: 'claude-3-opus-20240229', name: 'Claude Opus' }, { provider: 'gemini' as const, model: 'gemini-1.5-flash', name: 'Gemini Flash' }, { provider: 'gemini' as const, model: 'gemini-1.5-pro', name: 'Gemini Pro' } ]; const comparison = models.map(({ provider, model, name }) => { const trackingId = this.tracker.startTracking('_compare'); this.tracker.endTracking(trackingId, { provider, model, inputTokens: Math.floor(tokens / 2), outputTokens: Math.ceil(tokens / 2), totalTokens: tokens }); const usage = this.tracker.getUserUsage('_compare'); const cost = usage?.usageByModel[`${provider}/${model}`]?.cost || 0; this.tracker.clearUserUsage('_compare'); return { name, cost }; }).sort((a, b) => a.cost - b.cost); let result = `💰 Cost comparison for ${tokens} tokens:\n\n`; comparison.forEach((item, i) => { const emoji = i === 0 ? '🏆' : i === 1 ? '🥈' : i === 2 ? '🥉' : ' '; result += `${emoji} ${item.name}: ${formatCost(item.cost)}\n`; }); return { content: [{ type: 'text', text: result }] }; }
  • The tool registration in the ListToolsRequestSchema handler, including name, description, and input schema definition.
    { name: 'compare_costs', description: 'Compare costs between models', inputSchema: { type: 'object', properties: { tokens: { type: 'number', description: 'Number of tokens to compare' } }, required: ['tokens'] } },
  • The input schema definition for the compare_costs tool.
    inputSchema: { type: 'object', properties: { tokens: { type: 'number', description: 'Number of tokens to compare' } }, required: ['tokens']

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