---
title: Headless Initialization (self-hosted)
description: Learn how to automatically initialize Langfuse resources via environment variables.
label: "Version: v4"
sidebarTitle: "Headless Initialization"
---

# Headless Initialization

By default, you need to create a user account, organization and project via the Langfuse UI before being able to use the API. You can find the API keys in the project settings within the UI.

If you want to automatically initialize these resources, you can optionally use the following `LANGFUSE_INIT_*` environment variables. When these variables are set, Langfuse will automatically create the specified resources on startup if they don't already exist. This allows for easy integration with infrastructure-as-code and automated deployment pipelines.

For more programmatic control over the provisioning process, you can also use the [Instance Management API](/self-hosting/administration/instance-management-api).

## Resource Dependencies

The different resources depend on each other.

You can e.g. initialize an organization and a user without having to also initialize a project and API keys, but you cannot initialize a project or user without also initializing an organization.

```
Organization
├── Project      (part of organization)
│   └── API Keys (set for project)
└── User         (owner of organization)
```

## Environment Variables

| Environment Variable               | Description                                                                                    | Required to Create Resource | Example            |
| ---------------------------------- | ---------------------------------------------------------------------------------------------- | --------------------------- | ------------------ |
| `LANGFUSE_INIT_ORG_ID`             | Unique identifier for the organization                                                         | Yes                         | `my-org`           |
| `LANGFUSE_INIT_ORG_NAME`           | Name of the organization                                                                       | No                          | `My Org`           |
| `LANGFUSE_INIT_PROJECT_ID`         | Unique identifier for the project                                                              | Yes                         | `my-project`       |
| `LANGFUSE_INIT_PROJECT_NAME`       | Name of the project                                                                            | No                          | `My Project`       |
| `LANGFUSE_INIT_PROJECT_RETENTION`  | [Data Retention](/docs/data-retention) in days for project. Leave blank to retain data forever | No                          | `30`               |
| `LANGFUSE_INIT_PROJECT_PUBLIC_KEY` | Public API key for the project                                                                 | Yes                         | `lf_pk_1234567890` |
| `LANGFUSE_INIT_PROJECT_SECRET_KEY` | Secret API key for the project                                                                 | Yes                         | `lf_sk_1234567890` |
| `LANGFUSE_INIT_USER_EMAIL`         | Email address of the initial user                                                              | Yes                         | `user@example.com` |
| `LANGFUSE_INIT_USER_NAME`          | Name of the initial user                                                                       | No                          | `John Doe`         |
| `LANGFUSE_INIT_USER_PASSWORD`      | Password for the initial user                                                                  | Yes                         | `password123`      |

## Troubleshooting

- If you use `LANGFUSE_INIT_*` in Docker Compose, do not double-quote the values ([GitHub issue](https://github.com/langfuse/langfuse/issues/3398)).
- The resources depend on one another (see note above). For example, you must create an organization to initialize a project.

---

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/administration/headless-initialization.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>.
