API keys and authentication
Never expose Langflow ports directly to the internet without proper security measures.
Set LANGFLOW_AUTO_LOGIN=False, use a non-default LANGFLOW_SECRET_KEY, and deploy your Langflow server behind a reverse proxy with authentication enabled.
For more information, see Start a Langflow server with authentication enabled.
Authentication credentials help prevent unauthorized access to your Langflow server, flows, and services connected through components.
There are three types of credentials that you use in Langflow:
- Langflow API keys: For authentication with the Langflow API and authorizing server-side Langflow actions like running flows and uploading files.
- Component API keys: For authentication between Langflow and a service connected through a component, such as a model provider or third-party API.
- Authentication environment variables: These environment variables configure how Langflow handles user authentication and authorization.
Langflow API keys
You can use Langflow API keys to interact with Langflow programmatically.
By default, most Langflow API endpoints, such as /v1/run/$FLOW_ID, require authentication with a Langflow API key.
Langflow validates API keys against keys stored in the database, but you can configure Langflow to validate API keys against an environment variable instead.
For more information, see LANGFLOW_API_KEY_SOURCE.
Webhook endpoints require API key authentication by default. To disable authentication for webhook endpoints, use the LANGFLOW_WEBHOOK_AUTH_ENABLE environment variable.
To configure authentication for Langflow MCP servers, see Use Langflow as an MCP server.
Langflow API key permissions
A Langflow API key adopts the privileges of the user who created it. This means that API keys you create have the same permissions and access that you do, including access to your flows, components, and Langflow database. A Langflow API key cannot be used to access resources outside of your own Langflow server.
In single-user environments, you are always a superuser, and your Langflow API keys always have superuser privileges.
In multi-user environments, users who aren't superusers cannot use their API keys to access other users' resources. Superusers can only run their own flows, and cannot run flows owned by other users. You must start your Langflow server with authentication enabled to allow superusers to manage users and create non-superuser accounts.
Create a Langflow API key
You can generate a Langflow API key in your Langflow Settings or with the Langflow CLI.
The CLI option is required if your Langflow server is running in --backend-only mode.
- Langflow Settings
- Langflow CLI
- In the Langflow header, click your profile icon, and then select Settings.
- Click Langflow API Keys, and then click Add New.
- Name your key, and then click Create API Key.
- Copy the API key and store it securely.
If you're serving your flow with --backend-only=true, you can't create API keys in your Langflow Settings because the frontend isn't running.
In this case, you must create API keys with the Langflow CLI.
-
Recommended: Start your Langflow server with authentication enabled.
The Langflow team recommends enabling authentication for security reasons to prevent unauthorized creation of API keys and superusers, especially in production environments. If authentication isn't enabled (
LANGFLOW_AUTO_LOGIN=True), all users are effectively superusers, and they can create API keys with the Langflow CLI. -
Create an API key with
langflow api-key:uv run langflow api-keyAll API keys created with the Langflow CLI have superuser privileges because the command requires superuser authentication, and Langflow API keys adopt the privileges of the user who created them.
Use a Langflow API key
To authenticate Langflow API requests, pass your Langflow API key an x-api-key header or query parameter.
- HTTP header
- Query parameter
curl -X POST \
"http://$LANGFLOW_SERVER_ADDRESS/api/v1/run/$FLOW_ID?stream=false" \
-H "Content-Type: application/json" \
-H "x-api-key: $LANGFLOW_API_KEY" \
-d '{"inputs": {"text":""}, "tweaks": {}}'
curl -X POST \
"http://$LANGFLOW_SERVER_ADDRESS/api/v1/run/$FLOW_ID?x-api-key=$LANGFLOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"inputs": {"text":""}, "tweaks": {}}'
For more information about forming Langflow API requests, see Get started with the Langflow API and Trigger flows with the Langflow API.
Track API key usage
By default, Langflow tracks API key usage through total_uses and last_used_at records in your Langflow database.
To disable API key tracking, set LANGFLOW_DISABLE_TRACK_APIKEY_USAGE=True in your Langflow environment variables.
This can help avoid database contention during periods of high concurrency.
Revoke an API key
To revoke and delete an API key, do the following:
- In the Langflow header, click your profile icon, and then select Settings.
- Click Langflow API Keys.
- Select the keys you want to delete, and then click Delete.
This action immediately invalidates the key and prevents it from being used again.
Component API keys
Component API keys authorize access to external services that are called by components in your flows, such as model providers, databases, or third-party APIs. These aren't Langflow API keys or general application credentials.
In Langflow, you can store component API keys in global variables in your Settings or import them from your runtime environment. For more information, see Global variables.
You create and manage component API keys within the service provider's platform. Langflow only stores the encrypted key value or a secure reference to a key stored elsewhere; it doesn't manage the actual credentials at the source. This means that deleting a global variable from Langflow doesn't delete or invalidate the actual API key in the service provider's system. You must delete or rotate component API keys directly using the service provider's interface or API.
For added security, you can set LANGFLOW_REMOVE_API_KEYS=True to omit API keys and tokens from flow data in your Langflow database.
Additionally, when exporting flows, you can choose to omit API keys from the exported flow JSON.
Authentication environment variables
This section describes the available authentication configuration variables.
You can use the .env.example file in the Langflow repository as a template for your own .env file.
For JWT authentication configuration, including algorithm selection and key management, see JWT authentication.
LANGFLOW_AUTO_LOGIN
This variable controls whether authentication is required to access your Langflow server, including the visual editor, API, and Langflow CLI:
-
If
LANGFLOW_AUTO_LOGIN=False, automatic login is disabled. Users must sign in to the visual editor, authenticate as a superuser to run certain Langflow CLI commands, and use a Langflow API key for Langflow API requests. Iffalse, you must explicitly setLANGFLOW_SUPERUSER_PASSWORDbefore startup. SetLANGFLOW_SUPERUSERonly if you want to override the default superuser username. -
If
LANGFLOW_AUTO_LOGIN=True(default), all API requests require authentication with a Langflow API key, but the visual editor automatically signs in all users as superusers, and Langflow uses the configured superuser username with a configured or generated bootstrap password. All users access the same visual editor environment without password protection, they can run all Langflow CLI commands as superusers, and Langflow automatically authenticates internal requests between the backend and frontend based on the users' superuser privileges. If you also want to bypass authentication for Langflow API requests in addition to other bypassed authentication, seeLANGFLOW_SKIP_AUTH_AUTO_LOGIN.
Langflow doesn't allow users to simultaneously edit the same flow in real time. If two users edit the same flow, Langflow saves only the work of the most recent editor based on the state of that user's workspace. Any changes made by the other user in the interim are overwritten.
Default authentication enforcement and LANGFLOW_SKIP_AUTH_AUTO_LOGIN
In Langflow version 1.6, the default settings are LANGFLOW_AUTO_LOGIN=True and LANGFLOW_SKIP_AUTH_AUTO_LOGIN=False.
This enforces authentication for API requests only, as explained in the preceding section.
For temporary backwards compatibility, you can revert to the fully unauthenticated behavior from earlier versions by setting both variables to true.
However, a future release will set LANGFLOW_AUTO_LOGIN=False and remove LANGFLOW_SKIP_AUTH_AUTO_LOGIN.
At that point, Langflow will strictly enforce API key authentication for API requests, and you can manually disable authentication for some features, like the visual editor, by setting LANGFLOW_AUTO_LOGIN=True.
Authentication enforcement in earlier versions
Langflow version 1.5 was the first version that could enforce authentication for Langflow API requests, regardless of the value of LANGFLOW_AUTO_LOGIN.
As a temporary bypass for backwards compatibility, this version added the LANGFLOW_SKIP_AUTH_AUTO_LOGIN environment variable and set both variables to true by default to preserve the fully unauthenticated behavior from earlier versions.
This allowed users to upgrade to version 1.5 with no change in the authentication behavior.
In Langflow versions earlier than 1.5, Langflow API requests didn't require authentication.
Additionally, the default setting of LANGFLOW_AUTO_LOGIN=True automatically granted all users superuser privileges in the visual editor, and it allowed all users to run all Langflow CLI commands as superusers.
LANGFLOW_ENABLE_SUPERUSER_CLI
Controls the availability of the langflow superuser command in the Langflow CLI.
The default is true, but false is recommended to prevent unrestricted superuser creation.
For more information, see langflow superuser.
LANGFLOW_SUPERUSER and LANGFLOW_SUPERUSER_PASSWORD
These variables specify the username and password for the Langflow server's superuser.
LANGFLOW_SUPERUSER=administrator
LANGFLOW_SUPERUSER_PASSWORD=securepassword
LANGFLOW_SUPERUSER_PASSWORD is required if LANGFLOW_AUTO_LOGIN=False. LANGFLOW_SUPERUSER is optional and defaults to langflow.
LANGFLOW_SUPERUSER_PASSWORD can't use the legacy default value langflow; startup fails closed instead.
When LANGFLOW_AUTO_LOGIN=True, LANGFLOW_SUPERUSER selects the auto-login account username and LANGFLOW_SUPERUSER_PASSWORD is optional. If the password isn't set, Langflow generates an unknown bootstrap password for the auto-login account.
When you start a Langflow server with authentication enabled, if the required password is not set, then startup fails instead of creating a default password.
These defaults don't apply when using the Langflow CLI command langflow superuser.
LANGFLOW_SECRET_KEY
This environment variable stores a secret key used for encrypting sensitive data like API keys and for JWT signing when using the HS256 algorithm. Langflow uses the Fernet library for secret key encryption. For JWT-specific configuration, see JWT authentication.
If no secret key is provided, Langflow automatically generates one.
However, you should generate and explicitly set your own key in production environments. This is particularly important for multi-instance deployments like Kubernetes to ensure consistent encryption across instances.
To generate a secret encryption key for LANGFLOW_SECRET_KEY, do the following:
-
Run the command to generate and copy a secret to the clipboard.
- macOS or Linux
- Windows
-
macOS: Generate a secret key and copy it to the clipboard:
python3 -c "from secrets import token_urlsafe; print(f'LANGFLOW_SECRET_KEY={token_urlsafe(32)}')" | pbcopy -
Linux: Generate a secret key and copy it to the clipboard:
python3 -c "from secrets import token_urlsafe; print(f'LANGFLOW_SECRET_KEY={token_urlsafe(32)}')" | xclip -selection clipboard -
Unix: Generate a secret key and print it to the terminal to manually copy it:
python3 -c "from secrets import token_urlsafe; print(f'LANGFLOW_SECRET_KEY={token_urlsafe(32)}')"
-
Generate a secret key and copy it to the clipboard:
python -c "from secrets import token_urlsafe; print(f'LANGFLOW_SECRET_KEY={token_urlsafe(32)}')" -
Generate a secret key and print it to the terminal to manually copy it:
# Or just print
python -c "from secrets import token_urlsafe; print(f'LANGFLOW_SECRET_KEY={token_urlsafe(32)}')"
-
Paste the value into your
.envfile:LANGFLOW_SECRET_KEY=dBuu...2kM2_fbIf you're running Langflow on Docker, reference the
LANGFLOW_SECRET_KEYfrom your.envfile in thedocker-compose.ymlfile like this:environment:
- LANGFLOW_SECRET_KEY=${LANGFLOW_SECRET_KEY}
Rotate the secret key
Rotate LANGFLOW_SECRET_KEY if the key might have been compromised and as part of your routine credential management practices.
Langflow provides a migration script that re-encrypts stored credentials and other sensitive data with a new key so you can rotate without losing access.
For more information, see Secret Key Rotation in the Langflow Security Policy.