OpenAI

Adds instrumentation for OpenAI API.

Import name: Sentry.openAIIntegration

The openAIIntegration adds instrumentation for the openai API to capture spans by automatically wrapping OpenAI client calls and recording LLM interactions with configurable input/output recording.

It is enabled by default and will automatically capture spans for all OpenAI API method calls. You can opt-in to capture inputs and outputs by setting recordInputs and recordOutputs in the integration config:

Copied
Sentry.init({
  dsn: "",
  tracesSampleRate: 1.0,
  integrations: [
    Sentry.openAIIntegration({
      recordInputs: true,
      recordOutputs: true,
    }),
  ],
});

This integration only works in the Node.js runtime, not in the Edge runtime. For Next.js applications using the Edge runtime, this integration will not be available.

Requires SDK version 9.44.0 or higher.

Type: boolean

Records inputs to OpenAI API method calls (such as prompts and messages).

Defaults to true if sendDefaultPii is true.

Copied
Sentry.init({
  integrations: [Sentry.openAIIntegration({ recordInputs: true })],
});

Requires SDK version 9.44.0 or higher.

Type: boolean

Records outputs from OpenAI API method calls (such as generated text and responses).

Defaults to true if sendDefaultPii is true.

Copied
Sentry.init({
  integrations: [Sentry.openAIIntegration({ recordOutputs: true })],
});

By default this integration adds tracing support to OpenAI API method calls including:

  • chat.completions.create() - Chat completion requests
  • responses.create() - Response API requests

The integration will automatically detect streaming vs non-streaming requests and handle them appropriately.

  • openai: >=4.0.0 <6
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").