DeepTracer
Guides

Track Your AI Costs

Monitor your OpenAI, Anthropic, and other LLM spending with per-model cost breakdowns.

One runaway loop calling GPT-4 can cost hundreds of dollars before you notice. DeepTracer tracks every LLM call your app makes — cost, tokens, latency, and which feature triggered it — so you always know where your money is going.

Quick setup

Install the AI tracking package

npm install @deeptracer/ai
pnpm add @deeptracer/ai
yarn add @deeptracer/ai
bun add @deeptracer/ai

@deeptracer/ai works alongside your existing AI SDK. It wraps your calls without changing behavior — same inputs, same outputs, just with tracking added.

Wrap your AI calls

Import your AI SDK as usual, then wrap it with DeepTracer:

lib/ai.ts
import { wrapVercelAI } from "@deeptracer/ai"
import { generateText, streamText } from "ai"
import { logger } from "./deeptracer" // your DeepTracer logger instance

// Wrap the functions you use
const ai = wrapVercelAI(logger, { generateText, streamText })

// Export the wrapped versions
export const { generateText: trackedGenerateText, streamText: trackedStreamText } = ai

Then use the wrapped functions instead of the originals:

app/api/chat/route.ts
import { trackedGenerateText } from "@/lib/ai"
import { openai } from "@ai-sdk/openai"

export async function POST(req: Request) {
  const { prompt } = await req.json()

  const { text } = await trackedGenerateText({
    model: openai("gpt-4o"),
    prompt,
  })

  return Response.json({ text })
}

That's it. Every call to trackedGenerateText now reports the model, tokens, cost, and latency to DeepTracer.

Deploy and make some AI calls

Deploy your app (or test locally) and trigger a few AI calls. Each call sends a usage report to DeepTracer with:

  • Model name and provider
  • Input and output token counts
  • Estimated cost in USD
  • Response latency
  • Any metadata you attached

Open the LLM tab

Go to your DeepTracer dashboard and click the LLM tab in the sidebar. You'll see:

  • Daily spend chart — Total cost per day, broken down by model
  • Model breakdown — Which models you're using and how much each costs
  • Token usage — Input vs. output tokens over time
  • Latency — How fast each model responds
  • Per-call details — Individual LLM calls with full metadata

What gets tracked

Every LLM call reports these fields:

FieldExample
Modelgpt-4o, claude-sonnet-4-5-20250514
Provideropenai, anthropic
Operationchat.completion, embedding
Input tokens1,250
Output tokens340
Cost$0.0089
Latency2,100ms
Metadata{ "feature": "support-chat" }

Adding metadata

Tag your AI calls with metadata to see which features drive your costs:

const { text } = await trackedGenerateText({
  model: openai("gpt-4o"),
  prompt: "Summarize this support ticket...",
  // DeepTracer picks up experimental_telemetry metadata
  experimental_telemetry: {
    metadata: {
      feature: "support-chat",
      customerId: "cust_123",
    },
  },
})

Then filter by feature in the dashboard to answer questions like "How much is the support chat costing me per day?"

Why this matters

  • Catch runaway costs early — See spending spikes before they become big bills
  • Pick the right model — Compare cost vs. latency across models for each feature
  • Budget planning — Know your actual per-user AI cost, not just estimates
  • Debugging — When an AI feature feels slow, check the latency chart to confirm

What's next?

On this page