Wraps an OpenAI client's completion methods, enabling automatic LangSmith tracing. Method signatures are unchanged, with the exception that you can pass an additional and optional "langsmithExtra" field within the second parameter.

import { OpenAI } from "openai";
import { wrapOpenAI } from "langsmith/wrappers/openai";

const patchedClient = wrapOpenAI(new OpenAI());

const patchedStream = await patchedClient.chat.completions.create(
{
messages: [{ role: "user", content: `Say 'foo'` }],
model: "gpt-3.5-turbo",
stream: true,
},
{
langsmithExtra: {
metadata: {
additional_data: "bar",
},
},
},
);
  • Type Parameters

    • T extends OpenAIType

    Parameters

    • openai: T

      An OpenAI client instance.

    • Optionaloptions: Partial<RunTreeConfig>

      LangSmith options.

    Returns PatchedOpenAIClient<T>