---
title: Migrate Langfuse v1 to v2 (self-hosted)
description: A guide to upgrade a Langfuse v1 setup to v2.
---

# Migrate Langfuse v1 to v2

Langfuse v2 ([released](https://github.com/langfuse/langfuse/releases/tag/v2.0.0) Jan 30, 2024) is a major release of Langfuse that introduces a rebuilt usage and cost tracking system for LLM generations. The update requires running a one-off migration script on historical data to ensure accurate LLM costs of existing traces.

## Changes

### What has changed?

- Completely rebuilt usage/cost tracking system for LLM generations
- New model definition abstraction that enables:
  - Quick support for new emerging models
  - Tracking of model price changes over time
  - Custom models/prices at the project level
- Added ability to set usage and cost via API when ingesting traces
- Usage and cost information available on all UI tables and APIs

### What has not changed?

Everything else, including APIs and infrastructure components, remains the same. No breaking changes.

## Who needs to take action during the upgrade?

- **No action required** if you:
  - Use Langfuse Cloud
  - Only care about newly ingested traces
  - Don't use the cost tracking features

- **Action required** if you:
  - Self-host Langfuse
  - Want accurate cost data for historical traces

## Migration Steps

  This process is non-blocking and does not impact the availability of your
  Langfuse deployment.

<Steps>

### Update Langfuse to v2

Follow the deployment guide to upgrade your Langfuse deployment to v2.

- For production deployments, see the [upgrade guide](/self-hosting/v2/deployment-guide#update)
- If you use docker compose, see the [upgrade guide](/self-hosting/v2/docker-compose)

### Apply new model logic and prices to existing data

Langfuse includes a list of supported models for [usage and cost tracking](/docs/model-usage-and-cost). If a Langfuse update includes support for new models, these will only be applied to newly ingested traces/generations.

Optionally, you can apply the new model definitions to existing data using the following steps. During the migration, the database remains available (non-blocking).

1. Clone the repository and create an `.env` file:

   ```bash
   # Clone the Langfuse repository
   git clone https://github.com/langfuse/langfuse.git

   # Navigate to the Langfuse directory
   cd langfuse

   # Checkout the Langfuse v2 branch
   git checkout v2

   # Install all dependencies
   pnpm i

   # Create an .env file
   cp .env.dev.example .env
   ```

2. Edit the `.env` to connect to your database from your machine:

   ```bash filename=".env"
   NODE_ENV=production

   # Replace with your database connection string
   DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres
   ```

3. Execute the migration. Depending on the size of your database, this might take a while.

   ```bash
   pnpm run models:migrate
   ```

4. Clean up: remove the `.env` file to avoid connecting to the production database from your local machine.

</Steps>

---

If you experience any issues when self-hosting Langfuse, please:

1. Check out [Troubleshooting & FAQ](/self-hosting/troubleshooting-and-faq) page.
2. Use [Ask AI](/ask-ai) to get instant answers to your questions.
3. Ask the maintainers on [GitHub Discussions](/gh-support).
4. Create a bug report or feature request on [GitHub](/issues).

  Enterprise-grade support is available when self-hosting Langfuse. Learn more on
  our [pricing page](/pricing-self-host).

<!-- agent-instructions -->

---

## Agent Instructions

This page is part of the [Langfuse](https://langfuse.com) documentation, published as plain Markdown for AI agents. Every page is available as Markdown by appending `.md` to its URL, or by sending an `Accept: text/markdown` header. This page: `https://langfuse.com/self-hosting/upgrade/upgrade-guides/upgrade-v1-to-v2.md`.

### Querying these docs

If the answer is not on this page, query the documentation instead of guessing:

- **Semantic search** across all Langfuse docs, returning an answer with the relevant pages and excerpts. Ask a specific, self-contained question:

  ```bash
  curl -sG "https://langfuse.com/api/search-docs" --data-urlencode "query=How do I trace a LangGraph agent?"
  ```

- **Index of every page**: <https://langfuse.com/llms.txt>, with per-section indexes [llms-docs.txt](https://langfuse.com/llms-docs.txt), [llms-integrations.txt](https://langfuse.com/llms-integrations.txt), and [llms-self-hosting.txt](https://langfuse.com/llms-self-hosting.txt).

### Before writing Langfuse code

- **Install the [Langfuse Agent Skill](https://langfuse.com/docs/api-and-data-platform/features/agent-skill).** It encodes Langfuse's own best practices for instrumentation, prompt management, and evaluation, and materially improves results.
- **Read [What does a good trace look like?](https://langfuse.com/docs/observability/best-practices.md)** before instrumenting an application.
- **Verify endpoints, parameters, and response fields** against the [API reference](https://api.reference.langfuse.com) instead of inferring them from code examples.
- **Use the [Langfuse CLI](https://langfuse.com/docs/api-and-data-platform/features/cli)** (`npx langfuse-cli api <resource> <action>`) to read or write traces, prompts, datasets, and scores from the terminal.

Found an error in these docs? Please open an issue at <https://github.com/langfuse/langfuse-docs/issues>.
