Langfuse JS/TS SDKs
    Preparing search index...

    Manager for prompt operations in Langfuse.

    Provides methods to create, retrieve, and manage prompts with built-in caching for optimal performance. Supports both text and chat prompts with variable substitution and placeholder functionality.

    Index

    Constructors

    Accessors

    Methods

    Constructors

    • Internal

      Creates a new PromptManager instance.

      Parameters

      • params: { apiClient: LangfuseAPIClient }

        Configuration object containing the API client

      Returns PromptManager

    Accessors

    • get logger(): Logger

      Returns Logger

    Methods

    • Creates a new prompt in Langfuse.

      Parameters

      Returns Promise<ChatPromptClient>

      Promise that resolves to a ChatPromptClient

    • Creates a new prompt in Langfuse.

      Parameters

      • body: Omit<Text, "type"> & { type?: "text" }

        The prompt data to create (text prompt)

      Returns Promise<TextPromptClient>

      Promise that resolves to a TextPromptClient

    • Creates a new prompt in Langfuse.

      Parameters

      • body: Chat

        The prompt data to create (chat prompt)

      Returns Promise<ChatPromptClient>

      Promise that resolves to a ChatPromptClient

    • Delete prompt versions. If neither version nor label is specified, all versions of the prompt are deleted.

      The Langfuse SDK prompt cache is invalidated for all cached versions with the specified name.

      Parameters

      • name: string

        Name of the prompt to delete

      • Optionaloptions: { label?: string; version?: number }

        Optional deletion configuration

        • Optionallabel?: string

          Optional label to filter deletion. If specified, deletes all prompt versions with this label

        • Optionalversion?: number

          Optional version to delete. If specified, deletes only this specific version

      Returns Promise<void>

      Promise that resolves when deletion is complete

      If the prompt does not exist

      If the API request fails

      // Delete all versions of a prompt
      await langfuse.prompt.delete("my-prompt");

      // Delete specific version
      await langfuse.prompt.delete("my-prompt", { version: 2 });

      // Delete all versions with a specific label
      await langfuse.prompt.delete("my-prompt", { label: "staging" });
    • Retrieves a text prompt by name.

      Parameters

      • name: string

        Name of the prompt to retrieve

      • Optionaloptions: {
            cacheTtlSeconds?: number;
            fallback?: string;
            fetchTimeoutMs?: number;
            label?: string;
            maxRetries?: number;
            type?: "text";
            version?: number;
        }

        Optional retrieval configuration

        • OptionalcacheTtlSeconds?: number

          Cache TTL in seconds (0 to disable caching)

        • Optionalfallback?: string

          Fallback text content if prompt fetch fails

        • OptionalfetchTimeoutMs?: number

          Request timeout in milliseconds

        • Optionallabel?: string

          Label to filter by

        • OptionalmaxRetries?: number

          Maximum retry attempts for failed requests

        • Optionaltype?: "text"

          Specify text prompt type

        • Optionalversion?: number

          Specific version to retrieve (defaults to latest)

      Returns Promise<TextPromptClient>

      Promise that resolves to a TextPromptClient

    • Retrieves a chat prompt by name.

      Parameters

      • name: string

        Name of the prompt to retrieve

      • Optionaloptions: {
            cacheTtlSeconds?: number;
            fallback?: ChatMessage[];
            fetchTimeoutMs?: number;
            label?: string;
            maxRetries?: number;
            type: "chat";
            version?: number;
        }

        Optional retrieval configuration

        • OptionalcacheTtlSeconds?: number

          Cache TTL in seconds (0 to disable caching)

        • Optionalfallback?: ChatMessage[]

          Fallback chat messages if prompt fetch fails

        • OptionalfetchTimeoutMs?: number

          Request timeout in milliseconds

        • Optionallabel?: string

          Label to filter by

        • OptionalmaxRetries?: number

          Maximum retry attempts for failed requests

        • type: "chat"

          Specify chat prompt type

        • Optionalversion?: number

          Specific version to retrieve (defaults to latest)

      Returns Promise<ChatPromptClient>

      Promise that resolves to a ChatPromptClient

    • Updates the labels of an existing prompt version.

      Parameters

      • params: { name: string; newLabels: string[]; version: number }

        Update parameters

        • name: string

          Name of the prompt to update

        • newLabels: string[]

          New labels to apply to the prompt version

        • version: number

          Version number of the prompt to update

      Returns Promise<Prompt>

      Promise that resolves to the updated prompt

      const updatedPrompt = await langfuse.prompt.update({
      name: "my-prompt",
      version: 1,
      newLabels: ["production", "v2"]
      });