get_api_pricing
Fetch current API pricing per million tokens for AI models tracked by tickerr.ai. Filter by model or provider name to get input and output costs for models like GPT-4o, Claude, and Gemini.
Instructions
Get current API pricing (input/output cost per 1M tokens) for AI models tracked by tickerr.ai. Filter by model or provider name.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filter | No | Filter by model or tool name — e.g. "claude", "gpt-4o", "gemini" | |
| limit | No | Max models to return (default 50) |
Implementation Reference
- src/index.ts:39-42 (schema)The PricingRow interface defines the shape of pricing data used by get_api_pricing: tool_slug, tool_name, model_name, model_slug, input_per_1m, output_per_1m, and cached_input_per_1m.
interface PricingRow { tool_slug: string; tool_name: string; model_name: string; model_slug: string input_per_1m: number; output_per_1m: number | null; cached_input_per_1m: number | null } - src/index.ts:146-188 (handler)The main handler for 'get_api_pricing' tool. Fetches pricing data from /pricing endpoint, applies optional filter by model/tool name, limits results, and returns a formatted table with input, output, and cached input costs per 1M tokens.
server.tool( 'get_api_pricing', 'Get current API pricing (input/output cost per 1M tokens) for AI models tracked by tickerr.ai. Filter by model or provider name.', { filter: z.string().optional().describe('Filter by model or tool name — e.g. "claude", "gpt-4o", "gemini"'), limit: z.number().int().min(1).max(200).optional().describe('Max models to return (default 50)'), }, async ({ filter, limit = 50 }) => { 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.model_slug.toLowerCase().includes(q) || m.tool_name.toLowerCase().includes(q) ) } models = models.slice(0, limit) if (models.length === 0) { return { content: [{ type: 'text' as const, text: `No models found${filter ? ` matching "${filter}"` : ''}.` }] } } const fmt = (n: number | null) => n !== null ? `$${n.toFixed(2)}` : 'n/a' const col = (s: string, w: number) => s.length > w ? s.slice(0, w - 1) + '…' : s.padEnd(w) const header = `${col('Model', 38)} ${col('Tool', 18)} ${'In/1M'.padStart(8)} ${'Out/1M'.padStart(8)} ${'Cache/1M'.padStart(9)}` const sep = '─'.repeat(header.length) const rows = models.map((m) => `${col(m.model_name, 38)} ${col(m.tool_name, 18)} ${fmt(m.input_per_1m).padStart(8)} ${fmt(m.output_per_1m).padStart(8)} ${fmt(m.cached_input_per_1m).padStart(9)}` ) return { content: [{ type: 'text' as const, text: [ `${models.length} models (sorted cheapest input first):`, '', header, sep, ...rows, '', 'Full pricing: https://tickerr.ai/pricing', ].join('\n'), }], } } ) - src/index.ts:146-152 (registration)Registers the 'get_api_pricing' tool in the MCP server using server.tool() with schema validation for optional 'filter' and 'limit' parameters.
server.tool( 'get_api_pricing', 'Get current API pricing (input/output cost per 1M tokens) for AI models tracked by tickerr.ai. Filter by model or provider name.', { filter: z.string().optional().describe('Filter by model or tool name — e.g. "claude", "gpt-4o", "gemini"'), limit: z.number().int().min(1).max(200).optional().describe('Max models to return (default 50)'), }, - src/index.ts:9-16 (helper)The fetchJSON helper function used by get_api_pricing (and all other tools) to make authenticated GET requests to the tickerr.ai API and parse JSON responses.
async function fetchJSON<T>(path: string): Promise<T> { const res = await fetch(`${BASE_URL}${path}`, { headers: { 'User-Agent': UA } }) if (!res.ok) { const text = await res.text().catch(() => '') throw new Error(`tickerr API ${res.status}: ${text.slice(0, 200)}`) } return res.json() as Promise<T> }