langfuse
Version:
1,478 lines (1,477 loc) • 78 kB
text/typescript
import { LangfuseCoreOptions, LangfuseCore, LangfusePersistedProperty, LangfuseFetchOptions, LangfuseFetchResponse, LangfuseWebStateless, LangfuseTraceClient, LangfuseSpanClient, LangfuseGenerationClient, LangfusePromptClient, CreateLangfuseTraceBody, CreateLangfuseGenerationBody } from 'langfuse-core';
export { ChatPromptClient, LangfuseEventClient, LangfuseGenerationClient, LangfuseMedia, LangfusePromptClient, LangfusePromptRecord, LangfuseSpanClient, LangfuseTraceClient, TextPromptClient } from 'langfuse-core';
import OpenAI from 'openai';
/** AnnotationQueueStatus */
type ApiAnnotationQueueStatus = "PENDING" | "COMPLETED";
/** AnnotationQueueObjectType */
type ApiAnnotationQueueObjectType = "TRACE" | "OBSERVATION";
/** AnnotationQueue */
interface ApiAnnotationQueue {
id: string;
name: string;
description?: string | null;
scoreConfigIds: string[];
/** @format date-time */
createdAt: string;
/** @format date-time */
updatedAt: string;
}
/** AnnotationQueueItem */
interface ApiAnnotationQueueItem {
id: string;
queueId: string;
objectId: string;
objectType: ApiAnnotationQueueObjectType;
status: ApiAnnotationQueueStatus;
/** @format date-time */
completedAt?: string | null;
/** @format date-time */
createdAt: string;
/** @format date-time */
updatedAt: string;
}
/** PaginatedAnnotationQueues */
interface ApiPaginatedAnnotationQueues {
data: ApiAnnotationQueue[];
meta: ApiUtilsMetaResponse;
}
/** PaginatedAnnotationQueueItems */
interface ApiPaginatedAnnotationQueueItems {
data: ApiAnnotationQueueItem[];
meta: ApiUtilsMetaResponse;
}
/** CreateAnnotationQueueItemRequest */
interface ApiCreateAnnotationQueueItemRequest {
objectId: string;
objectType: ApiAnnotationQueueObjectType;
/** Defaults to PENDING for new queue items */
status?: ApiAnnotationQueueStatus | null;
}
/** UpdateAnnotationQueueItemRequest */
interface ApiUpdateAnnotationQueueItemRequest {
status?: ApiAnnotationQueueStatus | null;
}
/** DeleteAnnotationQueueItemResponse */
interface ApiDeleteAnnotationQueueItemResponse {
success: boolean;
message: string;
}
/** CreateCommentRequest */
interface ApiCreateCommentRequest {
/** The id of the project to attach the comment to. */
projectId: string;
/** The type of the object to attach the comment to (trace, observation, session, prompt). */
objectType: string;
/** The id of the object to attach the comment to. If this does not reference a valid existing object, an error will be thrown. */
objectId: string;
/** The content of the comment. May include markdown. Currently limited to 3000 characters. */
content: string;
/** The id of the user who created the comment. */
authorUserId?: string | null;
}
/** CreateCommentResponse */
interface ApiCreateCommentResponse {
/** The id of the created object in Langfuse */
id: string;
}
/** GetCommentsResponse */
interface ApiGetCommentsResponse {
data: ApiComment[];
meta: ApiUtilsMetaResponse;
}
/** Trace */
interface ApiTrace {
/** The unique identifier of a trace */
id: string;
/**
* The timestamp when the trace was created
* @format date-time
*/
timestamp: string;
/** The name of the trace */
name?: string | null;
/** The input data of the trace. Can be any JSON. */
input?: any;
/** The output data of the trace. Can be any JSON. */
output?: any;
/** The session identifier associated with the trace */
sessionId?: string | null;
/** The release version of the application when the trace was created */
release?: string | null;
/** The version of the trace */
version?: string | null;
/** The user identifier associated with the trace */
userId?: string | null;
/** The metadata associated with the trace. Can be any JSON. */
metadata?: any;
/** The tags associated with the trace. Can be an array of strings or null. */
tags?: string[] | null;
/** Public traces are accessible via url without login */
public?: boolean | null;
/** The environment from which this trace originated. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'. */
environment?: string | null;
}
/** TraceWithDetails */
type ApiTraceWithDetails = ApiTrace & {
/** Path of trace in Langfuse UI */
htmlPath: string;
/**
* Latency of trace in seconds
* @format double
*/
latency: number;
/**
* Cost of trace in USD
* @format double
*/
totalCost: number;
/** List of observation ids */
observations: string[];
/** List of score ids */
scores: string[];
};
/** TraceWithFullDetails */
type ApiTraceWithFullDetails = ApiTrace & {
/** Path of trace in Langfuse UI */
htmlPath: string;
/**
* Latency of trace in seconds
* @format double
*/
latency: number;
/**
* Cost of trace in USD
* @format double
*/
totalCost: number;
/** List of observations */
observations: ApiObservationsView[];
/** List of scores */
scores: ApiScore[];
};
/** Session */
interface ApiSession {
id: string;
/** @format date-time */
createdAt: string;
projectId: string;
/** The environment from which this session originated. */
environment?: string | null;
}
/** SessionWithTraces */
type ApiSessionWithTraces = ApiSession & {
traces: ApiTrace[];
};
/** Observation */
interface ApiObservation {
/** The unique identifier of the observation */
id: string;
/** The trace ID associated with the observation */
traceId?: string | null;
/** The type of the observation */
type: string;
/** The name of the observation */
name?: string | null;
/**
* The start time of the observation
* @format date-time
*/
startTime: string;
/**
* The end time of the observation.
* @format date-time
*/
endTime?: string | null;
/**
* The completion start time of the observation
* @format date-time
*/
completionStartTime?: string | null;
/** The model used for the observation */
model?: string | null;
/** The parameters of the model used for the observation */
modelParameters?: Record<string, ApiMapValue>;
/** The input data of the observation */
input?: any;
/** The version of the observation */
version?: string | null;
/** Additional metadata of the observation */
metadata?: any;
/** The output data of the observation */
output?: any;
/** (Deprecated. Use usageDetails and costDetails instead.) The usage data of the observation */
usage?: ApiUsage | null;
/** The level of the observation */
level: ApiObservationLevel;
/** The status message of the observation */
statusMessage?: string | null;
/** The parent observation ID */
parentObservationId?: string | null;
/** The prompt ID associated with the observation */
promptId?: string | null;
/** The usage details of the observation. Key is the name of the usage metric, value is the number of units consumed. The total key is the sum of all (non-total) usage metrics or the total value ingested. */
usageDetails?: Record<string, number>;
/** The cost details of the observation. Key is the name of the cost metric, value is the cost in USD. The total key is the sum of all (non-total) cost metrics or the total value ingested. */
costDetails?: Record<string, number>;
/** The environment from which this observation originated. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'. */
environment?: string | null;
}
/** ObservationsView */
type ApiObservationsView = ApiObservation & {
/** The name of the prompt associated with the observation */
promptName?: string | null;
/** The version of the prompt associated with the observation */
promptVersion?: number | null;
/** The unique identifier of the model */
modelId?: string | null;
/**
* The price of the input in USD
* @format double
*/
inputPrice?: number | null;
/**
* The price of the output in USD.
* @format double
*/
outputPrice?: number | null;
/**
* The total price in USD.
* @format double
*/
totalPrice?: number | null;
/**
* (Deprecated. Use usageDetails and costDetails instead.) The calculated cost of the input in USD
* @format double
*/
calculatedInputCost?: number | null;
/**
* (Deprecated. Use usageDetails and costDetails instead.) The calculated cost of the output in USD
* @format double
*/
calculatedOutputCost?: number | null;
/**
* (Deprecated. Use usageDetails and costDetails instead.) The calculated total cost in USD
* @format double
*/
calculatedTotalCost?: number | null;
/**
* The latency in seconds.
* @format double
*/
latency?: number | null;
/**
* The time to the first token in seconds
* @format double
*/
timeToFirstToken?: number | null;
};
/**
* Usage
* (Deprecated. Use usageDetails and costDetails instead.) Standard interface for usage and cost
*/
interface ApiUsage {
/** Number of input units (e.g. tokens) */
input?: number | null;
/** Number of output units (e.g. tokens) */
output?: number | null;
/** Defaults to input+output if not set */
total?: number | null;
/** Unit of usage in Langfuse */
unit?: ApiModelUsageUnit | null;
/**
* USD input cost
* @format double
*/
inputCost?: number | null;
/**
* USD output cost
* @format double
*/
outputCost?: number | null;
/**
* USD total cost, defaults to input+output
* @format double
*/
totalCost?: number | null;
}
/**
* ScoreConfig
* Configuration for a score
*/
interface ApiScoreConfig {
id: string;
name: string;
/** @format date-time */
createdAt: string;
/** @format date-time */
updatedAt: string;
projectId: string;
dataType: ApiScoreDataType;
/** Whether the score config is archived. Defaults to false */
isArchived: boolean;
/**
* Sets minimum value for numerical scores. If not set, the minimum value defaults to -∞
* @format double
*/
minValue?: number | null;
/**
* Sets maximum value for numerical scores. If not set, the maximum value defaults to +∞
* @format double
*/
maxValue?: number | null;
/** Configures custom categories for categorical scores */
categories?: ApiConfigCategory[] | null;
description?: string | null;
}
/** ConfigCategory */
interface ApiConfigCategory {
/** @format double */
value: number;
label: string;
}
/** BaseScore */
interface ApiBaseScore {
id: string;
traceId: string;
name: string;
source: ApiScoreSource;
observationId?: string | null;
/** @format date-time */
timestamp: string;
/** @format date-time */
createdAt: string;
/** @format date-time */
updatedAt: string;
authorUserId?: string | null;
comment?: string | null;
/** Reference a score config on a score. When set, config and score name must be equal and value must comply to optionally defined numerical range */
configId?: string | null;
/** Reference an annotation queue on a score. Populated if the score was initially created in an annotation queue. */
queueId?: string | null;
/** The environment from which this score originated. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'. */
environment?: string | null;
}
/** NumericScore */
type ApiNumericScore = ApiBaseScore & {
/**
* The numeric value of the score
* @format double
*/
value: number;
};
/** BooleanScore */
type ApiBooleanScore = ApiBaseScore & {
/**
* The numeric value of the score. Equals 1 for "True" and 0 for "False"
* @format double
*/
value: number;
/** The string representation of the score value. Is inferred from the numeric value and equals "True" or "False" */
stringValue: string;
};
/** CategoricalScore */
type ApiCategoricalScore = ApiBaseScore & {
/**
* Only defined if a config is linked. Represents the numeric category mapping of the stringValue
* @format double
*/
value?: number | null;
/** The string representation of the score value. If no config is linked, can be any string. Otherwise, must map to a config category */
stringValue: string;
};
/** Score */
type ApiScore = ({
dataType: "NUMERIC";
} & ApiNumericScore) | ({
dataType: "CATEGORICAL";
} & ApiCategoricalScore) | ({
dataType: "BOOLEAN";
} & ApiBooleanScore);
/**
* CreateScoreValue
* The value of the score. Must be passed as string for categorical scores, and numeric for boolean and numeric scores
*/
type ApiCreateScoreValue = number | string;
/** Comment */
interface ApiComment {
id: string;
projectId: string;
/** @format date-time */
createdAt: string;
/** @format date-time */
updatedAt: string;
objectType: ApiCommentObjectType;
objectId: string;
content: string;
authorUserId?: string | null;
}
/** Dataset */
interface ApiDataset {
id: string;
name: string;
description?: string | null;
metadata?: any;
projectId: string;
/** @format date-time */
createdAt: string;
/** @format date-time */
updatedAt: string;
}
/** DatasetItem */
interface ApiDatasetItem {
id: string;
status: ApiDatasetStatus;
input?: any;
expectedOutput?: any;
metadata?: any;
sourceTraceId?: string | null;
sourceObservationId?: string | null;
datasetId: string;
datasetName: string;
/** @format date-time */
createdAt: string;
/** @format date-time */
updatedAt: string;
}
/** DatasetRunItem */
interface ApiDatasetRunItem {
id: string;
datasetRunId: string;
datasetRunName: string;
datasetItemId: string;
traceId: string;
observationId?: string | null;
/** @format date-time */
createdAt: string;
/** @format date-time */
updatedAt: string;
}
/** DatasetRun */
interface ApiDatasetRun {
/** Unique identifier of the dataset run */
id: string;
/** Name of the dataset run */
name: string;
/** Description of the run */
description?: string | null;
/** Metadata of the dataset run */
metadata?: any;
/** Id of the associated dataset */
datasetId: string;
/** Name of the associated dataset */
datasetName: string;
/**
* The date and time when the dataset run was created
* @format date-time
*/
createdAt: string;
/**
* The date and time when the dataset run was last updated
* @format date-time
*/
updatedAt: string;
}
/** DatasetRunWithItems */
type ApiDatasetRunWithItems = ApiDatasetRun & {
datasetRunItems: ApiDatasetRunItem[];
};
/**
* Model
* Model definition used for transforming usage into USD cost and/or tokenization.
*/
interface ApiModel {
id: string;
/** Name of the model definition. If multiple with the same name exist, they are applied in the following order: (1) custom over built-in, (2) newest according to startTime where model.startTime<observation.startTime */
modelName: string;
/** Regex pattern which matches this model definition to generation.model. Useful in case of fine-tuned models. If you want to exact match, use `(?i)^modelname$` */
matchPattern: string;
/**
* Apply only to generations which are newer than this ISO date.
* @format date-time
*/
startDate?: string | null;
/** Unit used by this model. */
unit?: ApiModelUsageUnit | null;
/**
* Price (USD) per input unit
* @format double
*/
inputPrice?: number | null;
/**
* Price (USD) per output unit
* @format double
*/
outputPrice?: number | null;
/**
* Price (USD) per total unit. Cannot be set if input or output price is set.
* @format double
*/
totalPrice?: number | null;
/** Optional. Tokenizer to be applied to observations which match to this model. See docs for more details. */
tokenizerId?: string | null;
/** Optional. Configuration for the selected tokenizer. Needs to be JSON. See docs for more details. */
tokenizerConfig?: any;
isLangfuseManaged: boolean;
}
/**
* ModelUsageUnit
* Unit of usage in Langfuse
*/
type ApiModelUsageUnit = "CHARACTERS" | "TOKENS" | "MILLISECONDS" | "SECONDS" | "IMAGES" | "REQUESTS";
/** ObservationLevel */
type ApiObservationLevel = "DEBUG" | "DEFAULT" | "WARNING" | "ERROR";
/** MapValue */
type ApiMapValue = string | null | number | null | boolean | null | string[] | null;
/** CommentObjectType */
type ApiCommentObjectType = "TRACE" | "OBSERVATION" | "SESSION" | "PROMPT";
/** DatasetStatus */
type ApiDatasetStatus = "ACTIVE" | "ARCHIVED";
/** ScoreSource */
type ApiScoreSource = "ANNOTATION" | "API" | "EVAL";
/** ScoreDataType */
type ApiScoreDataType = "NUMERIC" | "BOOLEAN" | "CATEGORICAL";
/** DeleteDatasetItemResponse */
interface ApiDeleteDatasetItemResponse {
/** Success message after deletion */
message: string;
}
/** CreateDatasetItemRequest */
interface ApiCreateDatasetItemRequest {
datasetName: string;
input?: any;
expectedOutput?: any;
metadata?: any;
sourceTraceId?: string | null;
sourceObservationId?: string | null;
/** Dataset items are upserted on their id. Id needs to be unique (project-level) and cannot be reused across datasets. */
id?: string | null;
/** Defaults to ACTIVE for newly created items */
status?: ApiDatasetStatus | null;
}
/** PaginatedDatasetItems */
interface ApiPaginatedDatasetItems {
data: ApiDatasetItem[];
meta: ApiUtilsMetaResponse;
}
/** CreateDatasetRunItemRequest */
interface ApiCreateDatasetRunItemRequest {
runName: string;
/** Description of the run. If run exists, description will be updated. */
runDescription?: string | null;
/** Metadata of the dataset run, updates run if run already exists */
metadata?: any;
datasetItemId: string;
observationId?: string | null;
/** traceId should always be provided. For compatibility with older SDK versions it can also be inferred from the provided observationId. */
traceId?: string | null;
}
/** PaginatedDatasets */
interface ApiPaginatedDatasets {
data: ApiDataset[];
meta: ApiUtilsMetaResponse;
}
/** CreateDatasetRequest */
interface ApiCreateDatasetRequest {
name: string;
description?: string | null;
metadata?: any;
}
/** PaginatedDatasetRuns */
interface ApiPaginatedDatasetRuns {
data: ApiDatasetRun[];
meta: ApiUtilsMetaResponse;
}
/** DeleteDatasetRunResponse */
interface ApiDeleteDatasetRunResponse {
message: string;
}
/** HealthResponse */
interface ApiHealthResponse {
/**
* Langfuse server version
* @example "1.25.0"
*/
version: string;
/** @example "OK" */
status: string;
}
/** IngestionEvent */
type ApiIngestionEvent = ({
type: "trace-create";
} & ApiTraceEvent) | ({
type: "score-create";
} & ApiScoreEvent) | ({
type: "span-create";
} & ApiCreateSpanEvent) | ({
type: "span-update";
} & ApiUpdateSpanEvent) | ({
type: "generation-create";
} & ApiCreateGenerationEvent) | ({
type: "generation-update";
} & ApiUpdateGenerationEvent) | ({
type: "event-create";
} & ApiCreateEventEvent) | ({
type: "sdk-log";
} & ApiSDKLogEvent) | ({
type: "observation-create";
} & ApiCreateObservationEvent) | ({
type: "observation-update";
} & ApiUpdateObservationEvent);
/** ObservationType */
type ApiObservationType = "SPAN" | "GENERATION" | "EVENT";
/** IngestionUsage */
type ApiIngestionUsage = ApiUsage | ApiOpenAIUsage;
/**
* OpenAIUsage
* Usage interface of OpenAI for improved compatibility.
*/
interface ApiOpenAIUsage {
promptTokens?: number | null;
completionTokens?: number | null;
totalTokens?: number | null;
}
/** OptionalObservationBody */
interface ApiOptionalObservationBody {
traceId?: string | null;
name?: string | null;
/** @format date-time */
startTime?: string | null;
metadata?: any;
input?: any;
output?: any;
level?: ApiObservationLevel | null;
statusMessage?: string | null;
parentObservationId?: string | null;
version?: string | null;
environment?: string | null;
}
/** CreateEventBody */
type ApiCreateEventBody = ApiOptionalObservationBody & {
id?: string | null;
};
/** UpdateEventBody */
type ApiUpdateEventBody = ApiOptionalObservationBody & {
id: string;
};
/** CreateSpanBody */
type ApiCreateSpanBody = ApiCreateEventBody & {
/** @format date-time */
endTime?: string | null;
};
/** UpdateSpanBody */
type ApiUpdateSpanBody = ApiUpdateEventBody & {
/** @format date-time */
endTime?: string | null;
};
/** CreateGenerationBody */
type ApiCreateGenerationBody = ApiCreateSpanBody & {
/** @format date-time */
completionStartTime?: string | null;
model?: string | null;
modelParameters?: Record<string, ApiMapValue>;
usage?: ApiIngestionUsage | null;
usageDetails?: ApiUsageDetails | null;
costDetails?: Record<string, number>;
promptName?: string | null;
promptVersion?: number | null;
};
/** UpdateGenerationBody */
type ApiUpdateGenerationBody = ApiUpdateSpanBody & {
/** @format date-time */
completionStartTime?: string | null;
model?: string | null;
modelParameters?: Record<string, ApiMapValue>;
usage?: ApiIngestionUsage | null;
promptName?: string | null;
usageDetails?: ApiUsageDetails | null;
costDetails?: Record<string, number>;
promptVersion?: number | null;
};
/** ObservationBody */
interface ApiObservationBody {
id?: string | null;
traceId?: string | null;
type: ApiObservationType;
name?: string | null;
/** @format date-time */
startTime?: string | null;
/** @format date-time */
endTime?: string | null;
/** @format date-time */
completionStartTime?: string | null;
model?: string | null;
modelParameters?: Record<string, ApiMapValue>;
input?: any;
version?: string | null;
metadata?: any;
output?: any;
/** (Deprecated. Use usageDetails and costDetails instead.) Standard interface for usage and cost */
usage?: ApiUsage | null;
level?: ApiObservationLevel | null;
statusMessage?: string | null;
parentObservationId?: string | null;
environment?: string | null;
}
/** TraceBody */
interface ApiTraceBody {
id?: string | null;
/** @format date-time */
timestamp?: string | null;
name?: string | null;
userId?: string | null;
input?: any;
output?: any;
sessionId?: string | null;
release?: string | null;
version?: string | null;
metadata?: any;
tags?: string[] | null;
environment?: string | null;
/** Make trace publicly accessible via url */
public?: boolean | null;
}
/** SDKLogBody */
interface ApiSDKLogBody {
log: any;
}
/** ScoreBody */
interface ApiScoreBody {
id?: string | null;
/** @example "cdef-1234-5678-90ab" */
traceId: string;
/** @example "novelty" */
name: string;
environment?: string | null;
/** The value of the score. Must be passed as string for categorical scores, and numeric for boolean and numeric scores. Boolean score values must equal either 1 or 0 (true or false) */
value: ApiCreateScoreValue;
observationId?: string | null;
comment?: string | null;
/** When set, must match the score value's type. If not set, will be inferred from the score value or config */
dataType?: ApiScoreDataType | null;
/** Reference a score config on a score. When set, the score name must equal the config name and scores must comply with the config's range and data type. For categorical scores, the value must map to a config category. Numeric scores might be constrained by the score config's max and min values */
configId?: string | null;
}
/** BaseEvent */
interface ApiBaseEvent {
/** UUID v4 that identifies the event */
id: string;
/** Datetime (ISO 8601) of event creation in client. Should be as close to actual event creation in client as possible, this timestamp will be used for ordering of events in future release. Resolution: milliseconds (required), microseconds (optimal). */
timestamp: string;
/** Optional. Metadata field used by the Langfuse SDKs for debugging. */
metadata?: any;
}
/** TraceEvent */
type ApiTraceEvent = ApiBaseEvent & {
body: ApiTraceBody;
};
/** CreateObservationEvent */
type ApiCreateObservationEvent = ApiBaseEvent & {
body: ApiObservationBody;
};
/** UpdateObservationEvent */
type ApiUpdateObservationEvent = ApiBaseEvent & {
body: ApiObservationBody;
};
/** ScoreEvent */
type ApiScoreEvent = ApiBaseEvent & {
body: ApiScoreBody;
};
/** SDKLogEvent */
type ApiSDKLogEvent = ApiBaseEvent & {
body: ApiSDKLogBody;
};
/** CreateGenerationEvent */
type ApiCreateGenerationEvent = ApiBaseEvent & {
body: ApiCreateGenerationBody;
};
/** UpdateGenerationEvent */
type ApiUpdateGenerationEvent = ApiBaseEvent & {
body: ApiUpdateGenerationBody;
};
/** CreateSpanEvent */
type ApiCreateSpanEvent = ApiBaseEvent & {
body: ApiCreateSpanBody;
};
/** UpdateSpanEvent */
type ApiUpdateSpanEvent = ApiBaseEvent & {
body: ApiUpdateSpanBody;
};
/** CreateEventEvent */
type ApiCreateEventEvent = ApiBaseEvent & {
body: ApiCreateEventBody;
};
/** IngestionSuccess */
interface ApiIngestionSuccess {
id: string;
status: number;
}
/** IngestionError */
interface ApiIngestionError {
id: string;
status: number;
message?: string | null;
error?: any;
}
/** IngestionResponse */
interface ApiIngestionResponse {
successes: ApiIngestionSuccess[];
errors: ApiIngestionError[];
}
/**
* OpenAICompletionUsageSchema
* OpenAI Usage schema from (Chat-)Completion APIs
*/
interface ApiOpenAICompletionUsageSchema {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
prompt_tokens_details?: Record<string, number | null>;
completion_tokens_details?: Record<string, number | null>;
}
/**
* OpenAIResponseUsageSchema
* OpenAI Usage schema from Response API
*/
interface ApiOpenAIResponseUsageSchema {
input_tokens: number;
output_tokens: number;
total_tokens: number;
input_tokens_details?: Record<string, number | null>;
output_tokens_details?: Record<string, number | null>;
}
/** UsageDetails */
type ApiUsageDetails = Record<string, number> | ApiOpenAICompletionUsageSchema | ApiOpenAIResponseUsageSchema;
/** GetMediaResponse */
interface ApiGetMediaResponse {
/** The unique langfuse identifier of a media record */
mediaId: string;
/** The MIME type of the media record */
contentType: string;
/** The size of the media record in bytes */
contentLength: number;
/**
* The date and time when the media record was uploaded
* @format date-time
*/
uploadedAt: string;
/** The download URL of the media record */
url: string;
/** The expiry date and time of the media record download URL */
urlExpiry: string;
}
/** PatchMediaBody */
interface ApiPatchMediaBody {
/**
* The date and time when the media record was uploaded
* @format date-time
*/
uploadedAt: string;
/** The HTTP status code of the upload */
uploadHttpStatus: number;
/** The HTTP error message of the upload */
uploadHttpError?: string | null;
/** The time in milliseconds it took to upload the media record */
uploadTimeMs?: number | null;
}
/** GetMediaUploadUrlRequest */
interface ApiGetMediaUploadUrlRequest {
/** The trace ID associated with the media record */
traceId: string;
/** The observation ID associated with the media record. If the media record is associated directly with a trace, this will be null. */
observationId?: string | null;
/** The MIME type of the media record */
contentType: ApiMediaContentType;
/** The size of the media record in bytes */
contentLength: number;
/** The SHA-256 hash of the media record */
sha256Hash: string;
/** The trace / observation field the media record is associated with. This can be one of `input`, `output`, `metadata` */
field: string;
}
/** GetMediaUploadUrlResponse */
interface ApiGetMediaUploadUrlResponse {
/** The presigned upload URL. If the asset is already uploaded, this will be null */
uploadUrl?: string | null;
/** The unique langfuse identifier of a media record */
mediaId: string;
}
/**
* MediaContentType
* The MIME type of the media record
*/
type ApiMediaContentType = "image/png" | "image/jpeg" | "image/jpg" | "image/webp" | "image/gif" | "image/svg+xml" | "image/tiff" | "image/bmp" | "audio/mpeg" | "audio/mp3" | "audio/wav" | "audio/ogg" | "audio/oga" | "audio/aac" | "audio/mp4" | "audio/flac" | "video/mp4" | "video/webm" | "text/plain" | "text/html" | "text/css" | "text/csv" | "application/pdf" | "application/msword" | "application/vnd.ms-excel" | "application/zip" | "application/json" | "application/xml" | "application/octet-stream";
/** DailyMetrics */
interface ApiDailyMetrics {
/** A list of daily metrics, only days with ingested data are included. */
data: ApiDailyMetricsDetails[];
meta: ApiUtilsMetaResponse;
}
/** DailyMetricsDetails */
interface ApiDailyMetricsDetails {
/** @format date */
date: string;
countTraces: number;
countObservations: number;
/**
* Total model cost in USD
* @format double
*/
totalCost: number;
usage: ApiUsageByModel[];
}
/**
* UsageByModel
* Daily usage of a given model. Usage corresponds to the unit set for the specific model (e.g. tokens).
*/
interface ApiUsageByModel {
model?: string | null;
/** Total number of generation input units (e.g. tokens) */
inputUsage: number;
/** Total number of generation output units (e.g. tokens) */
outputUsage: number;
/** Total number of generation total units (e.g. tokens) */
totalUsage: number;
countTraces: number;
countObservations: number;
/**
* Total model cost in USD
* @format double
*/
totalCost: number;
}
/** PaginatedModels */
interface ApiPaginatedModels {
data: ApiModel[];
meta: ApiUtilsMetaResponse;
}
/** CreateModelRequest */
interface ApiCreateModelRequest {
/** Name of the model definition. If multiple with the same name exist, they are applied in the following order: (1) custom over built-in, (2) newest according to startTime where model.startTime<observation.startTime */
modelName: string;
/** Regex pattern which matches this model definition to generation.model. Useful in case of fine-tuned models. If you want to exact match, use `(?i)^modelname$` */
matchPattern: string;
/**
* Apply only to generations which are newer than this ISO date.
* @format date-time
*/
startDate?: string | null;
/** Unit used by this model. */
unit?: ApiModelUsageUnit | null;
/**
* Price (USD) per input unit
* @format double
*/
inputPrice?: number | null;
/**
* Price (USD) per output unit
* @format double
*/
outputPrice?: number | null;
/**
* Price (USD) per total units. Cannot be set if input or output price is set.
* @format double
*/
totalPrice?: number | null;
/** Optional. Tokenizer to be applied to observations which match to this model. See docs for more details. */
tokenizerId?: string | null;
/** Optional. Configuration for the selected tokenizer. Needs to be JSON. See docs for more details. */
tokenizerConfig?: any;
}
/** Observations */
interface ApiObservations {
data: ApiObservation[];
meta: ApiUtilsMetaResponse;
}
/** ObservationsViews */
interface ApiObservationsViews {
data: ApiObservationsView[];
meta: ApiUtilsMetaResponse;
}
/** Projects */
interface ApiProjects {
data: ApiProject[];
}
/** Project */
interface ApiProject {
id: string;
name: string;
}
/** PromptMetaListResponse */
interface ApiPromptMetaListResponse {
data: ApiPromptMeta[];
meta: ApiUtilsMetaResponse;
}
/** PromptMeta */
interface ApiPromptMeta {
name: string;
versions: number[];
labels: string[];
tags: string[];
/** @format date-time */
lastUpdatedAt: string;
/** Config object of the most recent prompt version that matches the filters (if any are provided) */
lastConfig: any;
}
/** CreatePromptRequest */
type ApiCreatePromptRequest = ({
type: "chat";
} & ApiCreateChatPromptRequest) | ({
type: "text";
} & ApiCreateTextPromptRequest);
/** CreateChatPromptRequest */
interface ApiCreateChatPromptRequest {
name: string;
prompt: ApiChatMessage[];
config?: any;
/** List of deployment labels of this prompt version. */
labels?: string[] | null;
/** List of tags to apply to all versions of this prompt. */
tags?: string[] | null;
/** Commit message for this prompt version. */
commitMessage?: string | null;
}
/** CreateTextPromptRequest */
interface ApiCreateTextPromptRequest {
name: string;
prompt: string;
config?: any;
/** List of deployment labels of this prompt version. */
labels?: string[] | null;
/** List of tags to apply to all versions of this prompt. */
tags?: string[] | null;
/** Commit message for this prompt version. */
commitMessage?: string | null;
}
/** Prompt */
type ApiPrompt = ({
type: "chat";
} & ApiChatPrompt) | ({
type: "text";
} & ApiTextPrompt);
/** BasePrompt */
interface ApiBasePrompt {
name: string;
version: number;
config: any;
/** List of deployment labels of this prompt version. */
labels: string[];
/** List of tags. Used to filter via UI and API. The same across versions of a prompt. */
tags: string[];
/** Commit message for this prompt version. */
commitMessage?: string | null;
/** The dependency resolution graph for the current prompt. Null if prompt has no dependencies. */
resolutionGraph?: Record<string, any>;
}
/** ChatMessage */
interface ApiChatMessage {
role: string;
content: string;
}
/** TextPrompt */
type ApiTextPrompt = ApiBasePrompt & {
prompt: string;
};
/** ChatPrompt */
type ApiChatPrompt = ApiBasePrompt & {
prompt: ApiChatMessage[];
};
/** ScoreConfigs */
interface ApiScoreConfigs {
data: ApiScoreConfig[];
meta: ApiUtilsMetaResponse;
}
/** CreateScoreConfigRequest */
interface ApiCreateScoreConfigRequest {
name: string;
dataType: ApiScoreDataType;
/** Configure custom categories for categorical scores. Pass a list of objects with `label` and `value` properties. Categories are autogenerated for boolean configs and cannot be passed */
categories?: ApiConfigCategory[] | null;
/**
* Configure a minimum value for numerical scores. If not set, the minimum value defaults to -∞
* @format double
*/
minValue?: number | null;
/**
* Configure a maximum value for numerical scores. If not set, the maximum value defaults to +∞
* @format double
*/
maxValue?: number | null;
/** Description is shown across the Langfuse UI and can be used to e.g. explain the config categories in detail, why a numeric range was set, or provide additional context on config name or usage */
description?: string | null;
}
/** CreateScoreRequest */
interface ApiCreateScoreRequest {
id?: string | null;
/** @example "cdef-1234-5678-90ab" */
traceId: string;
/** @example "novelty" */
name: string;
/** The value of the score. Must be passed as string for categorical scores, and numeric for boolean and numeric scores. Boolean score values must equal either 1 or 0 (true or false) */
value: ApiCreateScoreValue;
observationId?: string | null;
comment?: string | null;
/** The environment of the score. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'. */
environment?: string | null;
/** The data type of the score. When passing a configId this field is inferred. Otherwise, this field must be passed or will default to numeric. */
dataType?: ApiScoreDataType | null;
/** Reference a score config on a score. The unique langfuse identifier of a score config. When passing this field, the dataType and stringValue fields are automatically populated. */
configId?: string | null;
}
/** CreateScoreResponse */
interface ApiCreateScoreResponse {
/** The id of the created object in Langfuse */
id: string;
}
/** GetScoresResponseTraceData */
interface ApiGetScoresResponseTraceData {
/** The user ID associated with the trace referenced by score */
userId?: string | null;
/** A list of tags associated with the trace referenced by score */
tags?: string[] | null;
/** The environment of the trace referenced by score */
environment?: string | null;
}
/** GetScoresResponseDataNumeric */
type ApiGetScoresResponseDataNumeric = ApiNumericScore & {
trace: ApiGetScoresResponseTraceData;
};
/** GetScoresResponseDataCategorical */
type ApiGetScoresResponseDataCategorical = ApiCategoricalScore & {
trace: ApiGetScoresResponseTraceData;
};
/** GetScoresResponseDataBoolean */
type ApiGetScoresResponseDataBoolean = ApiBooleanScore & {
trace: ApiGetScoresResponseTraceData;
};
/** GetScoresResponseData */
type ApiGetScoresResponseData = ({
dataType: "NUMERIC";
} & ApiGetScoresResponseDataNumeric) | ({
dataType: "CATEGORICAL";
} & ApiGetScoresResponseDataCategorical) | ({
dataType: "BOOLEAN";
} & ApiGetScoresResponseDataBoolean);
/** GetScoresResponse */
interface ApiGetScoresResponse {
data: ApiGetScoresResponseData[];
meta: ApiUtilsMetaResponse;
}
/** PaginatedSessions */
interface ApiPaginatedSessions {
data: ApiSession[];
meta: ApiUtilsMetaResponse;
}
/** Traces */
interface ApiTraces {
data: ApiTraceWithDetails[];
meta: ApiUtilsMetaResponse;
}
/** DeleteTraceResponse */
interface ApiDeleteTraceResponse {
message: string;
}
/** Sort */
interface ApiSort {
id: string;
}
/** utilsMetaResponse */
interface ApiUtilsMetaResponse {
/** current page number */
page: number;
/** number of items per page */
limit: number;
/** number of total items given the current filters/selection (if any) */
totalItems: number;
/** number of total pages given the current limit */
totalPages: number;
}
interface ApiAnnotationQueuesListQueuesParams {
/** page number, starts at 1 */
page?: number | null;
/** limit of items per page */
limit?: number | null;
}
interface ApiAnnotationQueuesListQueueItemsParams {
/** Filter by status */
status?: ApiAnnotationQueueStatus | null;
/** page number, starts at 1 */
page?: number | null;
/** limit of items per page */
limit?: number | null;
/** The unique identifier of the annotation queue */
queueId: string;
}
interface ApiCommentsGetParams {
/** Page number, starts at 1. */
page?: number | null;
/** Limit of items per page. If you encounter api issues due to too large page sizes, try to reduce the limit */
limit?: number | null;
/** Filter comments by object type (trace, observation, session, prompt). */
objectType?: string | null;
/** Filter comments by object id. If objectType is not provided, an error will be thrown. */
objectId?: string | null;
/** Filter comments by author user id. */
authorUserId?: string | null;
}
interface ApiDatasetItemsListParams {
datasetName?: string | null;
sourceTraceId?: string | null;
sourceObservationId?: string | null;
/** page number, starts at 1 */
page?: number | null;
/** limit of items per page */
limit?: number | null;
}
interface ApiDatasetsListParams {
/** page number, starts at 1 */
page?: number | null;
/** limit of items per page */
limit?: number | null;
}
interface ApiDatasetsGetRunsParams {
/** page number, starts at 1 */
page?: number | null;
/** limit of items per page */
limit?: number | null;
datasetName: string;
}
interface ApiIngestionBatchPayload {
/** Batch of tracing events to be ingested. Discriminated by attribute `type`. */
batch: ApiIngestionEvent[];
/** Optional. Metadata field used by the Langfuse SDKs for debugging. */
metadata?: any;
}
interface ApiMetricsDailyParams {
/** page number, starts at 1 */
page?: number | null;
/** limit of items per page */
limit?: number | null;
/** Optional filter by the name of the trace */
traceName?: string | null;
/** Optional filter by the userId associated with the trace */
userId?: string | null;
/** Optional filter for metrics where traces include all of these tags */
tags?: (string | null)[];
/** Optional filter for metrics where events include any of these environments */
environment?: (string | null)[];
/**
* Optional filter to only include traces and observations on or after a certain datetime (ISO 8601)
* @format date-time
*/
fromTimestamp?: string | null;
/**
* Optional filter to only include traces and observations before a certain datetime (ISO 8601)
* @format date-time
*/
toTimestamp?: string | null;
}
interface ApiModelsListParams {
/** page number, starts at 1 */
page?: number | null;
/** limit of items per page */
limit?: number | null;
}
interface ApiObservationsGetManyParams {
/** Page number, starts at 1. */
page?: number | null;
/** Limit of items per page. If you encounter api issues due to too large page sizes, try to reduce the limit. */
limit?: number | null;
name?: string | null;
userId?: string | null;
type?: string | null;
traceId?: string | null;
parentObservationId?: string | null;
/** Optional filter for observations where the environment is one of the provided values. */
environment?: (string | null)[];
/**
* Retrieve only observations with a start_time or or after this datetime (ISO 8601).
* @format date-time
*/
fromStartTime?: string | null;
/**
* Retrieve only observations with a start_time before this datetime (ISO 8601).
* @format date-time
*/
toStartTime?: string | null;
/** Optional filter to only include observations with a certain version. */
version?: string | null;
}
interface ApiPromptVersionUpdatePayload {
/** New labels for the prompt version. Labels are unique across versions. The "latest" label is reserved and managed by Langfuse. */
newLabels: string[];
}
interface ApiPromptsGetParams {
/** Version of the prompt to be retrieved. */
version?: number | null;
/** Label of the prompt to be retrieved. Defaults to "production" if no label or version is set. */
label?: string | null;
/** The name of the prompt */
promptName: string;
}
interface ApiPromptsListParams {
name?: string | null;
label?: string | null;
tag?: string | null;
/** page number, starts at 1 */
page?: number | null;
/** limit of items per page */
limit?: number | null;
/**
* Optional filter to only include prompt versions created/updated on or after a certain datetime (ISO 8601)
* @format date-time
*/
fromUpdatedAt?: string | null;
/**
* Optional filter to only include prompt versions created/updated before a certain datetime (ISO 8601)
* @format date-time
*/
toUpdatedAt?: string | null;
}
interface ApiScoreConfigsGetParams {
/** Page number, starts at 1. */
page?: number | null;
/** Limit of items per page. If you encounter api issues due to too large page sizes, try to reduce the limit */
limit?: number | null;
}
interface ApiScoreGetParams {
/** Page number, starts at 1. */
page?: number | null;
/** Limit of items per page. If you encounter api issues due to too large page sizes, try to reduce the limit. */
limit?: number | null;
/** Retrieve only scores with this userId associated to the trace. */
userId?: string | null;
/** Retrieve only scores with this name. */
name?: string | null;
/**
* Optional filter to only include scores created on or after a certain datetime (ISO 8601)
* @format date-time
*/
fromTimestamp?: string | null;
/**
* Optional filter to only include scores created before a certain datetime (ISO 8601)
* @format date-time
*/
toTimestamp?: string | null;
/** Optional filter for scores where the environment is one of the provided values. */
environment?: (string | null)[];
/** Retrieve only scores from a specific source. */
source?: ApiScoreSource | null;
/** Retrieve only scores with <operator> value. */
operator?: string | null;
/**
* Retrieve only scores with <operator> value.
* @format double
*/
value?: number | null;
/** Comma-separated list of score IDs to limit the results to. */
scoreIds?: string | null;
/** Retrieve only scores with a specific configId. */
configId?: string | null;
/** Retrieve only scores with a specific annotation queueId. */
queueId?: string | null;
/** Retrieve only scores with a specific dataType. */
dataType?: ApiScoreDataType | null;
/** Only scores linked to traces that include all of these tags will be returned. */
traceTags?: (string | null)[];
}
interface ApiSessionsListParams {
/** Page number, starts at 1 */
page?: number | null;
/** Limit of items per page. If you encounter api issues due to too large page sizes, try to reduce the limit. */
limit?: number | null;
/**
* Optional filter to only include sessions created on or after a certain datetime (ISO 8601)
* @format date-time
*/
fromTimestamp?: string | null;
/**
* Optional filter to only include sessions created before a certain datetime (ISO 8601)
* @format date-time
*/
toTimestamp?: string | null;
/** Optional filter for sessions where the environment is one of the provided values. */
environment?: (string | null)[];
}
interface ApiTraceListParams {
/** Page number, starts at 1 */
page?: number | null;
/** Limit of items per page. If you encounter api issues due to too large page sizes, try to reduce the limit. */
limit?: number | null;
userId?: string | null;
name?: string | null;
sessionId?: string | null;
/**
* Optional filter to only include traces with a trace.timestamp on or after a certain datetime (ISO 8601)
* @format date-time
*/
fromTimestamp?: string | null;
/**
* Optional filter to only include traces with a trace.timestamp before a certain datetime (ISO 8601)
* @format date-time
*/
toTimestamp?: string | null;
/** Format of the string [field].[asc/desc]. Fields: id, timestamp, name, userId, release, version, public, bookmarked, sessionId. Example: timestamp.asc */
orderBy?: string | null;
/** Only traces that include all of these tags will be returned. */
tags?: (string | null)[];
/** Optional filter to only include traces with a certain version. */
version?: string | null;
/** Optional filter to only include traces with a certain release. */
release?: string | null;
/** Optional filter for traces where the environment is one of the provided values. */
environment?: (string | null)[];
}
interface ApiTraceDeleteMultiplePayload {
/** List of trace IDs to delete */
traceIds: string[];
}
type QueryParamsType = Record<string | number, any>;
type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">;
interface FullRequestParams extends Omit<RequestInit, "body"> {
/** set parameter to `true` for call `securityWorker` for this request */
secure?: boolean;
/** request path */
path: string;
/** content type of request body */
type?: ContentType;
/** query params */
query?: QueryParamsType;
/** format of response (i.e. response.json() -> format: "json") */
format?: ResponseFormat;
/** request body */
body?: unknown;
/** base url */
baseUrl?: string;
/** request cancellation token */
cancelToken?: CancelToken;
}
type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">;
interface ApiConfig<SecurityDataType = unknown> {
baseUrl?: string;
baseApiParams?: Omit<RequestParams, "baseUrl" | "cancelToken" | "signal">;
securityWorker?: (securityData: SecurityDataType | null) => Promise<RequestParams | void> | RequestParams | void;
customFetch?: typeof fetch;
}
interface HttpResponse<D extends unknown, E extends unknown = unknown> extends Response {
data: D;
error: E;
}
type CancelToken = Symbol | string | number;
declare enum ContentType {
Json = "application/json",
FormData = "multipart/form-data",
UrlEncoded = "application/x-www-form-urlencoded",
Text = "text/plain"
}
declare class HttpClient<SecurityDataType = unknown> {
baseUrl: string;
private securityData;
private securityWorker?;
private abortControllers;
private customFetch;
private baseApiParams;
constructor(apiConfig?: ApiConfig<SecurityDataType>);
setSecurityData: (data: SecurityDataType | null) => void;
protected encodeQueryParam(key: string, value: any): string;
protected addQueryParam(query: QueryParamsType, key: string): string;
protected addArrayQueryParam(query: Que