Skip to main content

API Keys

warning

This page may contain outdated information. It will be updated as soon as possible.

Langflow provides an API key functionality that allows users to access their individual components and flows without traditional login authentication. The API key is a user-specific token that can be included in the request header or query parameter to authenticate API calls. This documentation outlines how to generate, use, and manage API keys in Langflow.

warning

The default user and password are set using the LANGFLOW_SUPERUSER and LANGFLOW_SUPERUSER_PASSWORD environment variables.

The default values are langflow and langflow, respectively.

Generate an API key

Generate a user-specific token to use with Langflow.

Generate an API key with the Langflow UI

Docusaurus themed imageDocusaurus themed image
  1. Click on the "API Key" icon.
  2. Click on "Create new secret key".
  3. Give it an optional name.
  4. Click on "Create secret key".
  5. 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
╰──────────────────────────────

Use the Langflow API key

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

Use the x-api-key header

Include the x-api-key in the HTTP header when making API requests:


_10
curl -X POST \
_10
http://localhost:3000/api/v1/run/<your_flow_id> \
_10
-H 'Content-Type: application/json'\
_10
-H 'x-api-key: <your api key>'\
_10
-d '{"inputs": {"text":""}, "tweaks": {}}'

With Python using requests:


_38
import requests
_38
from typing import Optional
_38
_38
BASE_API_URL = "http://localhost:3001/api/v1/process"
_38
FLOW_ID = "4441b773-0724-434e-9cee-19d995d8f2df"
_38
# You can tweak the flow by adding a tweaks dictionary
_38
# e.g {"OpenAI-XXXXX": {"model_name": "gpt-4"}}
_38
TWEAKS = {}
_38
_38
def run_flow(inputs: dict,
_38
flow_id: str,
_38
tweaks: Optional[dict] = None,
_38
apiKey: Optional[str] = None) -> dict:
_38
"""
_38
Run a flow with a given message and optional tweaks.
_38
_38
:param message: The message to send to the flow
_38
:param flow_id: The ID of the flow to run
_38
:param tweaks: Optional tweaks to customize the flow
_38
:return: The JSON response from the flow
_38
"""
_38
api_url = f"{BASE_API_URL}/{flow_id}"
_38
_38
payload = {"inputs": inputs}
_38
headers = {}
_38
_38
if tweaks:
_38
payload["tweaks"] = tweaks
_38
if apiKey:
_38
headers = {"x-api-key": apiKey}
_38
_38
response = requests.post(api_url, json=payload, headers=headers)
_38
return response.json()
_38
_38
# Setup any tweaks you want to apply to the flow
_38
inputs = {"text":""}
_38
api_key = "<your api key>"
_38
print(run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS, apiKey=api_key))

Use the query parameter

Include the API key as a query parameter in the URL:


_10
curl -X POST \
_10
http://localhost:3000/api/v1/process/<your_flow_id>?x-api-key=<your_api_key> \
_10
-H 'Content-Type: application/json'\
_10
-d '{"inputs": {"text":""}, "tweaks": {}}'

With Python using requests:


_37
import requests
_37
_37
BASE_API_URL = "http://localhost:3001/api/v1/process"
_37
FLOW_ID = "4441b773-0724-434e-9cee-19d995d8f2df"
_37
# You can tweak the flow by adding a tweaks dictionary
_37
# e.g {"OpenAI-XXXXX": {"model_name": "gpt-4"}}
_37
TWEAKS = {}
_37
_37
def run_flow(inputs: dict,
_37
flow_id: str,
_37
tweaks: Optional[dict] = None,
_37
apiKey: Optional[str] = None) -> dict:
_37
"""
_37
Run a flow with a given message and optional tweaks.
_37
_37
:param message: The message to send to the flow
_37
:param flow_id: The ID of the flow to run
_37
:param tweaks: Optional tweaks to customize the flow
_37
:return: The JSON response from the flow
_37
"""
_37
api_url = f"{BASE_API_URL}/{flow_id}"
_37
_37
payload = {"inputs": inputs}
_37
headers = {}
_37
_37
if tweaks:
_37
payload["tweaks"] = tweaks
_37
if apiKey:
_37
api_url += f"?x-api-key={apiKey}"
_37
_37
response = requests.post(api_url, json=payload, headers=headers)
_37
return response.json()
_37
_37
# Setup any tweaks you want to apply to the flow
_37
inputs = {"text":""}
_37
api_key = "<your api key>"
_37
print(run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS, apiKey=api_key))

Security Considerations

  • Visibility: For security reasons, the API key cannot be retrieved again through the UI.
  • Scope: The key allows access only to the flows and components of the specific user to whom it was issued.

Custom API endpoint

Under Project Settings > Endpoint Name, you can pick a custom name for the endpoint used to call your flow from the API.

Revoke an API Key

To revoke an API key, delete it from the UI. This action immediately invalidates the key and prevents it from being used again.

Hi, how can I help you?