The Python SDK supports both the Chat Completions API and the Responses API.
Python Splunk Agent Observability OpenAI SDK reference
The Python Splunk Agent Observability OpenAI SDK reference.
Installation
First, make sure you have the Splunk Agent Observability SDK installed. If you are using Python, ensure you install the OpenAI optional dependency.Basic usage
If you are using Python, import thesplunk_ao.openai module, instead of the OpenAI openai module and use that to create your client.
- The input prompt
- The model used
- The response
- Timing information
- Token usage
- Other relevant metadata
Responses API (Python only)
The Python SDK also supports OpenAI’s Responses API, which provides a simplified interface for single-turn interactions and additional features like built-in tools.Responses API basic example
Python
Tool calls
The Responses API supports function calling. Here’s an example that demonstrates tool definitions, executing tool calls, and providing results back to the model:Python
The Responses API also supports advanced features like:
- Reasoning items with the
reasoningparameter for chain-of-thought outputs - Built-in tools including web search, code interpreter, and file search
- Streaming with
stream=True
Sessions and traces
If you use the OpenAI wrapper by itself, it will automatically create a session and start a new trace for you, adding the call as an LLM span. Subsequent calls will be added as an LLM span to a new trace in the same session. The session will have an autogenerated name based off the content.


Streaming support
The OpenAI wrapper also supports streaming responses. When streaming, the wrapper will log the response as it streams in:Combining with the log decorator
You can combine the OpenAI wrapper with thelog decorator to create more complex traces:
Benefits of using the OpenAI integration
- Zero-config logging: No need to add logging code throughout your application
- Complete visibility: All prompts and responses are automatically captured
- Minimal code changes: Change your import statement in Python. No other code changes are required.
- Automatic tracing: Creates spans and traces without manual setup
- Streaming support: Works with both regular and streaming responses
Asynchronous OpenAI calls with Splunk Agent Observability
The Splunk Agent Observability OpenAI wrapper currently supports only synchronous calls for both the Chat Completions API and the Responses API. It does not include built-in support for theAsyncOpenAI class from the official OpenAI Python library. As a result, asynchronous calls made via the splunk_ao.openai wrapper won’t automatically generate LLM spans or upload telemetry to Splunk Agent Observability.You can still track async interactions by manually using the low-level SplunkAOLogger API. This requires importing and awaiting the OpenAI AsyncOpenAI client, wrapping each call with a call to add an LLM span, and flushing the logger to send your traces.Next steps
Splunk Agent Observability logger
Log with full control over sessions, traces, and spans using the Splunk Agent Observability logger.
Log decorator
Quickly add logging to your code with the log decorator and wrapper.
Splunk Agent Observability context
Manage logging using the Splunk Agent Observability context manager.