Observability for OpenAI Agents
Gain complete visibility into your OpenAI-powered agentic workflows. The Anosys Platform integrates with the OpenAI Python and JavaScript SDKs to automatically capture every API call, tool invocation, and model response — giving you the insights you need to optimize costs, debug failures, and ship faster.
Why Observability Matters for AI Agents
Agentic AI workflows are fundamentally different from traditional software — they are non-deterministic, multi-step, and often expensive to run. Without observability you are flying blind:
| Challenge | What Observability Gives You |
|---|---|
| Non-deterministic outputs | Trace every reasoning step so you can reproduce and compare runs |
| Runaway token usage | Real-time metrics on input/output tokens per session |
| Silent failures | Structured logs with error classification and alerting |
| Slow iterations | Latency breakdowns across tool calls and model invocations |
| Cost overruns | Per-session and per-project cost attribution dashboards |
Getting Started with OpenAI Agents
The Anosys SDK provides lightweight wrappers for both the OpenAI SDK and the OpenAI Agents SDK. Once initialized, every API call is automatically traced and exported — no manual instrumentation required.
To get started you need to:
- Create an ingestion channel in the Anosys Console. Go to the API tab and click Create New API Key to get your key.
- Install the Anosys SDK packages.
- Initialize the logger in your code before making OpenAI calls.
OpenAI SDK Integration
Use this when you're calling the OpenAI API directly (chat completions, embeddings, etc.).
Install
Initialize and Run
That's it. Every OpenAI API call made through the client is now automatically traced.
Environment variables
For production deployments, set OPENAI_API_KEY and ANOSYS_API_KEY as environment variables rather than hardcoding them. The SDK reads both from the environment automatically.
OpenAI Agents SDK Integration
Use this when you're building agents with the OpenAI Agents SDK (openai-agents). The Anosys integration plugs into the Agents SDK's tracing processor to capture agent runs, tool calls, handoffs, guardrails, and generation spans.
Install
Initialize and Run
User Context
Associate traces with user sessions for better segmentation and analysis:
Span Types Captured
The Agents SDK integration captures the following span types:
| Span Type | Description |
|---|---|
agent |
Agent execution spans with handoffs and tool lists |
function |
Tool/function call invocations |
generation |
LLM generation calls with token usage |
guardrail |
Guardrail evaluation checks |
handoff |
Agent-to-agent handoffs |
response |
Response spans |
custom |
Custom user-defined spans |
mcp_tools |
MCP tool invocations |
Streaming Support
Streaming is automatically detected and logged with both Python and JavaScript SDKs:
Custom Function Logging
Log custom functions using decorators to capture inputs, outputs, and execution time:
What the OpenAI SDK Captures
Because the Anosys logger wraps the OpenAI SDK directly, it captures rich data beyond standard OTLP telemetry:
| Data Point | Description |
|---|---|
| Model name & version | The exact model used for each call (e.g. gpt-5, gpt-4.1-mini) |
| Prompt & completion tokens | Precise input/output token counts per request |
| Request parameters | Temperature, top-p, max tokens, stop sequences, and other model settings |
| Tool / function calls | Names, arguments, and return values of any tool calls made by the agent |
| Streaming events | Per-chunk latency for streaming responses |
| Response metadata | Finish reason, system fingerprint, and response ID |
| Error details | HTTP status codes, rate-limit headers, and retry counts |
What You'll See in Anosys
Once the logger is active, the Anosys Platform automatically processes your OpenAI data and surfaces:
- Request traces — End-to-end visibility into every OpenAI API call, including multi-turn conversations and chained agent executions.
- Token usage metrics — Input and output token counts per request, per model, and over time.
- Model comparison — Side-by-side performance and cost breakdowns across different models (e.g.
gpt-5vsgpt-4.1-mini). - Latency analysis — Identify slow model calls and bottlenecks, including time-to-first-token for streaming responses.
- Error tracking — Structured error logs with automatic classification, including rate-limit events and API errors.
- Cost insights — Per-request and per-project cost estimates based on actual token usage and model pricing.
- Anomaly detection — ML-powered baselines that alert on token usage spikes, latency regressions, and model quality degradation without manual threshold configuration.
- Root cause analysis — Causal graphs that connect failures to upstream triggers across multi-step agent executions, tool calls, and model invocations.
- Alerts — Context-aware notifications via Slack, email, or webhooks when your agents hit errors, cost overruns, or performance regressions.
- Custom dashboards — Build your own views or start with auto-generated dashboards for model health, agent reliability, and cost attribution.
- Automated metric generation — Anosys automatically generates key metrics from your traces and logs so you get dashboards in minutes, not days.
- Custom pipelines — Enrich, route, and transform your agent telemetry with automated remediation workflows.
- Labeling — Tag and annotate agent sessions, models, or projects with custom labels for segmentation and drill-down analysis.
- AI Copilot — Ask questions about your agent data in plain English and get answers backed by your telemetry.
Configuration Reference
| Variable / Setting | Description |
|---|---|
OPENAI_API_KEY |
Your OpenAI API key |
ANOSYS_API_KEY |
Your Anosys API key (from the Console — API tab) |
ANOSYS_API_URL |
(Optional) Override the logging endpoint |
ANOSYS_LOG_LEVEL |
(Optional, JS only) debug / info / warn / error / silent (default: warn) |
Troubleshooting
I don't see any data in the Anosys Console
- Verify that
ANOSYS_API_KEYis set correctly and matches the key shown in your Anosys Console. - Make sure
AnosysOpenAILogger()is called before you create theOpenAI()client. - For the Agents SDK, ensure
set_tracing_processor()(Python) oraddTracingProcessor()(JS) is called before running agents. - Confirm that your OpenAI calls are completing successfully (check for API errors).
- Ensure outbound HTTPS traffic to
api.anosys.aiis not blocked by a firewall or proxy.
Does this work with async and streaming calls?
Yes. The Anosys logger automatically instruments both synchronous and asynchronous OpenAI clients, including streaming responses via stream=True.
Can I use this alongside other OTLP collectors?
Yes. The Anosys logger can coexist with other OpenTelemetry instrumentation. If you need to fan out to multiple backends, place an OpenTelemetry Collector in between and configure multiple exporters there.
Which OpenAI SDK versions are supported?
The anosys-sdk-openai package supports OpenAI Python SDK v1.x and later. The anosys-sdk-openai-agents package supports the OpenAI Agents SDK.
Next Steps
- OpenAI ChatKit Apps — add observability to ChatKit-powered chat widgets.
- Claude Code Observability — set up tracing for Claude Code sessions.
- Anthropic Agents Observability — OTEL-based setup for Anthropic agents.
- OpenTelemetry Integration — universal OTEL guide for any system that speaks OpenTelemetry.
- Data Ingestion Options — explore additional ways to send data to Anosys.
- FAQ — frequently asked questions about the Anosys Platform.