# OpenAI Agents SDK cost tracking

A trace processor records every model response inside an agent run: tool-calling loops, handoffs between agents and guardrail calls. Each agent run becomes a run in Veqen, so you see what one run cost from start to finish.

## Install

```bash
pip install veqen openai-agents
```

## Add the processor

```python
import veqen
from agents import Runner, add_trace_processor
from veqen.integrations.openai_agents import VeqenTracingProcessor

veqen.init()  # reads VEQEN_API_KEY, an ingest key
add_trace_processor(VeqenTracingProcessor(feature="support-agent"))

with veqen.tags(customer=org.id):
    result = await Runner.run(agent, question)
```

## Runs

Each call is tagged with the agent run's trace id, so **Agent runs** shows each run's total cost and every call in it. Tag `run` yourself (for example a conversation id) to group several agent runs into one.

## What it reads

The usage on each `response` span (Responses API) and `generation` span (Chat Completions), with cached input kept apart. Spans without usage are skipped.

## Next

- [Tags](/docs/tags): runs, customers and features.
- [OpenTelemetry](/docs/opentelemetry): if you already export the SDK's traces elsewhere.
