Skip to main content
TracePilot AI instruments your OpenAI calls with a single wrapper function. Every call you wrap becomes a structured span in the dashboard — capturing the prompt, the completion, token usage, latency, and any errors — without changing how the rest of your code reads the response.

Prerequisites

Install the SDK and make sure you have an OpenAI API key ready.
Get your TracePilot API key by signing in at tracepilotai.com with GitHub or Google. Your key looks like tp_live_xxxxxxxxxxxxxxxx.

Wrap your first call

1

Import and initialize

Import TracePilot alongside the OpenAI client and create instances of both.
2

Start a trace

Call tp.startTrace once at the beginning of each agent run. Pass a name that identifies this agent or workflow — it appears as the trace label in the dashboard.
3

Wrap the OpenAI call

Replace a bare openai.chat.completions.create call with tp.wrapOpenAI. Pass the call as a function and include the messages array as the second argument.
wrapOpenAI returns the original OpenAI response object unchanged. Any code that reads result.choices[0].message.content or any other field on the completion response continues to work without modification.

Full working example

After the function runs, open tracepilotai.com/dashboard. The trace appears immediately with no additional configuration.

Optional parameters

wrapOpenAI accepts two additional parameters that become useful once your agent has multiple steps.

parentSpanId

Pass the spanId returned by a previous wrapOpenAI or wrapToolCall call to link the current span as a child of that span. This builds a parent-child execution tree in the dashboard.

stepOrder

Pass a number to control the order in which spans are displayed within the same parent. Without stepOrder, the dashboard sorts spans by arrival time, which can be inconsistent under concurrency.
If you are self-hosting the TracePilot backend, pass your endpoint as the second argument to the constructor.
All other methods work identically.
If the OpenAI call throws, wrapOpenAI captures the error as a failed span in the dashboard and re-throws the original error. Your existing try/catch blocks remain effective.