Wraps an OpenAI SDK object with Langfuse tracing. Function calls are extended with a tracer that logs detailed information about the call, including the method name, input parameters, and output.

const client = new OpenAI();
const res = observeOpenAI(client, { traceName: "My.OpenAI.Chat.Trace" }).chat.completions.create({
messages: [{ role: "system", content: "Say this is a test!" }],
model: "gpt-3.5-turbo",
user: "langfuse",
max_tokens: 300
});
  • Type Parameters

    • SDKType extends object

    Parameters

    • sdk: SDKType

      The OpenAI SDK object to be wrapped.

    • OptionallangfuseConfig: LangfuseConfig

      Optional configuration object for the wrapper.

    Returns SDKType & OpenAI & Pick<Langfuse, "flushAsync" | "shutdownAsync">

    • A proxy of the original SDK object with methods wrapped for tracing.