Self-host Langfuse for LLM monitoring in your company

Langfuse records prompts, answers and costs of AI applications, and the README describes how to run it on your own infrastructure. This tutorial takes you from an empty machine to a first logged model call.

Niklas Schult4 min read

Illustration: A small wooden house with a lantern inside, fed by a glass tube from a brass flask standing beside it.

What you will have at the end and what you need

At the end you will have a Langfuse instance running on a machine you control and a Python script whose model call appears there as a trace. Langfuse is an open source platform for observability and evaluation of AI applications. It tracks usage and costs and lets you inspect individual calls, which helps when a department asks why an internal assistant gave a certain answer.

You need a machine or virtual machine with Docker and Docker Compose, Git, and Python with pip for the test script. The Langfuse README says Docker Compose suits a single machine or one virtual machine, and it names Kubernetes with Helm as the preferred production deployment. The sections below follow the Docker Compose route, which fits a first trial. A small test machine is enough to follow along, and you can move to a production setup once the first traces look right.

Start Langfuse with Docker Compose

The following block clones the repository, changes into it and starts the stack. The README states that this takes about five minutes. It uses a shallow clone, so only the latest state is downloaded.

Shell
# Get a copy of the latest Langfuse repository
git clone --depth=1 https://github.com/langfuse/langfuse.git
cd langfuse

# Run the langfuse docker compose
docker compose up

The Docker Compose guide from the project also explains how to set up Docker log rotation, so that container logs do not fill the disk. The README does not list the port or the first-login steps, so take those from the self-hosting documentation. For architecture and configuration options the README refers to the same documentation.

Create a project and generate credentials

Once the interface is reachable, create an account, then a new project, and then new API credentials in the project settings. The README gives these steps for the manual installation. You receive a secret key and a public key, which identify your application to Langfuse.

The next block shows the environment file for your application. The base URL must point to your own instance, because the README's default values name the hosted cloud regions. Replace the key values and the address with your own, and keep the file out of version control.

Shell
LANGFUSE_SECRET_KEY="sk-lf-..."
LANGFUSE_PUBLIC_KEY="pk-lf-..."
# Point this to your own instance instead of the cloud regions
LANGFUSE_BASE_URL="<address-of-your-instance>"

Log the first model call

One command installs the Python SDK and the OpenAI client. The README uses the OpenAI integration so that model parameters are captured automatically. For other models and frameworks it points to the get started guide.

Shell
pip install langfuse openai

The script below wraps two functions with the observe decorator and imports OpenAI through the Langfuse integration. Calling main creates a trace with the nested story call and the model request. The README example uses the model gpt-4o, which is an external service. For a setup where no data leaves your network, the README lists Ollama as a local model integration and OpenWebUI as a self-hosted chat interface, but it shows no code for them.

Python
from langfuse import observe
from langfuse.openai import openai  # OpenAI integration

@observe()
def story():
    return openai.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": "What is Langfuse?"}],
    ).choices[0].message.content

@observe()
def main():
    return story()

main()

Check that it works and avoid common pitfalls

Open your project in the Langfuse interface and look at the traces. After running the script, one trace for main should appear, with the story call and the model request beneath it. The README describes this as seeing your language model calls and other application logic in Langfuse.

The README points to a few things that cause trouble. The base URL in the examples defaults to a cloud region, so a forgotten change sends traces to the hosted service instead of your instance. Container logs can fill the disk unless log rotation is configured as the Docker Compose guide describes. The repository is MIT licensed except for the ee folders, which matters if you plan to use features from those folders. Production hardening is left to the self-hosting documentation.

Where this fits in a company

A self-hosted Langfuse is one more system to operate, with updates, backups and access control. The project offers a mailing list for self-hosting updates, which helps whoever maintains it to notice new releases. Decide early who owns the instance and who may read traces, because they contain prompts and answers that can include personal data. Many companies involve the data protection officer and, where one exists, the Betriebsrat (works council) before logging employee interactions.

souveraen.ai is an AI platform for company knowledge from clouditiv GmbH in Auerbach, Germany, available hosted in Germany or on-premise, with an OpenAI-compatible developer API. Applications built on it can be observed with the approach above. Background on running models in your own network is on the pages about local AI and on-premise operation, and on security and data protection.

Sources

More articles

All articles

OpenAI Private Inference: Is It Fit for Confidential Data?

OpenAI is testing an offer called Private Inference with first business customers, under which the provider is not meant to see the data it processes. Law firms, public bodies and companies with sensitive files need to know whether this makes ChatGPT services usable for confidential content.

Data protection4 min

AI applicant profiles: what employers may use from the web

AI tools can turn social media posts and press articles into an applicant profile within seconds. Employers in Germany need to know which public data the GDPR and the BDSG allow them to use in hiring.

Data protection4 min

Do lawyers need client consent to use AI?

A Legal Tribune Online article by Nico Kuhlmann concludes that using AI in a law firm is treated like engaging any other service provider. Consent is usually unnecessary, though borderline cases exist and the duty of confidentiality applies in full.

Data protection5 min

Test it with your own documents.

Free for 3 days, then from €24.90 per user per month. Cancellable monthly.

Free for 3 days, then from €24.90 per user per month.Free for 3 days
Try free for 3 days