CostKey

Integrations

Vercel AI SDK telemetry and observability

See every generateText and streamText run, its steps and tool calls, what it cost and the code that called it. No wrapping.

What you get

  • generateText and streamText runs (and ToolLoopAgent), their steps and tool executions become spans. Needs ai 7 or later.
  • Every model call priced, across 45+ providers, and attributed to the step it ran in.
  • The function, file and line behind each call.
  • Failed and retried runs, with the error and the step that raised it.
  • Cost split by agent or tool, and budgets on either.
  • Quality checks scored on every finished run.
chat-route
  • agentstreamText ยท chat$0.0093
  • stepstep 11.1s
  • toolgetWeather310ms
  • stepstep 21.8s

1. Start CostKey

Run it on your own machines. Open http://localhost:4100, sign up and copy your project's DSN.

bash
curl -fsSL https://costkey.dev/install.sh | sh

2. Install the SDK

bash
npm install costkey
TypeScript
import { CostKey } from 'costkey'

CostKey.init({ dsn: process.env.COSTKEY_DSN })

3. Add the Vercel AI SDK integration

TypeScript
import { registerTelemetry } from 'ai'
import { costkeyTelemetry } from 'costkey/integrations/ai-sdk'

registerTelemetry(costkeyTelemetry())
// Runs are named by `telemetry: { functionId }` when you set it.

AI SDK 4 to 6 have no telemetry integration API. Turn on their experimental_telemetry OpenTelemetry spans and use the OpenTelemetry bridge.

Full reference: Vercel AI SDK in the docs.

Questions

Does it work with Next.js?

Yes on Next.js: npx costkey setup detects it and writes the snippet for you. Bundled apps should upload sourcemaps so calls point at your source files.

Do I need to wrap my model?

No. Register the telemetry once; calls through any provider package are captured.

Try it on your own machines

One command starts Postgres, the server and the console with Docker.

bash
curl -fsSL https://costkey.dev/install.sh | sh