This guide covers the OpenAI model SDK. If you use the OpenAI Agents SDK, follow the OpenAI Agents SDK integration instead.
Supported APIs
Only the API surfaces in this table are auto-instrumented. Other OpenAI SDK calls continue to work normally, but this integration does not automatically create PromptLayer traces or request logs for them.
Prerequisites
- A PromptLayer API key for the workspace that should receive the traces
- An OpenAI API key
- Python 3.10 or later for the Python integration, or Node.js 20 or later for the JavaScript integration
Python
1. Install the SDKs
Install PromptLayer with the OpenAI tracing extra:2. Initialize instrumentation
Callinstrument_openai() before the first OpenAI request. It configures the OpenAI instrumentor and an authenticated OTLP exporter for PromptLayer.
instrument_openai() is idempotent when called again with the same tracer provider. If your application already owns an OpenTelemetry SDK tracer provider, pass it with tracer_provider=.
Use an existing PromptLayer client
Use an existing PromptLayer client
If your application already creates a PromptLayer client, select OpenAI when enabling tracing:Omit
tracing_providers to instrument every supported provider SDK that is installed. Use either this setup or instrument_openai() for the same tracer provider; you do not need both.JavaScript
1. Install the SDKs
2. Preload PromptLayer instrumentation
Start Node.js with thepromptlayer/register preload. The preload must run before your application imports openai.
NODE_OPTIONS:
3. Use the OpenAI SDK normally
shutdownTracing() when a short-lived process finishes, not after every request in a long-running server.
The preload instruments every supported provider. To instrument only OpenAI, call configureTracing({ providers: ["openai"] }) in a bootstrap module and dynamically import the application afterward. See Select Providers.
Capture Prompts and Responses
PromptLayer captures supported prompt and response content by default so search, analytics, request inspection, and debugging can use the complete LLM interaction. Model names, timing, token usage when available, and other non-content telemetry are still recorded when capture is disabled. To disable content capture, set the language-specific value beforeinstrument_openai() or the promptlayer/register preload runs:
captureContent: false to configureTracing(). Restart an already-running process after changing the setting.
Configuration Reference
Python also accepts
api_key, base_url, endpoint, and tracer_provider keyword arguments:
configure_tracing(providers=("openai", ...)) or the tracing_providers PromptLayer client option described in the auto-instrumentation overview.
Verify the Integration
Run one supported OpenAI request, flush tracing, and open Traces in PromptLayer. The OpenAI span should have an associated request log. If the call runs insidePromptLayer.run(), PromptLayer links the provider span to the existing run request log instead of creating a duplicate.
If no span appears:
- Confirm the initialization or JavaScript preload runs before the first OpenAI call.
- Confirm the call uses an API surface listed in Supported APIs.
- Confirm
PROMPTLAYER_API_KEYbelongs to the workspace you are checking. - Flush or shut down tracing before a short-lived process exits.
- If only prompt or response content is missing, confirm content capture was not disabled and restart the process after changing the setting.

