Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.galileo.ai/llms.txt

Use this file to discover all available pages before exploring further.


Function: wrapOpenAI()

function wrapOpenAI<T>(
  openAIClient: T,
  logger?: GalileoLogger,
  ingestionHook?: (request: LogTracesIngestRequest) => void | Promise<void>,
): T;
Defined in: src/handlers/openai/index.ts Wraps an OpenAI instance with logging.

Type Parameters

T

T extends OpenAIType

Parameters

openAIClient

T The OpenAI instance to wrap.

logger?

GalileoLogger The logger to use. Defaults to a new GalileoLogger instance.

ingestionHook?

(request: LogTracesIngestRequest) => void | Promise<void> Optional async callback invoked with the trace ingest request payload before sending to the Galileo API. Use this to inspect or modify trace data before ingestion. When provided without a logger, a new GalileoLogger is created with this hook and traces are automatically flushed to the hook after each completed call. No explicit flush() is needed.

Returns

T The wrapped OpenAI instance. Usage:
import { wrapOpenAI } from "galileo";

const openai = wrapOpenAI(new OpenAI({ apiKey: process.env.OPENAI_API_KEY }));

await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [{ content: "Say hello world!", role: "user" }],
});