CostKey

Integrations

OpenAI Agents SDK tracing and observability

See every agent, tool call, handoff and guardrail in an OpenAI Agents SDK run, with what each step cost and the code that made it.

What you get

  • Agents, function tools, handoffs, guardrails and turns become spans.
  • 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.
support-triage
  • agentTriage agent$0.0184
  • llmgpt-5-mini1.2s
  • toollookup_order220ms
  • handoff→ Refunds agent
  • llmgpt-52.9s
  • guardrailrefund_limitpassed

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[openai-agents]"
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 OpenAI Agents SDK integration

Python
from costkey.integrations.openai_agents import instrument

instrument()
result = await Runner.run(agent, "What's the weather in SF?")
TypeScript
import { addTraceProcessor } from '@openai/agents'
import { CostKeyAgentsProcessor } from 'costkey/integrations/openai-agents'

addTraceProcessor(new CostKeyAgentsProcessor())

instrument() adds a tracing processor, so the Agents SDK's tracing must be on. With tracing off, pass hooks=CostKeyRunHooks() to Runner.run instead. In TypeScript, the Agents SDK disables tracing when NODE_ENV=test; call setTracingDisabled(false) in tests.

Full reference: OpenAI Agents SDK in the docs.

Questions

Does this replace OpenAI's own tracing?

No. It adds a trace processor next to it. Your traces still go to OpenAI if you send them there.

Are calls inside handoffs priced?

Yes. Every model call is captured from HTTP and attributed to the innermost span it ran in, so a handoff's calls roll up to that agent.

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