DocsIntegrationsLangflow

⛓️ Langflow Integration

Langflow (GitHub) is a UI for LangChain, designed with react-flow to provide an effortless way to experiment and prototype flows.

With the native integration (since langflow v1.0.17), you can use Langflow to quickly create complex LLM applications in no-code and then use Langfuse to monitor and improve them.

Integration

Video guide on how to integrate Langflow with Langfuse (published by Langflow)

Get Langfuse API keys

  1. Create account and project on cloud.langfuse.com
  2. Copy API keys for your project

Setup Langflow

# API keys from project settings in Langfuse
export LANGFUSE_SECRET_KEY=sk-lf...
export LANGFUSE_PUBLIC_KEY=pk-lf...
 
export LANGFUSE_HOST="https://cloud.langfuse.com"  # 🇪🇺 for EU data region
# export LANGFUSE_HOST="https://cloud.langfuse.com" # 🇺🇸 for US data region
# export LANGFUSE_HOST="http://localhost:3000" # 🏠 for self-hosters
 
# Install Langflow
pip install langflow
 
# Start Langflow in the same terminal or environment where you set the environment variables:
python -m langflow run

Alternatively, you can run the Langflow CLI command with the environment variables set:

LANGFUSE_SECRET_KEY=secret_key LANGFUSE_PUBLIC_KEY=public_key LANGFUSE_HOST="http://localhost:3000" langflow

See your traces in Langfuse

Now, when you use Langflow’s chat or API, you can view the trace of your conversations in Langfuse.

Langflow traces in Langfuse

Example Langflow trace in the Langfuse UI

Running Langfuse and Langflow with Docker Compose

If you prefer to self-host Langfuse, you can run both services using Docker Compose. By combining the two docker-compose files, you can streamline the networking between them.

version: "3.5"
 
services:
  # Adapted from https://github.com/logspace-ai/langflow/blob/dev/docker_example/docker-compose.yml
  langflow:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "7860:7860"
    environment:
+     # Tokens are to be created in Langfuse, then copy-pasted here. Then restart docker-compose.
+     - LANGFUSE_SECRET_KEY=sk-lf-...
+     - LANGFUSE_PUBLIC_KEY=pk-lf-...
+     - LANGFUSE_HOST="http://langfuse-server:3000"
    command: langflow run --host 0.0.0.0
 
  # https://github.com/langfuse/langfuse/blob/main/docker-compose.yml
  langfuse-server:
    image: ghcr.io/langfuse/langfuse:latest
    depends_on:
      - db
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=production
      - DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres
      - NEXTAUTH_SECRET=mysecret
      - SALT=mysalt
      - NEXTAUTH_URL=http:localhost:3000
 
  db:
    image: postgres
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=postgres
    ports:
      - 5432:5432
    volumes:
      - database_data:/var/lib/postgresql/data
 
volumes:
  database_data:
    driver: local

To test the connectivity between Langflow and Langfuse, run the following command:

docker compose exec langflow python -c "import requests, os; addr = os.environ.get('LANGFUSE_HOST'); print(addr); res = requests.get(addr, timeout=5); print(res.status_code)"
 
# which should output the following:
# http://langfuse-server:3000
# 200

Was this page useful?

Questions? We're here to help

Subscribe to updates