--- title: API keys and authentication slug: /api-keys-and-authentication --- import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import Icon from "@site/src/components/icon"; :::warning 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](#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](#langflow-api-keys): For authentication with the Langflow API and authorizing server-side Langflow actions like running flows and uploading files. * [Component API keys](#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](#authentication-environment-variables): These environment variables configure how Langflow handles user authentication and authorization. ## Langflow API keys {#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`](#langflow-api-key-source). To require API key authentication for flow webhook endpoints, use the [`LANGFLOW_WEBHOOK_AUTH_ENABLE`](/webhook#require-authentication-for-webhooks) environment variable. To configure authentication for Langflow MCP servers, see [Use Langflow as an MCP server](/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](#start-a-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. 1. In the Langflow header, click your profile icon, and then select **Settings**. 2. Click **Langflow API Keys**, and then click **Add New**. 3. Name your key, and then click **Create API Key**. 4. 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. 1. Recommended: [Start your Langflow server with authentication enabled](#start-a-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. 2. Create an API key with [`langflow api-key`](/configuration-cli#langflow-api-key): ```shell uv run langflow api-key ``` All 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. ```shell 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": {}}' ``` ```shell 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](/api-reference-api-examples) and [Trigger flows with the Langflow API](/concepts-publish). ### Track API key usage By default, Langflow tracks API key usage through `total_uses` and `last_used_at` records in your [Langflow database](/memory). To disable API key tracking, set `LANGFLOW_DISABLE_TRACK_APIKEY_USAGE=True` in your [Langflow environment variables](/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: 1. In the Langflow header, click your profile icon, and then select **Settings**. 2. Click **Langflow API Keys**. 3. Select the keys you want to delete, and then click