What Is Langfuse?
Langfuse is a tool mainly used to analyze your prompts’ token counts, including both input and output tokens. It also includes other features such as response time tracking. You can use it online, but the hosted version has some limitations. Here is the homepage .
Install Langfuse Locally
- Install Git, Docker, and Docker Compose.
- Clone the Langfuse repository.
git clone https://github.com/langfuse/langfuse.git
cd langfuse
- Start the application with
docker compose up. - Open
http://localhost:3000to access the Langfuse UI.
Use Langfuse in a Python Environment
- Install the library with
pip install langfuse. - Create a project in the Langfuse UI and note the Secret Key, Public Key, and Base URL for later use.
- Create a
.envfile and add the following variables, replacing the placeholders with the values from the previous step.
LANGFUSE_SECRET_KEY = "sk-lf-..."
LANGFUSE_PUBLIC_KEY = "pk-lf-..."
LANGFUSE_BASE_URL = "http://localhost:3000"
-
Import the library into your code.
from langfuse.openai import openai -
Start building with Langfuse.