Hierarchy

  • LangfuseCore
    • Langfuse

Constructors

  • Parameters

    • Optionalparams: {
          publicKey?: string;
          secretKey?: string;
      } & {
          enabled?: boolean;
          persistence?:
              | "localStorage"
              | "sessionStorage"
              | "memory"
              | "cookie";
          persistence_name?: string;
      } & LangfuseCoreOptions

    Returns Langfuse

Properties

_events: SimpleEventEmitter
_flushTimer?: any
_retryOptions: RetriableOptions
additionalHeaders: Record<string, string>
baseUrl: string
isLocalEventExportEnabled: boolean

Methods

  • Parameters

    • projectId: string

    Returns Promise<(
        | {
            type: "trace-create";
        } & {
            body: {
                id?: null | string;
                input?: unknown;
                metadata?: unknown;
                name?: null | string;
                output?: unknown;
                public?: null | boolean;
                release?: null | string;
                sessionId?: null | string;
                tags?: null | string[];
                timestamp?: null | string;
                userId?: null | string;
                version?: null | string;
            };
        } & {
            id: string;
            metadata?: unknown;
            timestamp: string;
        }
        | {
            type: "score-create";
        } & {
            body: {
                comment?: null | string;
                configId?: null | string;
                dataType?: "NUMERIC" | "BOOLEAN" | "CATEGORICAL";
                id?: null | string;
                name: string;
                observationId?: null | string;
                traceId: string;
                value: string | number;
            };
        } & {
            id: string;
            metadata?: unknown;
            timestamp: string;
        }
        | {
            type: "span-create";
        } & {
            body: {
                endTime?: null | string;
            } & {
                id?: null | string;
            } & {
                input?: unknown;
                level?:
                    | "DEBUG"
                    | "DEFAULT"
                    | "WARNING"
                    | "ERROR";
                metadata?: unknown;
                name?: null | string;
                output?: unknown;
                parentObservationId?: null | string;
                startTime?: null | string;
                statusMessage?: null | string;
                traceId?: null | string;
                version?: null | string;
            };
        } & {
            id: string;
            metadata?: unknown;
            timestamp: string;
        }
        | {
            type: "span-update";
        } & {
            body: {
                endTime?: null | string;
            } & {
                id: string;
            } & {
                input?: unknown;
                level?:
                    | "DEBUG"
                    | "DEFAULT"
                    | "WARNING"
                    | "ERROR";
                metadata?: unknown;
                name?: null | string;
                output?: unknown;
                parentObservationId?: null | string;
                startTime?: null | string;
                statusMessage?: null | string;
                traceId?: null | string;
                version?: null | string;
            };
        } & {
            id: string;
            metadata?: unknown;
            timestamp: string;
        }
        | {
            type: "generation-create";
        } & {
            body: {
                completionStartTime?: null | string;
                model?: null | string;
                modelParameters?: null | {
                    [key: string]: (...)[(...)]["MapValue"];
                };
                promptName?: null | string;
                promptVersion?: null | number;
                usage?: {
                    input?: null | number;
                    inputCost?: null | number;
                    output?: null | number;
                    outputCost?: null | number;
                    total?: null | number;
                    totalCost?: null | number;
                    unit?:
                        | "CHARACTERS"
                        | "TOKENS"
                        | "MILLISECONDS"
                        | "SECONDS"
                        | "IMAGES"
                        | "REQUESTS";
                } | {
                    completionTokens?: null | number;
                    promptTokens?: null | number;
                    totalTokens?: null | number;
                };
            } & {
                endTime?: null | string;
            } & {
                id?: null | string;
            } & {
                input?: unknown;
                level?:
                    | "DEBUG"
                    | "DEFAULT"
                    | "WARNING"
                    | "ERROR";
                metadata?: unknown;
                name?: null | string;
                output?: unknown;
                parentObservationId?: null | string;
                startTime?: null | string;
                statusMessage?: null | string;
                traceId?: null | string;
                version?: null | string;
            };
        } & {
            id: string;
            metadata?: unknown;
            timestamp: string;
        }
        | {
            type: "generation-update";
        } & {
            body: {
                completionStartTime?: null | string;
                model?: null | string;
                modelParameters?: null | {
                    [key: string]: (...)[(...)]["MapValue"];
                };
                promptName?: null | string;
                promptVersion?: null | number;
                usage?: {
                    input?: null | number;
                    inputCost?: null | number;
                    output?: null | number;
                    outputCost?: null | number;
                    total?: null | number;
                    totalCost?: null | number;
                    unit?:
                        | "CHARACTERS"
                        | "TOKENS"
                        | "MILLISECONDS"
                        | "SECONDS"
                        | "IMAGES"
                        | "REQUESTS";
                } | {
                    completionTokens?: null | number;
                    promptTokens?: null | number;
                    totalTokens?: null | number;
                };
            } & {
                endTime?: null | string;
            } & {
                id: string;
            } & {
                input?: unknown;
                level?:
                    | "DEBUG"
                    | "DEFAULT"
                    | "WARNING"
                    | "ERROR";
                metadata?: unknown;
                name?: null | string;
                output?: unknown;
                parentObservationId?: null | string;
                startTime?: null | string;
                statusMessage?: null | string;
                traceId?: null | string;
                version?: null | string;
            };
        } & {
            id: string;
            metadata?: unknown;
            timestamp: string;
        }
        | {
            type: "event-create";
        } & {
            body: {
                id?: null | string;
            } & {
                input?: unknown;
                level?:
                    | "DEBUG"
                    | "DEFAULT"
                    | "WARNING"
                    | "ERROR";
                metadata?: unknown;
                name?: null | string;
                output?: unknown;
                parentObservationId?: null | string;
                startTime?: null | string;
                statusMessage?: null | string;
                traceId?: null | string;
                version?: null | string;
            };
        } & {
            id: string;
            metadata?: unknown;
            timestamp: string;
        }
        | {
            type: "sdk-log";
        } & {
            body: {
                log: unknown;
            };
        } & {
            id: string;
            metadata?: unknown;
            timestamp: string;
        }
        | {
            type: "observation-create";
        } & {
            body: {
                completionStartTime?: null | string;
                endTime?: null | string;
                id?: null | string;
                input?: unknown;
                level?:
                    | "DEBUG"
                    | "DEFAULT"
                    | "WARNING"
                    | "ERROR";
                metadata?: unknown;
                model?: null | string;
                modelParameters?: null | {
                    [key: string]: components["schemas"]["MapValue"];
                };
                name?: null | string;
                output?: unknown;
                parentObservationId?: null | string;
                startTime?: null | string;
                statusMessage?: null | string;
                traceId?: null | string;
                type: "SPAN" | "GENERATION" | "EVENT";
                usage?: {
                    input?: null | number;
                    inputCost?: null | number;
                    output?: null | number;
                    outputCost?: null | number;
                    total?: null | number;
                    totalCost?: null | number;
                    unit?:
                        | "CHARACTERS"
                        | "TOKENS"
                        | "MILLISECONDS"
                        | "SECONDS"
                        | "IMAGES"
                        | "REQUESTS";
                };
                version?: null | string;
            };
        } & {
            id: string;
            metadata?: unknown;
            timestamp: string;
        }
        | {
            type: "observation-update";
        } & {
            body: {
                completionStartTime?: null | string;
                endTime?: null | string;
                id?: null | string;
                input?: unknown;
                level?:
                    | "DEBUG"
                    | "DEFAULT"
                    | "WARNING"
                    | "ERROR";
                metadata?: unknown;
                model?: null | string;
                modelParameters?: null | {
                    [key: string]: components["schemas"]["MapValue"];
                };
                name?: null | string;
                output?: unknown;
                parentObservationId?: null | string;
                startTime?: null | string;
                statusMessage?: null | string;
                traceId?: null | string;
                type: "SPAN" | "GENERATION" | "EVENT";
                usage?: {
                    input?: null | number;
                    inputCost?: null | number;
                    output?: null | number;
                    outputCost?: null | number;
                    total?: null | number;
                    totalCost?: null | number;
                    unit?:
                        | "CHARACTERS"
                        | "TOKENS"
                        | "MILLISECONDS"
                        | "SECONDS"
                        | "IMAGES"
                        | "REQUESTS";
                };
                version?: null | string;
            };
        } & {
            id: string;
            metadata?: unknown;
            timestamp: string;
        })[]>

  • Parameters

    • name: string

    Returns Promise<Omit<{
        createdAt: Date;
        description?: null | string;
        id: string;
        metadata?: any;
        name: string;
        projectId: string;
        updatedAt: Date;
    }, "externalId" | "traceIdType">>

  • Parameters

    • query: undefined | {
          datasetName?: null | string;
          limit?: null | number;
          page?: null | number;
          sourceObservationId?: null | string;
          sourceTraceId?: null | string;
      }

    Returns Promise<Omit<{
        data: {
            createdAt: string;
            datasetId: string;
            datasetName: string;
            expectedOutput?: unknown;
            id: string;
            input?: unknown;
            metadata?: unknown;
            sourceObservationId?: null | string;
            sourceTraceId?: null | string;
            status: "ACTIVE" | "ARCHIVED";
            updatedAt: string;
        }[];
        meta: {
            limit: number;
            page: number;
            totalItems: number;
            totalPages: number;
        };
    }, "externalId" | "traceIdType">>

  • Parameters

    • p: {
          body?: string | Buffer;
          fetchTimeout?: number;
          method:
              | "GET"
              | "POST"
              | "PUT"
              | "PATCH";
      }
      • Optionalbody?: string | Buffer
      • OptionalfetchTimeout?: number
      • method:
            | "GET"
            | "POST"
            | "PUT"
            | "PATCH"

    Returns LangfuseFetchOptions

  • Parameters

    • response: any

    Returns any

  • Parameters

    • body: Omit<{
          completionStartTime?: null | Date;
          endTime?: null | Date;
          id: string;
          input?: any;
          level?:
              | "DEBUG"
              | "DEFAULT"
              | "WARNING"
              | "ERROR";
          metadata?: any;
          model?: null | string;
          modelParameters?: null | {
              [key: string]: components["schemas"]["MapValue"];
          };
          name?: null | string;
          output?: any;
          parentObservationId?: null | string;
          promptName?: null | string;
          promptVersion?: null | number;
          startTime?: null | Date;
          statusMessage?: null | string;
          traceId?: null | string;
          usage?: {
              input?: null | number;
              inputCost?: null | number;
              output?: null | number;
              outputCost?: null | number;
              total?: null | number;
              totalCost?: null | number;
              unit?:
                  | "CHARACTERS"
                  | "TOKENS"
                  | "MILLISECONDS"
                  | "SECONDS"
                  | "IMAGES"
                  | "REQUESTS";
          } | {
              completionTokens?: null | number;
              promptTokens?: null | number;
              totalTokens?: null | number;
          };
          version?: null | string;
      }, "externalId" | "traceIdType">

    Returns this

  • Parameters

    • body: Omit<{
          endTime?: null | Date;
          id: string;
          input?: any;
          level?:
              | "DEBUG"
              | "DEFAULT"
              | "WARNING"
              | "ERROR";
          metadata?: any;
          name?: null | string;
          output?: any;
          parentObservationId?: null | string;
          startTime?: null | Date;
          statusMessage?: null | string;
          traceId?: null | string;
          version?: null | string;
      }, "externalId" | "traceIdType">

    Returns this

  • Returns Promise<void>

  • Creates a dataset. Upserts the dataset if it already exists.

    Parameters

    • dataset: string | {
          description?: string;
          metadata?: any;
          name: string;
      }

      Can be either a string (name) or an object with name, description and metadata

    Returns Promise<Omit<{
        createdAt: Date;
        description?: null | string;
        id: string;
        metadata?: any;
        name: string;
        projectId: string;
        updatedAt: Date;
    }, "externalId" | "traceIdType">>

    A promise that resolves to the response of the create operation.

  • Creates a dataset item. Upserts the item if it already exists.

    Parameters

    • body: Omit<{
          datasetName: string;
          expectedOutput?: any;
          id?: null | string;
          input?: any;
          metadata?: any;
          sourceObservationId?: null | string;
          sourceTraceId?: null | string;
          status?: "ACTIVE" | "ARCHIVED";
      }, "externalId" | "traceIdType">

      The body of the dataset item to be created.

    Returns Promise<Omit<{
        createdAt: Date;
        datasetId: string;
        datasetName: string;
        expectedOutput?: any;
        id: string;
        input?: any;
        metadata?: any;
        sourceObservationId?: null | string;
        sourceTraceId?: null | string;
        status: "ACTIVE" | "ARCHIVED";
        updatedAt: Date;
    }, "externalId" | "traceIdType">>

    A promise that resolves to the response of the create operation.

  • Parameters

    • body: Omit<{
          datasetItemId: string;
          metadata?: any;
          observationId?: null | string;
          runDescription?: null | string;
          runName: string;
          traceId?: null | string;
      }, "externalId" | "traceIdType">

    Returns Promise<Omit<{
        createdAt: Date;
        datasetItemId: string;
        datasetRunId: string;
        datasetRunName: string;
        id: string;
        observationId?: null | string;
        traceId: string;
        updatedAt: Date;
    }, "externalId" | "traceIdType">>

  • Parameters

    • body: CreateChatPromptBody

    Returns Promise<ChatPromptClient>

  • Parameters

    • body: CreateTextPromptBody

    Returns Promise<TextPromptClient>

  • Parameters

    • body: CreateLangfusePromptBody

    Returns Promise<{
        type: "chat";
    } & {
        prompt: {
            content: string;
            role: string;
        }[];
    } & {
        config: unknown;
        labels: string[];
        name: string;
        tags: string[];
        version: number;
    } | {
        type: "text";
    } & {
        prompt: string;
    } & {
        config: unknown;
        labels: string[];
        name: string;
        tags: string[];
        version: number;
    }>

  • Parameters

    • Optionalenabled: boolean

    Returns void

  • ** QUEUEING AND FLUSHING *

    Parameters

    • type:
          | "trace-create"
          | "score-create"
          | "span-create"
          | "span-update"
          | "generation-create"
          | "generation-update"
          | "event-create"
          | "sdk-log"
          | "observation-create"
          | "observation-update"
    • body: EventBody

    Returns void

  • Parameters

    • body: Omit<{
          id?: null | string;
          input?: any;
          level?:
              | "DEBUG"
              | "DEFAULT"
              | "WARNING"
              | "ERROR";
          metadata?: any;
          name?: null | string;
          output?: any;
          parentObservationId?: null | string;
          startTime?: null | Date;
          statusMessage?: null | string;
          traceId?: null | string;
          version?: null | string;
      }, "externalId" | "traceIdType">

    Returns LangfuseEventClient

  • Parameters

    • body: Omit<{
          id?: null | string;
          input?: any;
          level?:
              | "DEBUG"
              | "DEFAULT"
              | "WARNING"
              | "ERROR";
          metadata?: any;
          name?: null | string;
          output?: any;
          parentObservationId?: null | string;
          startTime?: null | Date;
          statusMessage?: null | string;
          traceId?: null | string;
          version?: null | string;
      }, "externalId" | "traceIdType">

    Returns string

  • Parameters

    • url: string
    • options: LangfuseFetchOptions

    Returns Promise<LangfuseFetchResponse>

  • Parameters

    • observationId: string

    Returns Promise<{
        data: Omit<{
            calculatedInputCost?: null | number;
            calculatedOutputCost?: null | number;
            calculatedTotalCost?: null | number;
            completionStartTime?: null | Date;
            endTime?: null | Date;
            id: string;
            input?: any;
            inputPrice?: null | number;
            latency?: null | number;
            level:
                | "DEBUG"
                | "DEFAULT"
                | "WARNING"
                | "ERROR";
            metadata?: any;
            model?: null | string;
            modelId?: null | string;
            modelParameters?: null | {
                [key: string]: components["schemas"]["MapValue"];
            };
            name?: null | string;
            output?: any;
            outputPrice?: null | number;
            parentObservationId?: null | string;
            promptId?: null | string;
            promptName?: null | string;
            promptVersion?: null | number;
            startTime: Date;
            statusMessage?: null | string;
            timeToFirstToken?: null | number;
            totalPrice?: null | number;
            traceId?: null | string;
            type: string;
            usage?: {
                input?: null | number;
                inputCost?: null | number;
                output?: null | number;
                outputCost?: null | number;
                total?: null | number;
                totalCost?: null | number;
                unit?:
                    | "CHARACTERS"
                    | "TOKENS"
                    | "MILLISECONDS"
                    | "SECONDS"
                    | "IMAGES"
                    | "REQUESTS";
            };
            version?: null | string;
        }, "externalId" | "traceIdType">;
    }>

  • Parameters

    • Optionalquery: GetLangfuseObservationsQuery

    Returns Promise<Omit<{
        data: ({
            calculatedInputCost?: null | number;
            calculatedOutputCost?: null | number;
            calculatedTotalCost?: null | number;
            inputPrice?: null | number;
            latency?: null | number;
            modelId?: null | string;
            outputPrice?: null | number;
            promptName?: null | string;
            promptVersion?: null | number;
            timeToFirstToken?: null | number;
            totalPrice?: null | number;
        } & {
            completionStartTime?: null | string;
            endTime?: null | string;
            id: string;
            input?: unknown;
            level:
                | "DEBUG"
                | "DEFAULT"
                | "WARNING"
                | "ERROR";
            metadata?: unknown;
            model?: null | string;
            modelParameters?: null | {
                [key: string]: components["schemas"]["MapValue"];
            };
            name?: null | string;
            output?: unknown;
            parentObservationId?: null | string;
            promptId?: null | string;
            startTime: string;
            statusMessage?: null | string;
            traceId?: null | string;
            type: string;
            usage?: {
                input?: null | number;
                inputCost?: null | number;
                output?: null | number;
                outputCost?: null | number;
                total?: null | number;
                totalCost?: null | number;
                unit?:
                    | "CHARACTERS"
                    | "TOKENS"
                    | "MILLISECONDS"
                    | "SECONDS"
                    | "IMAGES"
                    | "REQUESTS";
            };
            version?: null | string;
        })[];
        meta: {
            limit: number;
            page: number;
            totalItems: number;
            totalPages: number;
        };
    }, "externalId" | "traceIdType">>

  • Parameters

    • Optionalquery: GetLangfuseSessionsQuery

    Returns Promise<Omit<{
        data: {
            createdAt: string;
            id: string;
            projectId: string;
        }[];
        meta: {
            limit: number;
            page: number;
            totalItems: number;
            totalPages: number;
        };
    }, "externalId" | "traceIdType">>

  • Parameters

    • traceId: string

    Returns Promise<{
        data: Omit<{
            htmlPath: string;
            id: string;
            input?: any;
            latency: number;
            metadata?: any;
            name?: null | string;
            observations: ({
                calculatedInputCost?: null | number;
                calculatedOutputCost?: null | number;
                calculatedTotalCost?: null | number;
                inputPrice?: null | number;
                latency?: null | number;
                modelId?: null | string;
                outputPrice?: null | number;
                promptName?: null | string;
                promptVersion?: null | number;
                timeToFirstToken?: null | number;
                totalPrice?: null | number;
            } & {
                completionStartTime?: null | string;
                endTime?: null | string;
                id: string;
                input?: unknown;
                level:
                    | "DEBUG"
                    | "DEFAULT"
                    | "WARNING"
                    | "ERROR";
                metadata?: unknown;
                model?: null | string;
                modelParameters?: null | {
                    [key: string]: (...)[(...)]["MapValue"];
                };
                name?: null | string;
                output?: unknown;
                parentObservationId?: null | string;
                promptId?: null | string;
                startTime: string;
                statusMessage?: null | string;
                traceId?: null | string;
                type: string;
                usage?: {
                    input?: null | number;
                    inputCost?: null | number;
                    output?: null | number;
                    outputCost?: null | number;
                    total?: null | number;
                    totalCost?: null | number;
                    unit?:
                        | "CHARACTERS"
                        | "TOKENS"
                        | "MILLISECONDS"
                        | "SECONDS"
                        | "IMAGES"
                        | "REQUESTS";
                };
                version?: null | string;
            })[];
            output?: any;
            public?: null | boolean;
            release?: null | string;
            scores: ({
                dataType: "NUMERIC";
            } & {
                value: number;
            } & {
                authorUserId?: null | string;
                comment?: null | string;
                configId?: null | string;
                createdAt: string;
                id: string;
                name: string;
                observationId?: null | string;
                queueId?: null | string;
                source: "ANNOTATION" | "API" | "EVAL";
                timestamp: string;
                traceId: string;
                updatedAt: string;
            } | {
                dataType: "CATEGORICAL";
            } & {
                stringValue: string;
                value?: null | number;
            } & {
                authorUserId?: null | string;
                comment?: null | string;
                configId?: null | string;
                createdAt: string;
                id: string;
                name: string;
                observationId?: null | string;
                queueId?: null | string;
                source: "ANNOTATION" | "API" | "EVAL";
                timestamp: string;
                traceId: string;
                updatedAt: string;
            } | {
                dataType: "BOOLEAN";
            } & {
                stringValue: string;
                value: number;
            } & {
                authorUserId?: null | string;
                comment?: null | string;
                configId?: null | string;
                createdAt: string;
                id: string;
                name: string;
                observationId?: null | string;
                queueId?: null | string;
                source: "ANNOTATION" | "API" | "EVAL";
                timestamp: string;
                traceId: string;
                updatedAt: string;
            })[];
            sessionId?: null | string;
            tags?: null | string[];
            timestamp: Date;
            totalCost: number;
            userId?: null | string;
            version?: null | string;
        }, "externalId" | "traceIdType">;
    }>

  • Parameters

    • Optionalquery: GetLangfuseTracesQuery

    Returns Promise<Omit<{
        data: ({
            htmlPath: string;
            latency: number;
            observations: string[];
            scores: string[];
            totalCost: number;
        } & {
            id: string;
            input?: unknown;
            metadata?: unknown;
            name?: null | string;
            output?: unknown;
            public?: null | boolean;
            release?: null | string;
            sessionId?: null | string;
            tags?: null | string[];
            timestamp: string;
            userId?: null | string;
            version?: null | string;
        })[];
        meta: {
            limit: number;
            page: number;
            totalItems: number;
            totalPages: number;
        };
    }, "externalId" | "traceIdType">>

  • Parameters

    • __namedParameters: {
          data: any;
          field: "input" | "output" | "metadata";
          observationId?: string;
          traceId: string;
      }
      • data: any
      • field: "input" | "output" | "metadata"
      • OptionalobservationId?: string
      • traceId: string

    Returns Promise<any>

  • Parameters

    • Optionalcallback: ((err?: any, data?: any) => void)
        • (err?, data?): void
        • Parameters

          • Optionalerr: any
          • Optionaldata: any

          Returns void

    Returns void

  • Asynchronously flushes all events that are not yet sent to the server. This function always resolves, even if there were errors when flushing. Errors are emitted as "error" events and the promise resolves.

    Returns Promise<void>

    A promise that resolves when the flushing is completed.

  • Parameters

    • body: Omit<Omit<{
          completionStartTime?: null | Date;
          endTime?: null | Date;
          id?: null | string;
          input?: any;
          level?:
              | "DEBUG"
              | "DEFAULT"
              | "WARNING"
              | "ERROR";
          metadata?: any;
          model?: null | string;
          modelParameters?: null | {
              [key: string]: components["schemas"]["MapValue"];
          };
          name?: null | string;
          output?: any;
          parentObservationId?: null | string;
          promptName?: null | string;
          promptVersion?: null | number;
          startTime?: null | Date;
          statusMessage?: null | string;
          traceId?: null | string;
          usage?: {
              input?: null | number;
              inputCost?: null | number;
              output?: null | number;
              outputCost?: null | number;
              total?: null | number;
              totalCost?: null | number;
              unit?:
                  | "CHARACTERS"
                  | "TOKENS"
                  | "MILLISECONDS"
                  | "SECONDS"
                  | "IMAGES"
                  | "REQUESTS";
          } | {
              completionTokens?: null | number;
              promptTokens?: null | number;
              totalTokens?: null | number;
          };
          version?: null | string;
      }, "externalId" | "traceIdType">, "promptName" | "promptVersion"> & PromptInput

    Returns LangfuseGenerationClient

  • Parameters

    • body: Omit<Omit<{
          completionStartTime?: null | Date;
          endTime?: null | Date;
          id?: null | string;
          input?: any;
          level?:
              | "DEBUG"
              | "DEFAULT"
              | "WARNING"
              | "ERROR";
          metadata?: any;
          model?: null | string;
          modelParameters?: null | {
              [key: string]: components["schemas"]["MapValue"];
          };
          name?: null | string;
          output?: any;
          parentObservationId?: null | string;
          promptName?: null | string;
          promptVersion?: null | number;
          startTime?: null | Date;
          statusMessage?: null | string;
          traceId?: null | string;
          usage?: {
              input?: null | number;
              inputCost?: null | number;
              output?: null | number;
              outputCost?: null | number;
              total?: null | number;
              totalCost?: null | number;
              unit?:
                  | "CHARACTERS"
                  | "TOKENS"
                  | "MILLISECONDS"
                  | "SECONDS"
                  | "IMAGES"
                  | "REQUESTS";
          } | {
              completionTokens?: null | number;
              promptTokens?: null | number;
              totalTokens?: null | number;
          };
          version?: null | string;
      }, "externalId" | "traceIdType">, "promptName" | "promptVersion"> & PromptInput

    Returns string

  • Returns any

  • Returns void

  • Parameters

    • name: string
    • Optionaloptions: {
          fetchItemsPageSize: number;
      }
      • fetchItemsPageSize: number

    Returns Promise<{
        description?: string;
        id: string;
        items: DatasetItem[];
        metadata?: any;
        name: string;
        projectId: string;
    }>

  • Parameters

    • id: string

    Returns Promise<Omit<{
        createdAt: Date;
        datasetId: string;
        datasetName: string;
        expectedOutput?: any;
        id: string;
        input?: any;
        metadata?: any;
        sourceObservationId?: null | string;
        sourceTraceId?: null | string;
        status: "ACTIVE" | "ARCHIVED";
        updatedAt: Date;
    }, "externalId" | "traceIdType">>

  • Parameters

    • params: Omit<{
          datasetName: string;
          runName: string;
      }, "externalId" | "traceIdType">

    Returns Promise<Omit<{
        createdAt: Date;
        datasetId: string;
        datasetName: string;
        datasetRunItems: {
            createdAt: string;
            datasetItemId: string;
            datasetRunId: string;
            datasetRunName: string;
            id: string;
            observationId?: null | string;
            traceId: string;
            updatedAt: string;
        }[];
        description?: null | string;
        id: string;
        metadata?: any;
        name: string;
        updatedAt: Date;
    }, "externalId" | "traceIdType">>

  • Parameters

    • datasetName: string
    • Optionalquery: {
          limit?: null | number;
          page?: null | number;
      }
      • Optionallimit?: null | number

        limit of items per page

      • Optionalpage?: null | number

        page number, starts at 1

    Returns Promise<Omit<{
        data: {
            createdAt: string;
            datasetId: string;
            datasetName: string;
            description?: null | string;
            id: string;
            metadata?: unknown;
            name: string;
            updatedAt: string;
        }[];
        meta: {
            limit: number;
            page: number;
            totalItems: number;
            totalPages: number;
        };
    }, "externalId" | "traceIdType">>

  • Returns string

  • Returns string

  • Type Parameters

    • T

    Parameters

    • key: LangfusePersistedProperty

    Returns undefined | T

  • Parameters

    • name: string
    • Optionalversion: number
    • Optionaloptions: {
          cacheTtlSeconds?: number;
          fallback?: string;
          fetchTimeoutMs?: number;
          label?: string;
          maxRetries?: number;
          type?: "text";
      }
      • OptionalcacheTtlSeconds?: number
      • Optionalfallback?: string
      • OptionalfetchTimeoutMs?: number
      • Optionallabel?: string
      • OptionalmaxRetries?: number
      • Optionaltype?: "text"

    Returns Promise<TextPromptClient>

  • Parameters

    • name: string
    • Optionalversion: number
    • Optionaloptions: {
          cacheTtlSeconds?: number;
          fallback?: Omit<{
              content: string;
              role: string;
          }, "externalId" | "traceIdType">[];
          fetchTimeoutMs?: number;
          label?: string;
          maxRetries?: number;
          type: "chat";
      }
      • OptionalcacheTtlSeconds?: number
      • Optionalfallback?: Omit<{
            content: string;
            role: string;
        }, "externalId" | "traceIdType">[]
      • OptionalfetchTimeoutMs?: number
      • Optionallabel?: string
      • OptionalmaxRetries?: number
      • type: "chat"

    Returns Promise<ChatPromptClient>

  • Parameters

    • name: string
    • Optionalversion: number
    • Optionallabel: string
    • OptionalmaxRetries: number
    • OptionalrequestTimeout: number

    Returns Promise<GetLangfusePromptResponse>

  • Returns string

  • Parameters

    • event: string
    • cb: ((...args: any[]) => void)
        • (...args): void
        • Parameters

          • Rest...args: any[]

          Returns void

    Returns (() => void)

      • (): void
      • Returns void

  • Parameters

    • type:
          | "trace-create"
          | "score-create"
          | "span-create"
          | "span-update"
          | "generation-create"
          | "generation-update"
          | "event-create"
          | "sdk-log"
          | "observation-create"
          | "observation-update"
    • body: EventBody

    Returns Promise<void>

  • Parameters

    • type:
          | "trace-create"
          | "score-create"
          | "span-create"
          | "span-update"
          | "generation-create"
          | "generation-update"
          | "event-create"
          | "sdk-log"
          | "observation-create"
          | "observation-update"
    • body: EventBody

    Returns Promise<void>

  • Parameters

    • queue: LangfuseQueueItem[]
    • MAX_MSG_SIZE: number
    • BATCH_SIZE_LIMIT: number

    Returns {
        processedItems: LangfuseQueueItem[];
        remainingItems: LangfuseQueueItem[];
    }

    • processedItems: LangfuseQueueItem[]
    • remainingItems: LangfuseQueueItem[]
  • Parameters

    • body: Omit<{
          comment?: null | string;
          configId?: null | string;
          dataType?: "NUMERIC" | "BOOLEAN" | "CATEGORICAL";
          id?: null | string;
          name: string;
          observationId?: null | string;
          traceId: string;
          value: string | number;
      }, "externalId" | "traceIdType">

    Returns this

  • Parameters

    • body: Omit<{
          comment?: null | string;
          configId?: null | string;
          dataType?: "NUMERIC" | "BOOLEAN" | "CATEGORICAL";
          id?: null | string;
          name: string;
          observationId?: null | string;
          traceId: string;
          value: string | number;
      }, "externalId" | "traceIdType">

    Returns string

  • Type Parameters

    • T

    Parameters

    • key: LangfusePersistedProperty
    • value: null | T

    Returns void

  • Returns void

  • Returns Promise<void>

  • Parameters

    • body: Omit<{
          endTime?: null | Date;
          id?: null | string;
          input?: any;
          level?:
              | "DEBUG"
              | "DEFAULT"
              | "WARNING"
              | "ERROR";
          metadata?: any;
          name?: null | string;
          output?: any;
          parentObservationId?: null | string;
          startTime?: null | Date;
          statusMessage?: null | string;
          traceId?: null | string;
          version?: null | string;
      }, "externalId" | "traceIdType">

    Returns LangfuseSpanClient

  • Parameters

    • body: Omit<{
          endTime?: null | Date;
          id?: null | string;
          input?: any;
          level?:
              | "DEBUG"
              | "DEFAULT"
              | "WARNING"
              | "ERROR";
          metadata?: any;
          name?: null | string;
          output?: any;
          parentObservationId?: null | string;
          startTime?: null | Date;
          statusMessage?: null | string;
          traceId?: null | string;
          version?: null | string;
      }, "externalId" | "traceIdType">

    Returns string

  • Parameters

    • Optionalbody: Omit<{
          id?: null | string;
          input?: any;
          metadata?: any;
          name?: null | string;
          output?: any;
          public?: null | boolean;
          release?: null | string;
          sessionId?: null | string;
          tags?: null | string[];
          timestamp?: null | Date;
          userId?: null | string;
          version?: null | string;
      }, "externalId" | "traceIdType">

    Returns LangfuseTraceClient

  • ** Handlers for each object type *

    Parameters

    • body: Omit<{
          id?: null | string;
          input?: any;
          metadata?: any;
          name?: null | string;
          output?: any;
          public?: null | boolean;
          release?: null | string;
          sessionId?: null | string;
          tags?: null | string[];
          timestamp?: null | Date;
          userId?: null | string;
          version?: null | string;
      }, "externalId" | "traceIdType">

    Returns string

  • Truncates the event body if its byte size exceeds the specified maximum byte size. Emits a warning event if truncation occurs. The fields that may be truncated are: "input", "output", and "metadata". The fields are truncated in the order of their size, from largest to smallest until the total byte size is within the limit.

    Parameters

    • body: EventBody
    • maxByteSize: number

    Returns EventBody

  • Parameters

    • body: Omit<Omit<{
          completionStartTime?: null | Date;
          endTime?: null | Date;
          id: string;
          input?: any;
          level?:
              | "DEBUG"
              | "DEFAULT"
              | "WARNING"
              | "ERROR";
          metadata?: any;
          model?: null | string;
          modelParameters?: null | {
              [key: string]: components["schemas"]["MapValue"];
          };
          name?: null | string;
          output?: any;
          parentObservationId?: null | string;
          promptName?: null | string;
          promptVersion?: null | number;
          startTime?: null | Date;
          statusMessage?: null | string;
          traceId?: null | string;
          usage?: {
              input?: null | number;
              inputCost?: null | number;
              output?: null | number;
              outputCost?: null | number;
              total?: null | number;
              totalCost?: null | number;
              unit?:
                  | "CHARACTERS"
                  | "TOKENS"
                  | "MILLISECONDS"
                  | "SECONDS"
                  | "IMAGES"
                  | "REQUESTS";
          } | {
              completionTokens?: null | number;
              promptTokens?: null | number;
              totalTokens?: null | number;
          };
          version?: null | string;
      }, "externalId" | "traceIdType">, "promptName" | "promptVersion"> & PromptInput

    Returns string

  • Parameters

    • body: Omit<{
          endTime?: null | Date;
          id: string;
          input?: any;
          level?:
              | "DEBUG"
              | "DEFAULT"
              | "WARNING"
              | "ERROR";
          metadata?: any;
          name?: null | string;
          output?: any;
          parentObservationId?: null | string;
          startTime?: null | Date;
          statusMessage?: null | string;
          traceId?: null | string;
          version?: null | string;
      }, "externalId" | "traceIdType">

    Returns string