get_model_pricing
Compare AI model pricing across major providers like Anthropic, OpenAI, Google, Meta, Mistral, and Cohere. Get prices per million tokens to make informed cost decisions.
Instructions
Get AI model pricing comparison across all major providers (Anthropic, OpenAI, Google, Meta, Mistral, Cohere). Prices per 1M tokens.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mcp-server/src/index.ts:156-186 (registration)Registration of the 'get_model_pricing' tool via server.tool() on the MCP server. No input schema. Fetches pricing data from /models endpoint and formats it as text.
server.tool( 'get_model_pricing', 'Get AI model pricing comparison across all major providers (Anthropic, OpenAI, Google, Meta, Mistral, Cohere). Prices per 1M tokens.', {}, async () => { const data = await fetchJSON('/models') as { providers: { name: string; models: { name: string; inputPrice: number; outputPrice: number; contextWindow: number; released: string; capabilities: string[] }[]; }[]; }; const text = data.providers .map(p => { const models = p.models .map(m => { const input = m.inputPrice === 0 ? 'Free' : `$${m.inputPrice.toFixed(2)}`; const output = m.outputPrice === 0 ? 'Free' : `$${m.outputPrice.toFixed(2)}`; const ctx = m.contextWindow >= 1000000 ? `${(m.contextWindow / 1000000).toFixed(0)}M` : `${(m.contextWindow / 1000).toFixed(0)}K`; return ` ${m.name}: Input ${input}, Output ${output}, Context ${ctx}, Released ${m.released}`; }) .join('\n'); return ` ${p.name}:\n${models}`; }) .join('\n\n'); return { content: [{ type: 'text' as const, text: `AI Model Pricing (per 1M tokens):\n\n${text}` }] }; } ); - mcp-server/src/index.ts:160-185 (handler)Handler function for get_model_pricing. Calls fetchJSON('/models') to retrieve pricing data from tensorfeed.ai, then formats it into a human-readable text response listing providers and their models with input/output prices per 1M tokens, context window size, and release date.
async () => { const data = await fetchJSON('/models') as { providers: { name: string; models: { name: string; inputPrice: number; outputPrice: number; contextWindow: number; released: string; capabilities: string[] }[]; }[]; }; const text = data.providers .map(p => { const models = p.models .map(m => { const input = m.inputPrice === 0 ? 'Free' : `$${m.inputPrice.toFixed(2)}`; const output = m.outputPrice === 0 ? 'Free' : `$${m.outputPrice.toFixed(2)}`; const ctx = m.contextWindow >= 1000000 ? `${(m.contextWindow / 1000000).toFixed(0)}M` : `${(m.contextWindow / 1000).toFixed(0)}K`; return ` ${m.name}: Input ${input}, Output ${output}, Context ${ctx}, Released ${m.released}`; }) .join('\n'); return ` ${p.name}:\n${models}`; }) .join('\n\n'); return { content: [{ type: 'text' as const, text: `AI Model Pricing (per 1M tokens):\n\n${text}` }] }; } - mcp-server/src/index.ts:19-59 (helper)Helper function fetchJSON that handles API calls to tensorfeed.ai. Used by the get_model_pricing handler to fetch data from the /models endpoint. Handles authentication via TENSORFEED_TOKEN env var and error states including 402 (payment required) and 401 (token rejected).
async function fetchJSON(path: string, opts: FetchOptions = {}): Promise<unknown> { const headers: Record<string, string> = { 'User-Agent': `TensorFeed-MCP/${SDK_VERSION}`, }; if (opts.body !== undefined) headers['Content-Type'] = 'application/json'; if (opts.auth) { const token = process.env.TENSORFEED_TOKEN; if (!token) { throw new Error( 'TENSORFEED_TOKEN env var is not set. Premium MCP tools require a bearer token. ' + 'Buy credits at https://tensorfeed.ai/developers/agent-payments and pass the returned tf_live_... token via the TENSORFEED_TOKEN env var in your MCP client config.', ); } headers['Authorization'] = `Bearer ${token}`; } const res = await fetch(`${API_BASE}${path}`, { method: opts.method ?? 'GET', headers, ...(opts.body !== undefined ? { body: JSON.stringify(opts.body) } : {}), }); if (!res.ok) { let errPayload: unknown; try { errPayload = await res.json(); } catch { errPayload = await res.text().catch(() => ''); } if (res.status === 402) { throw new Error( `Payment required (402). Your token may be out of credits. Top up at https://tensorfeed.ai/developers/agent-payments. Detail: ${JSON.stringify(errPayload)}`, ); } if (res.status === 401) { throw new Error( `Token rejected (401). Check that TENSORFEED_TOKEN is set to a valid tf_live_... token. Detail: ${JSON.stringify(errPayload)}`, ); } throw new Error(`API error ${res.status}: ${JSON.stringify(errPayload)}`); } return res.json(); }