OpenAI SDK and Agents SDK
Trace OpenAI calls and OpenAI Agents SDK runs in Python and JavaScript: model calls, tool calls, handoffs, guardrails, tokens and latency.
| You build with | Package |
|---|---|
The OpenAI SDK (openai) |
anosys-sdk-openai |
The OpenAI Agents SDK (openai-agents, @openai/agents) |
anosys-sdk-openai-agents |
Before you start
- Create an endpoint of type OpenTelemetry / AI Agents in the console, then go to Collecting → Integration Options → API and click Create New API 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:
Leave out prompts and outputs
AnosysOpenAIAgentsLogger accepts capture_inputs=False and capture_outputs=False (and capture_parameters=False for model settings) to send timing, tokens and structure only.
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
| 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 | Streaming responses, with final usage |
| Response metadata | Finish reason, system fingerprint, and response ID |
| Errors | Error type and message |
Configuration Reference
| Variable / Setting | Description |
|---|---|
OPENAI_API_KEY |
Your OpenAI API key |
ANOSYS_API_KEY |
Your Anosys API key |
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.
- Monitor agents in production — dashboards, alerts and evaluations.
- Anthropic SDK and Claude Agent SDK — the same for Claude.
- OpenTelemetry Integration — universal OTEL guide for any system that speaks OpenTelemetry.
- Send any data — send other events into the same workspace.
- FAQ — frequently asked questions about the Anosys Platform.