Implements

Constructors

Methods

  • Add runs to an annotation queue with the specified queue ID.

    Parameters

    • queueId: string

      The ID of the annotation queue

    • runIds: string[]

      The IDs of the runs to be added to the annotation queue

    Returns Promise<void>

  • Awaits all pending trace batches. Useful for environments where you need to be sure that all tracing requests finish before execution ends, such as serverless environments.

    Returns Promise<void> | Promise<[...void[], void]>

    A promise that resolves once all currently pending traces have sent.

    import { Client } from "langsmith";

    const client = new Client();

    try {
    // Tracing happens here
    ...
    } finally {
    await client.awaitPendingTraceBatches();
    }
  • Batch ingest/upsert multiple runs in the Langsmith system.

    Parameters

    Returns Promise<void>

  • Clone a public dataset to your own langsmith tenant. This operation is idempotent. If you already have a dataset with the given name, this function will do nothing.

    Parameters

    • tokenOrUrl: string

      The token of the public dataset to clone.

    • Optionaloptions: { datasetName?: string; sourceApiUrl?: string } = {}

      Additional options for cloning the dataset.

      • OptionaldatasetName?: string

        The name of the dataset to create in your tenant. Defaults to the name of the public dataset.

      • OptionalsourceApiUrl?: string

        The URL of the langsmith server where the data is hosted. Defaults to the API URL of your current client.

    Returns Promise<void>

  • Create an annotation queue on the LangSmith API.

    Parameters

    • options: { name: string; description?: string; queueId?: string }

      The options for creating an annotation queue

      • name: string

        The name of the annotation queue

      • Optionaldescription?: string

        The description of the annotation queue

      • OptionalqueueId?: string

        The ID of the annotation queue

    Returns Promise<AnnotationQueue>

    The created AnnotationQueue object

  • Parameters

    • promptIdentifier: string
    • object: any
    • Optionaloptions: { parentCommitHash?: string }

    Returns Promise<string>

  • Parameters

    • __namedParameters: {
          experimentIds: string[];
          name: string;
          createdAt?: Date;
          description?: string;
          id?: string;
          metadata?: Record<string, unknown>;
          referenceDatasetId?: string;
      }

    Returns Promise<ComparativeExperiment>

  • Parameters

    • name: string
    • __namedParameters: {
          dataType?: DataType;
          description?: string;
          inputsSchema?: KVMap;
          metadata?: RecordStringAny;
          outputsSchema?: KVMap;
      } = {}

    Returns Promise<Dataset>

  • Parameters

    • props: {
          inputs: KVMap[];
          datasetId?: string;
          datasetName?: string;
          exampleIds?: string[];
          metadata?: KVMap[];
          outputs?: KVMap[];
          sourceRunIds?: string[];
          splits?: (string | string[])[];
      }

    Returns Promise<Example[]>

  • Parameters

    • runId: null | string
    • key: string
    • __namedParameters: {
          comment?: string;
          comparativeExperimentId?: string;
          correction?: object;
          eager?: boolean;
          feedbackConfig?: FeedbackConfig;
          feedbackId?: string;
          feedbackSourceType?: FeedbackSourceType;
          projectId?: string;
          score?: ScoreType;
          sourceInfo?: object;
          sourceRunId?: string;
          value?: ValueType;
      }

    Returns Promise<Feedback>

  • Creates a presigned feedback token and URL.

    The token can be used to authorize feedback metrics without needing an API key. This is useful for giving browser-based applications the ability to submit feedback without needing to expose an API key.

    Parameters

    • runId: string

      The ID of the run.

    • feedbackKey: string

      The feedback key.

    • options: { expiration?: string | TimeDelta; feedbackConfig?: FeedbackConfig } = {}

      Additional options for the token.

    Returns Promise<FeedbackIngestToken>

    A promise that resolves to a FeedbackIngestToken.

  • Parameters

    • promptIdentifier: string
    • Optionaloptions: { description?: string; isPublic?: boolean; readme?: string; tags?: string[] }

    Returns Promise<Prompt>

  • Delete an annotation queue with the specified queue ID.

    Parameters

    • queueId: string

      The ID of the annotation queue to delete

    Returns Promise<void>

  • Parameters

    • __namedParameters: { datasetId?: string; datasetName?: string }

    Returns Promise<void>

  • Parameters

    • exampleId: string

    Returns Promise<void>

  • Parameters

    • feedbackId: string

    Returns Promise<void>

  • Parameters

    • __namedParameters: { projectId?: string; projectName?: string }

    Returns Promise<void>

  • Parameters

    • promptIdentifier: string

    Returns Promise<void>

  • Delete a run from an an annotation queue.

    Parameters

    • queueId: string

      The ID of the annotation queue to delete the run from

    • queueRunId: string

      The ID of the run to delete from the annotation queue

    Returns Promise<void>

  • Parameters

    • __namedParameters: {
          fromVersion: string | Date;
          toVersion: string | Date;
          datasetId?: string;
          datasetName?: string;
      }

    Returns Promise<DatasetDiffInfo>

  • Parameters

    • run: string | Run
    • evaluator: RunEvaluator
    • __namedParameters: { loadChildRuns: boolean; referenceExample?: Example; sourceInfo?: KVMap } = ...

    Returns Promise<Feedback>

    This method is deprecated and will be removed in future LangSmith versions, use evaluate from langsmith/evaluation instead.

  • Flushes current queued traces.

    Returns Promise<void>

  • Parameters

    • __namedParameters: { datasetId?: string; datasetName?: string }

    Returns Promise<string>

  • Parameters

    • __namedParameters: { projectId?: string; projectName?: string }

    Returns Promise<string>

  • Parameters

    • promptIdentifier: string

    Returns Promise<null | Prompt>

  • Get a run from an annotation queue at the specified index.

    Parameters

    • queueId: string

      The ID of the annotation queue

    • index: number

      The index of the run to retrieve

    Returns Promise<RunWithAnnotationQueueInfo>

    A Promise that resolves to a RunWithAnnotationQueueInfo object

    If the run is not found at the given index or for other API-related errors

  • Parameters

    • __namedParameters: {
          dataSourceType?: string;
          endTime?: string;
          error?: boolean;
          filter?: string;
          id?: string[];
          isRoot?: boolean;
          parentRun?: string;
          projectIds?: string[];
          projectNames?: string[];
          query?: string;
          referenceExampleIds?: string[];
          runType?: string;
          startTime?: string;
          trace?: string;
          traceFilter?: string;
          treeFilter?: string;
      }

    Returns Promise<any>

  • Parameters

    • __namedParameters: { projectOpts?: ProjectOptions; run?: Run; runId?: string }

    Returns Promise<string>

  • Get the size of an annotation queue.

    Parameters

    • queueId: string

      The ID of the annotation queue

    Returns Promise<{ size: number }>

  • Parameters

    • __namedParameters: { datasetId?: string; datasetName?: string }

    Returns Promise<boolean>

  • Parameters

    • __namedParameters: { projectId?: string; projectName?: string }

    Returns Promise<boolean>

  • Parameters

    • __namedParameters: { datasetId?: string; datasetName?: string; tag?: string }

    Returns Promise<void>

  • List the annotation queues on the LangSmith API.

    Parameters

    • options: { limit?: number; name?: string; nameContains?: string; queueIds?: string[] } = {}

      The options for listing annotation queues

      • Optionallimit?: number

        The maximum number of queues to return

      • Optionalname?: string

        The name of the queue to filter by

      • OptionalnameContains?: string

        The substring that the queue name should contain

      • OptionalqueueIds?: string[]

        The IDs of the queues to filter by

    Returns AsyncIterableIterator<AnnotationQueue>

    An iterator of AnnotationQueue objects

  • Parameters

    • __namedParameters: {
          datasetIds?: string[];
          datasetName?: string;
          datasetNameContains?: string;
          limit?: number;
          metadata?: RecordStringAny;
          offset?: number;
      } = {}

    Returns AsyncIterable<Dataset>

  • Parameters

    • __namedParameters: { asOf?: string | Date; datasetId?: string; datasetName?: string }

    Returns Promise<string[]>

  • Parameters

    • __namedParameters: {
          asOf?: string | Date;
          datasetId?: string;
          datasetName?: string;
          exampleIds?: string[];
          filter?: string;
          includeAttachments?: boolean;
          inlineS3Urls?: boolean;
          limit?: number;
          metadata?: KVMap;
          offset?: number;
          splits?: string[];
      } = {}

    Returns AsyncIterable<Example>

  • Parameters

    • __namedParameters: {
          feedbackKeys?: string[];
          feedbackSourceTypes?: FeedbackSourceType[];
          runIds?: string[];
      } = {}

    Returns AsyncIterable<Feedback>

  • Retrieves a list of presigned feedback tokens for a given run ID.

    Parameters

    • runId: string

      The ID of the run.

    Returns AsyncIterable<FeedbackIngestToken>

    An async iterable of FeedbackIngestToken objects.

  • Parameters

    • __namedParameters: {
          metadata?: RecordStringAny;
          name?: string;
          nameContains?: string;
          projectIds?: string[];
          referenceDatasetId?: string;
          referenceDatasetName?: string;
          referenceFree?: boolean;
      } = {}

    Returns AsyncIterable<TracerSession>

  • Parameters

    • Optionaloptions: {
          isArchived?: boolean;
          isPublic?: boolean;
          query?: string;
          sortField?: PromptSortField;
      }

    Returns AsyncIterableIterator<Prompt>

  • List runs from the LangSmith server.

    Parameters

    • props: ListRunsParams

    Returns AsyncIterable<Run>

    • The runs.
    // List all runs in a project
    const projectRuns = client.listRuns({ projectName: "<your_project>" });
    // List LLM and Chat runs in the last 24 hours
    const todaysLLMRuns = client.listRuns({
    projectName: "<your_project>",
    start_time: new Date(Date.now() - 24 * 60 * 60 * 1000),
    run_type: "llm",
    });
    // List traces in a project
    const rootRuns = client.listRuns({
    projectName: "<your_project>",
    execution_order: 1,
    });
    // List runs without errors
    const correctRuns = client.listRuns({
    projectName: "<your_project>",
    error: false,
    });
    // List runs by run ID
    const runIds = [
    "a36092d2-4ad5-4fb4-9c0d-0dba9a2ed836",
    "9398e6be-964f-4aa4-8ae9-ad78cd4b7074",
    ];
    const selectedRuns = client.listRuns({ run_ids: runIds });
    // List all "chain" type runs that took more than 10 seconds and had `total_tokens` greater than 5000
    const chainRuns = client.listRuns({
    projectName: "<your_project>",
    filter: 'and(eq(run_type, "chain"), gt(latency, 10), gt(total_tokens, 5000))',
    });
    // List all runs called "extractor" whose root of the trace was assigned feedback "user_score" score of 1
    const goodExtractorRuns = client.listRuns({
    projectName: "<your_project>",
    filter: 'eq(name, "extractor")',
    traceFilter: 'and(eq(feedback_key, "user_score"), eq(feedback_score, 1))',
    });
    // List all runs that started after a specific timestamp and either have "error" not equal to null or a "Correctness" feedback score equal to 0
    const complexRuns = client.listRuns({
    projectName: "<your_project>",
    filter: 'and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(error, null), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))',
    });
    // List all runs where `tags` include "experimental" or "beta" and `latency` is greater than 2 seconds
    const taggedRuns = client.listRuns({
    projectName: "<your_project>",
    filter: 'and(or(has(tags, "experimental"), has(tags, "beta")), gt(latency, 2))',
    });
  • Get shared examples.

    Parameters

    • shareToken: string

      The share token to get examples for. A share token is the UUID (or LangSmith URL, including UUID) generated when explicitly marking an example as public.

    • Optionaloptions: { exampleIds?: string[] }

      Additional options for listing the examples.

      • OptionalexampleIds?: string[]

        A list of example IDs to filter by.

    Returns Promise<Example[]>

    The shared examples.

  • Parameters

    • shareToken: string
    • __namedParameters: { runIds?: string[] } = {}

    Returns Promise<Run[]>

  • Batch ingest/upsert multiple runs in the Langsmith system.

    Parameters

    Returns Promise<void>

  • Parameters

    • promptIdentifier: string

    Returns Promise<boolean>

  • Parameters

    • promptIdentifier: string
    • Optionaloptions: { includeModel?: boolean }

    Returns Promise<PromptCommit>

  • Parameters

    • promptIdentifier: string
    • Optionaloptions: {
          description?: string;
          isPublic?: boolean;
          object?: any;
          parentCommitHash?: string;
          readme?: string;
          tags?: string[];
      }

    Returns Promise<string>

  • Read an annotation queue with the specified queue ID.

    Parameters

    • queueId: string

      The ID of the annotation queue to read

    Returns Promise<AnnotationQueue>

    The AnnotationQueue object

  • Parameters

    • __namedParameters: { datasetId?: string; datasetName?: string }

    Returns Promise<Dataset>

  • Parameters

    • __namedParameters: { datasetId?: string; datasetName?: string }

    Returns Promise<any[]>

  • Get dataset version by closest date or exact tag.

    Use this to resolve the nearest version to a given timestamp or for a given tag.

    Parameters

    • options: { asOf?: string | Date; datasetId?: string; datasetName?: string; tag?: string }

      The options for getting the dataset version

      • OptionalasOf?: string | Date

        The timestamp of the dataset to retrieve

      • OptionaldatasetId?: string

        The ID of the dataset

      • OptionaldatasetName?: string

        The name of the dataset

      • Optionaltag?: string

        The tag of the dataset to retrieve

    Returns Promise<DatasetVersion>

    The dataset version

  • Parameters

    • __namedParameters: { includeStats?: boolean; projectId?: string; projectName?: string }

    Returns Promise<TracerSessionResult>

  • Parameters

    • runId: string
    • __namedParameters: { loadChildRuns: boolean } = ...

    Returns Promise<Run>

  • Parameters

    • runId: string

    Returns Promise<undefined | string>

  • Parameters

    • runId: string
    • __namedParameters: { shareId?: string } = {}

    Returns Promise<string>

  • Lets you run a similarity search query on a dataset.

    Requires the dataset to be indexed. Please see the indexDataset method to set up indexing.

    Parameters

    • inputs: KVMap

      The input on which to run the similarity search. Must have the same schema as the dataset.

    • datasetId: string

      The dataset to search for similar examples.

    • limit: number

      The maximum number of examples to return. Will return the top limit most similar examples in order of most similar to least similar. If no similar examples are found, random examples will be returned.

    • filter: { filter?: string } = {}

      A filter string to apply to the search. Only examples will be returned that match the filter string. Some examples of filters

                     - eq(metadata.mykey, "value")
                     - and(neq(metadata.my.nested.key, "value"), neq(metadata.mykey, "value"))
                     - or(eq(metadata.mykey, "value"), eq(metadata.mykey, "othervalue"))
      

    Returns Promise<ExampleSearch[]>

    A list of similar examples.

    dataset_id = "123e4567-e89b-12d3-a456-426614174000"
    inputs = {"text": "How many people live in Berlin?"}
    limit = 5
    examples = await client.similarExamples(inputs, dataset_id, limit)
  • Parameters

    • datasetId: string

    Returns Promise<void>

  • Parameters

    • runId: string

    Returns Promise<void>

  • Update an annotation queue with the specified queue ID.

    Parameters

    • queueId: string

      The ID of the annotation queue to update

    • options: { name: string; description?: string }

      The options for updating the annotation queue

      • name: string

        The new name for the annotation queue

      • Optionaldescription?: string

        The new description for the annotation queue

    Returns Promise<void>

  • Update a dataset

    Parameters

    • props: {
          datasetId?: string;
          datasetName?: string;
          description?: string;
          name?: string;
      }

      The dataset details to update

    Returns Promise<Dataset>

    The updated dataset

  • Parameters

    • __namedParameters: {
          exampleIds: string[];
          splitName: string;
          datasetId?: string;
          datasetName?: string;
          remove?: boolean;
      }

    Returns Promise<void>

  • Updates a tag on a dataset.

    If the tag is already assigned to a different version of this dataset, the tag will be moved to the new version. The as_of parameter is used to determine which version of the dataset to apply the new tags to.

    It must be an exact version of the dataset to succeed. You can use the "readDatasetVersion" method to find the exact version to apply the tags to.

    Parameters

    • props: { asOf: string | Date; tag: string; datasetId?: string; datasetName?: string }

    Returns Promise<void>

  • Parameters

    • feedbackId: string
    • __namedParameters: {
          comment?: null | string;
          correction?: null | object;
          score?: null | number | boolean;
          value?: null | string | number | boolean | object;
      }

    Returns Promise<void>

  • Parameters

    • projectId: string
    • __namedParameters: {
          description?: null | string;
          endTime?: null | string;
          metadata?: null | RecordStringAny;
          name?: null | string;
          projectExtra?: null | RecordStringAny;
      }

    Returns Promise<TracerSession>

  • Parameters

    • promptIdentifier: string
    • Optionaloptions: {
          description?: string;
          isArchived?: boolean;
          isPublic?: boolean;
          readme?: string;
          tags?: string[];
      }

    Returns Promise<Record<string, any>>

  • Parameters

    • __namedParameters: UploadCSVParams

    Returns Promise<Dataset>

  • Returns {
        apiUrl: string;
        apiKey?: string;
        hideInputs?: boolean;
        hideOutputs?: boolean;
        webUrl?: string;
    }