CostKey

Integrations

Claude Agent SDK observability and tracing

The Claude Agent SDK runs its model calls in a separate Claude Code process. CostKey's integration records the run, its tools and subagents, and prices every call.

What you get

  • The run, tool uses and subagents become spans, and every message that carries usage is sent as a priced call.
  • 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.
fix-tests
  • agenttriage$0.2140
  • llmclaude-sonnet-4-54.1s
  • toolBash · npm test6.3s
  • agentsubagent · reviewer$0.0610
  • toolRead40ms

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 · Python
pip install "costkey[claude-agent-sdk]"
bash · TypeScript
npm install costkey
Python
import os
import costkey

costkey.init(dsn=os.environ["COSTKEY_DSN"])
TypeScript
import { CostKey } from 'costkey'

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

3. Add the Claude Agent SDK integration

Python
from costkey.integrations.claude_agent_sdk import instrument

claude = instrument()
options = claude.with_hooks(ClaudeAgentOptions(model="claude-sonnet-4-5"))
async for message in query(prompt="Fix the failing test", options=options):
    ...
TypeScript
import { query } from '@anthropic-ai/claude-agent-sdk'
import { instrumentClaudeAgentQuery } from 'costkey/integrations/claude-agent-sdk'

const tracedQuery = instrumentClaudeAgentQuery(query, { name: 'triage' })
for await (const message of tracedQuery({ prompt, options })) { /* ... */ }

Your own options.hooks still run.

Full reference: Claude Agent SDK in the docs.

Questions

Why does the Claude Agent SDK need its own integration?

Its model calls run in another process, so HTTP capture in your process never sees them. The integration sends their usage instead.

Are cache reads priced?

Yes. Cache reads, cache writes, input and output are priced separately.

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