The OpenAI instrumentation supports additional headers via the extra_headers parameter to enhance trace metadata and organization. You can use the following headers:
x-maxim-trace-id: Associate LLM calls with a specific trace ID (UUID string). All calls with the same trace ID will be grouped together in a single trace.
x-maxim-trace-tags: Add custom tags to traces as a JSON string containing key-value pairs. Useful for filtering and organizing traces.
x-maxim-generation-name: Assign a custom name to a specific generation/LLM call within a trace (string).
x-maxim-session-id: Associate traces with a specific session ID (string).
The OpenAI Responses API is the new standard that will replace the Chat Completions API. Maxim provides plug-and-play observability for the Responses API, working with both sync and streaming calls while capturing model, parameters, messages, output text, tool calls, and errors without changing your OpenAI usage.
You can pass optional headers via extra_headers to control trace metadata:
x-maxim-trace-id: Associate LLM calls with a specific trace ID (UUID string). All calls with the same trace ID will be grouped together in a single trace.
x-maxim-trace-tags: Add custom tags to traces as a JSON string containing key-value pairs. Useful for filtering and organizing traces.
x-maxim-generation-name: Assign a custom name to a specific generation/LLM call within a trace (string).
x-maxim-session-id: Associate traces with a specific session ID (string).
Key Differences: Responses API vs Chat Completions
Feature
Chat Completions API
Responses API
Input Parameter
messages (list of message dicts)
input (string or structured input)
Response Field
response.choices[0].message.content
response.output_text
Tool Calls
response.choices[0].message.tool_calls
response.output (items with type="function_call")
Tool Results
Added to messages array
function_call_output with previous_response_id
Conversation
All messages in single call
Chained with previous_response_id
The Responses API is OpenAI’s future standard and supports advanced features like web search. As the Chat Completions API is being phased out, we recommend migrating to the Responses API for new projects.
from openai import OpenAIfrom maxim import Maximfrom maxim.logger.openai import MaximOpenAIClient# Make sure MAXIM_API_KEY and MAXIM_LOG_REPO_ID are set in env variableslogger = Maxim().logger()# Initialize MaximOpenAIClientclient = MaximOpenAIClient(client=OpenAI(api_key=OPENAI_API_KEY),logger=logger)
from openai import OpenAIfrom maxim import Maximfrom maxim.logger.openai import MaximOpenAIClient# Make sure MAXIM_API_KEY and MAXIM_LOG_REPO_ID are set in env variableslogger = Maxim().logger()# Initialize MaximOpenAIClientclient = MaximOpenAIClient(client=OpenAI(api_key=OPENAI_API_KEY),logger=logger)
2
Create a new trace externally and add it to a session
from uuid import uuid4# use this session id to add multiple traces in one sessionsession_id = str(uuid4())trace_id = str(uuid4())trace = logger.trace({ id: trace_id, name: "Trace name", session_id: session_id})
3
Make LLM calls and use this trace id
response = client.chat.completions.create( model="gpt-4o-mini", messages=messages, extra_headers={"x-maxim-trace-id": trace_id})# Extract response text and usageresponse_text = response.choices[0].message.contentprint(response_text)