track_openai

opik.integrations.openai.track_openai(openai_client: OpenAIClient, project_name: str | None = None) OpenAIClient

Adds Opik tracking wrappers to an OpenAI client.

The client is always patched; however every wrapped call checks opik.decorator.tracing_runtime_config.is_tracing_active() before emitting any telemetry. If tracing is disabled at call time, the wrapped function executes normally but no span/trace is sent.

Tracks calls to: * openai_client.chat.completions.create(), including support for stream=True mode. * openai_client.beta.chat.completions.parse() * openai_client.beta.chat.completions.stream() * openai_client.responses.create()

Can be used within other Opik-tracked functions.

Parameters:
  • openai_client – An instance of OpenAI or AsyncOpenAI client.

  • project_name – The name of the project to log data.

Returns:

The modified OpenAI client with Opik tracking enabled.