compare_pricing
Find the cheapest AI model for your workload by comparing costs based on input and output tokens. Filter by provider or model family, and rank results to identify the lowest price.
Instructions
Rank AI models by total cost for a given token workload. Useful for finding the cheapest model for your use case.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input_tokens | Yes | Number of input tokens per request | |
| output_tokens | No | Number of output tokens per request | |
| filter | No | Narrow to a provider or model family — e.g. "claude", "gpt", "gemini" | |
| top | No | Show only the N cheapest models (default 10) |
Implementation Reference
- src/index.ts:228-281 (registration)Registration of the 'compare_pricing' tool via server.tool() with name 'compare_pricing' and description 'Rank AI models by total cost for a given token workload.'
server.tool( 'compare_pricing', 'Rank AI models by total cost for a given token workload. Useful for finding the cheapest model for your use case.', { input_tokens: z.number().int().min(1).describe('Number of input tokens per request'), output_tokens: z.number().int().min(0).default(0).describe('Number of output tokens per request'), filter: z.string().optional().describe('Narrow to a provider or model family — e.g. "claude", "gpt", "gemini"'), top: z.number().int().min(1).max(30).optional().describe('Show only the N cheapest models (default 10)'), }, async ({ input_tokens, output_tokens, filter, top = 10 }) => { const data = await fetchJSON<{ models: PricingRow[] }>('/pricing') let models = data.models if (filter) { const q = filter.toLowerCase() models = models.filter( (m) => m.model_name.toLowerCase().includes(q) || m.tool_name.toLowerCase().includes(q) ) } const ranked = models .map((m) => ({ ...m, total: (input_tokens / 1_000_000) * m.input_per_1m + (m.output_per_1m !== null ? (output_tokens / 1_000_000) * m.output_per_1m : 0), })) .sort((a, b) => a.total - b.total) .slice(0, top) if (!ranked.length) { return { content: [{ type: 'text' as const, text: 'No models found for that filter.' }] } } const cheapest = ranked[0].total const fmt = (n: number) => n < 0.001 ? `$${n.toFixed(6)}` : `$${n.toFixed(4)}` const col = (s: string, w: number) => s.length > w ? s.slice(0, w - 1) + '…' : s.padEnd(w) const header = `${'#'.padStart(2)} ${col('Model', 36)} ${col('Tool', 18)} ${'Cost'.padStart(10)} vs cheapest` const sep = '─'.repeat(header.length) const rows = ranked.map((m, i) => { const mult = i === 0 ? '(cheapest)' : `${(m.total / cheapest).toFixed(1)}× more` return `${String(i + 1).padStart(2)} ${col(m.model_name, 36)} ${col(m.tool_name, 18)} ${fmt(m.total).padStart(10)} ${mult}` }) return { content: [{ type: 'text' as const, text: [ `Cost for ${input_tokens.toLocaleString()} input + ${output_tokens.toLocaleString()} output tokens:`, '', header, sep, ...rows, '', 'Full calculator: https://tickerr.ai/token-counter', ].join('\n'), }], } } ) - src/index.ts:231-236 (schema)Input schema for compare_pricing: input_tokens (required int), output_tokens (default 0), filter (optional string), top (optional int, default 10).
{ input_tokens: z.number().int().min(1).describe('Number of input tokens per request'), output_tokens: z.number().int().min(0).default(0).describe('Number of output tokens per request'), filter: z.string().optional().describe('Narrow to a provider or model family — e.g. "claude", "gpt", "gemini"'), top: z.number().int().min(1).max(30).optional().describe('Show only the N cheapest models (default 10)'), }, - src/index.ts:237-280 (handler)Handler function that fetches /pricing, filters models by optional filter string, calculates total cost per model based on input/output tokens, sorts by cheapest, and returns a ranked table of the top N models.
async ({ input_tokens, output_tokens, filter, top = 10 }) => { const data = await fetchJSON<{ models: PricingRow[] }>('/pricing') let models = data.models if (filter) { const q = filter.toLowerCase() models = models.filter( (m) => m.model_name.toLowerCase().includes(q) || m.tool_name.toLowerCase().includes(q) ) } const ranked = models .map((m) => ({ ...m, total: (input_tokens / 1_000_000) * m.input_per_1m + (m.output_per_1m !== null ? (output_tokens / 1_000_000) * m.output_per_1m : 0), })) .sort((a, b) => a.total - b.total) .slice(0, top) if (!ranked.length) { return { content: [{ type: 'text' as const, text: 'No models found for that filter.' }] } } const cheapest = ranked[0].total const fmt = (n: number) => n < 0.001 ? `$${n.toFixed(6)}` : `$${n.toFixed(4)}` const col = (s: string, w: number) => s.length > w ? s.slice(0, w - 1) + '…' : s.padEnd(w) const header = `${'#'.padStart(2)} ${col('Model', 36)} ${col('Tool', 18)} ${'Cost'.padStart(10)} vs cheapest` const sep = '─'.repeat(header.length) const rows = ranked.map((m, i) => { const mult = i === 0 ? '(cheapest)' : `${(m.total / cheapest).toFixed(1)}× more` return `${String(i + 1).padStart(2)} ${col(m.model_name, 36)} ${col(m.tool_name, 18)} ${fmt(m.total).padStart(10)} ${mult}` }) return { content: [{ type: 'text' as const, text: [ `Cost for ${input_tokens.toLocaleString()} input + ${output_tokens.toLocaleString()} output tokens:`, '', header, sep, ...rows, '', 'Full calculator: https://tickerr.ai/token-counter', ].join('\n'), }], } }