Skip to content
PluginStats

ai-sdk-cost-calculator weekly downloads statistics

By RenKoya1 · npm · AI SDKs

Cost calculator for Vercel AI SDK token usage. Supports OpenAI, Anthropic, Google, xAI (Grok), and DeepSeek with long context pricing, prompt caching, and reasoning tokens.

View on npm Fresh · Oct 18, 2026

ai-sdk-cost-calculator has 3,361 recorded weekly downloads on npm, a decrease of 56.0% over the past 30 days, ranking #1221 of 2,322 tracked listings.

Weekly downloads
3,361
Official API · Oct 18, 2026
7-day growth
-64.7%
-6.2K weekly downloads
30-day growth
-56.0%
-4.3K weekly downloads
90-day growth
+20.9%
+582 weekly downloads
Rank
#1221
Among tracked npm listings

About ai-sdk-cost-calculator

ai-sdk-cost-calculator

Cost calculator for Vercel AI SDK token usage. Calculate API costs for OpenAI, Anthropic, Google, xAI (Grok), DeepSeek, and Perplexity with support for long context pricing, prompt caching, reasoning tokens, and web search.

Features

  • Multi-provider support: OpenAI, Anthropic, Google Gemini, xAI Grok, DeepSeek, Perplexity
  • AI SDK native: Use with onFinish callbacks via withCost() wrapper
  • Session tracking: Track costs across multiple calls with createCostAwareAI()
  • Multi-model tracking: Track costs across different models in a single tracker
  • Web search pricing: Calculate costs for grounding/search features
  • Google Maps pricing: Calculate costs for Google Maps API requests
  • Image generation pricing: Calculate costs for DALL-E, Imagen, and other image models
  • Embedding pricing: Calculate embed() / embedMany() costs with calculateEmbeddingCost()
  • Speech & transcription: Calculate generateSpeech() (TTS) and transcribe() (STT) costs
  • Video generation: Calculate experimental_generateVideo() costs (per-second / per-video)
  • Auto-detection: Automatically detect web search/maps/image generation tool calls from results
  • Long context pricing: Automatic tier-based pricing (e.g., Claude Sonnet 4.5 >200K tokens)
  • Prompt caching: Separate pricing for cache reads and writes
  • Reasoning tokens: Support for o1/o3/R1 reasoning model costs
  • TypeScript: Full type definitions included

Installation

npm install ai-sdk-cost-calculator

Peer dependency: Requires ai (Vercel AI SDK) version 6.0.0 or higher.

npm install ai

Quick Start

import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { calculateCost, formatCost } from "ai-sdk-cost-calculator";

const result = await generateText({
  model: openai("gpt-4o"),
  prompt: "Hello, world!",
});

const cost = calculateCost({
  model: "gpt-4o",
  usage: result.usage,
});

console.log(`Total cost: ${formatCost(cost.totalCost)}`);
// Output: Total cost: $0.000150

AI SDK Integration

Using withCost with onFinish

The easiest way to track costs is with the withCost callback wrapper:

import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { withCost, formatCost } from "ai-sdk-cost-calculator";

const result = await generateText({
  model: openai("gpt-4o"),
  prompt: "Hello!",
  onFinish: withCost("gpt-4o", ({ cost, usage }) => {
    console.log(`Cost: ${formatCost(cost.totalCost)}`);
    console.log(`Tokens: ${usage.inputTokens} in, ${usage.outputTokens} out`);
  }),
});

You can also pass the model object directly:

const model = openai("gpt-4o");

await generateText({
  model,
  prompt: "Hello!",
  onFinish: withCost(model, ({ cost }) => {
    console.log(`Cost: ${formatCost(cost.totalCost)}`);
  }),
});
Using getCost for One-Shot Calculation

For simple post-hoc cost calculation:

import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { getCost, formatCost } from "ai-sdk-cost-calculator";

const result = await generateText({
  model: openai("gpt-4o"),
  prompt: "Hello!",
});

const cost = getCost("gpt-4o", result.usage);
console.log(`Cost: ${formatCost(cost.totalCost)}`);
Using createCostAwareAI for Session Tracking

For tracking costs across multiple calls in a session:

import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { anthropic } from "@ai-sdk/anthropic";
import { createCostAwareAI, formatCost } from "ai-sdk-cost-calculator";

const ai = createCostAwareAI({
  onCost: (model, cost) => {
    console.log(`[${model}] ${formatCost(cost.totalCost)}`);
  },
});

// First call
await generateText({
  model: openai("gpt-4o"),
  prompt: "Hello!",
  onFinish: ai.onFinish("gpt-4o"),
});

// Second call with different model
await generateText({
  model: anthropic("claude-sonnet-4-5"),
  prompt: "Hello!",
  onFinish: ai.onFinish("claude-sonnet-4-5"),
});

// Get totals
console.log(`Total: ${formatCost(ai.getTotal().totalCost)}`);
console.log(`Requests: ${ai.getRequestCount()}`);
console.log(`Models: ${ai.getModels().join(", ")}`);

// Reset when needed
ai.reset();

Multi-Model Tracker

Track costs across multiple models in a single tracker instance.

import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { anthropic } from "@ai-sdk/anthropic";
import { createTracker, formatCost } from "ai-sdk-cost-calculator";

const tracker = createTracker({
  onCost: (model, cost) => {
    console.log(`[${model}] Cost: ${formatCost(cost.totalCost)}`);
  },
});

// Use with onFinish callback
await generateText({
  model: openai("gpt-4o"),
  prompt: "Hello!",
  onFinish: tracker.onFinish("gpt-4o"),
});

await generateText({
  model: anthropic("claude-sonnet-4-5"),
  prompt: "Hello!",
  onFinish: tracker.onFinish("claude-sonnet-4-5", ({ cost, text }) => {
    console.log(`Response: ${text}, Cost: ${formatCost(cost.totalCost)}`);
  }),
});

// Or add usage manually
tracker.add("gpt-4o", result.usage, { webSearchRequests: 5 });

// Get per-model costs
for (const summary of tracker.getAllCosts()) {
  console.log(`${summary.model}: ${formatCost(summary.cost.totalCost)}`);
}

// Get total cost across all models
console.log(`Total: ${formatCost(tracker.getTotal().totalCost)}`);
console.log(`Requests: ${tracker.getTotalRequestCount()}`);
console.log(`Models: ${tracker.getModels().join(", ")}`);

// Reset when needed
tracker.reset();

Web Search & Google Maps Costs

Calculate costs including web search/grounding and Google Maps features.…

Description from the npm listing.

  • ai
  • ai-sdk
  • vercel-ai
  • cost
  • calculator
  • pricing
  • token
  • usage
  • openai
  • anthropic
  • claude
  • google
  • gemini
  • xai
  • grok
  • deepseek
  • llm
  • gpt
  • chatgpt

README badge

Show your rank in a README or on your website. The badge updates automatically.

Charts

Images: 30d · 1y · all time · 1600×900 dark

Adoption over time

ai-sdk-cost-calculator weekly downloads on npm, last 90 days: 3,361 weekly downloads as of Oct 18, 2026, +20.9% over 90 days.ai-sdk-cost-calculatorWeekly downloads on npm · Last 90 days3,361downloads / week+20.9% over 90 days02K4K6K8K10K12KJul 20Aug 4Aug 19Sep 3Sep 18Oct 3Oct 18downloads / weekobservedarchived (Internet Archive)no observationsJul 22, 2026 – Oct 18, 2026 · 89 observations · Updated Oc…pluginstats.com
ai-sdk-cost-calculator weekly downloads on npm, last 90 days: 3,361 weekly downloads as of Oct 18, 2026, +20.9% over 90 days.

7/30/90-day growth

ai-sdk-cost-calculator weekly downloads growth on npm: -64.7% over 7 days, -56.0% over 30 days, +20.9% over 90 days.ai-sdk-cost-calculatorWeekly downloads growth on npm3,361downloads / week now7-day growth-6,162 weekly downloads-64.7%30-day growth-4,277 weekly downloads-56.0%90-day growth+582 weekly downloads+20.9%Growth vs. nearest observation to each baseline date · Updated Oct 18, 2026pluginstats.com
ai-sdk-cost-calculator weekly downloads growth on npm: -64.7% over 7 days, -56.0% over 30 days, +20.9% over 90 days.

Ranking history

ai-sdk-cost-calculator npm ranking history: currently #1221 (by weekly downloads).ai-sdk-cost-calculatornpm ranking · by weekly downloads · Last 90 days#1221current rank#1195#1200#1205#1210#1215#1220#1225Jul 22Aug 6Aug 21Sep 5Sep 20Oct 5Oct 20rankOct 18, 2026 – Oct 20, 2026 · 3 observations · Updated Oct 18, 2026pluginstats.com
ai-sdk-cost-calculator npm ranking history: currently #1221 (by weekly downloads).

Listing placement

All npm2,320 listings · 116 pages · 1,162 shown · page 62, #4 (overall #1,224)
All npm: every listing in weekly downloads order

Listing placement

AI SDKs259 listings · 13 pages · page 5, #10 (overall #90)
AI SDKs: every listing in weekly downloads order

Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.

Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.

Recent observations

Full history (122)
Recent weekly downloads observations for ai-sdk-cost-calculator
Date (UTC)Weekly downloadsChange vs. previous
3,361+284
3,077-1.6K
4,644-522
5,166-2.7K
7,877-2K
9,8410
9,841+318
9,523+453
9,070+1.1K
7,962+327
7,635+997
6,638+846
5,792-1.1K
6,918—

Data source

Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.

Listing: https://www.npmjs.com/package/ai-sdk-cost-calculator. First seen Oct 16, 2026; last successful collection Oct 20, 2026. See the methodology.