Skip to main content
Glama
wn01011

llm-token-tracker

compare_costs

Compare pricing between different AI models to optimize token usage and manage API costs effectively.

Instructions

Compare costs between models

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tokensYesNumber of tokens to compare

Implementation Reference

  • The main handler function that implements the compare_costs tool. It simulates token usage for various models using the TokenTracker, calculates costs, sorts them, and returns a formatted comparison.
    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 }] }; }
  • Input schema for the compare_costs tool, requiring a 'tokens' number parameter.
    inputSchema: { type: 'object', properties: { tokens: { type: 'number', description: 'Number of tokens to compare' } }, required: ['tokens'] }
  • Tool registration in the ListTools response, including name, description, and input schema.
    { name: 'compare_costs', description: 'Compare costs between models', inputSchema: { type: 'object', properties: { tokens: { type: 'number', description: 'Number of tokens to compare' } }, required: ['tokens'] } },
  • Dispatch case in the CallToolRequest handler that routes to the compareCosts method.
    case 'compare_costs': return this.compareCosts(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