SDK & Integration · 2 min · Updated 2026-10-20

OpenAI Agents SDK cost tracking

Track every model call an agent makes with a trace processor

Setup

Install with the Agents extra (pip install "tokeven[openai-agents]"), set TOKEVEN_INGEST_TOKEN to your ingest token, then add the processor:

from agents import add_trace_processor
from tokeven.integrations.openai_agents import TokevenTracingProcessor

add_trace_processor(TokevenTracingProcessor())

The SDK's own tracing keeps working; Tokeven is added beside it.

What it captures

One event per model generation, for both Chat Completions and Responses API models. Only the model name and usage counters are read, never span inputs or outputs.

Budget guard

The Agents SDK catches processor errors, so the processor records spend but cannot stop a run. To enforce a budget, pass the ready-made hooks to your run: Runner.run(agent, input, hooks=guard_run_hooks()) (importable from tokeven.integrations.openai_agents).

Track your real costs

Calculators estimate. The dashboard shows what you actually spend and where you can save.