Skip to main content

API keys

Langflow provides an API key functionality that allows users to access their individual components and flows without traditional login authentication.

Generate a Langflow API key

Generate a user-specific token to use with Langflow.

Generate an API key with the Langflow UI

  1. Click your user icon, and then select Settings.
  2. Click Langflow API, and then click Add New.
  3. Name your key, and then click Create Secret Key.
  4. Copy the API key and store it in a secure location.

Generate an API key with the Langflow CLI


_13
langflow api-key
_13
# or
_13
python -m langflow api-key
_13
╭─────────────────────────────────────────────────────────────────────╮
_13
│ API Key Created Successfully: │
_13
│ │
_13
│ sk-O0elzoWID1izAH8RUKrnnvyyMwIzHi2Wk-uXWoNJ2Ro │
_13
│ │
_13
│ This is the only time the API key will be displayed. │
_13
│ Make sure to store it in a secure location. │
_13
│ │
_13
│ The API key has been copied to your clipboard. Cmd + V to paste it. │
_13
╰──────────────────────────────

Authenticate requests with the Langflow API key

Include your API key in API requests to authenticate requests to Langflow.

API keys allow access only to the flows and components of the specific user to whom the key was issued.

Include the API key in the HTTP header

To use the API key when making API requests, include the API key in the HTTP header:


_10
curl -X POST \
_10
"http://127.0.0.1:7860/api/v1/run/FLOW_ID?stream=false" \
_10
-H 'Content-Type: application/json' \
_10
-H 'x-api-key: API_KEY' \
_10
-d '{"inputs": {"text":""}, "tweaks": {}}'

Include the API key as a query parameter

To pass the API key as a query parameter:


_10
curl -X POST \
_10
"http://127.0.0.1:7860/api/v1/run/FLOW_ID?x-api-key=API_KEY?stream=false" \
_10
-H 'Content-Type: application/json' \
_10
-d '{"inputs": {"text":""}, "tweaks": {}}'

Generate a Langflow secret key

Langflow uses the Fernet library for encrypting sensitive data.

If no LANGFLOW_SECRET_KEY is provided, Langflow automatically generates one.

For more information, see Authentication.

Revoke an API key

To revoke an API key, delete it from the list of keys in the Settings menu.

  1. Click your user icon, and then select Settings.
  2. Click Langflow API.
  3. Select the keys you want to delete and click the trash can icon.

This action immediately invalidates the key and prevents it from being used again.

Add component API keys to Langflow

These are credentials for external services like OpenAI. They can be added to Langflow with the .env file or in the Langflow UI.

Component API keys that are set in the UI override those that are set in the environment variables.

Add component API keys with the .env file

To add component API keys to your .env file:


_10
OPENAI_API_KEY=sk-...
_10
ANTHROPIC_API_KEY=sk-...
_10
GOOGLE_API_KEY=...

Add component API keys with the Langflow UI

To add component API keys as Global variables with the Langflow UI:

  1. Click your user icon, and then select Settings.
  2. Click Langflow API.
  3. Add new API keys as Credential type variables.
  4. Apply them to specific component fields.

Component values set directly in a flow override values set in the UI and environment variables.

For more information, see Global variables.

Search