API Keys
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.
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โ
-
Click on the "API Key" icon.
-
Click on "Create new secret key".
-
Give it an optional name.
-
Click on "Create secret key".
-
Copy the API key and store it in a secure location.
Generate an API key with the Langflow CLIโ
_13langflow api-key_13# or_13python -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:
_10curl -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:
_38import requests_38from typing import Optional_38_38BASE_API_URL = "<http://localhost:3001/api/v1/process>"_38FLOW_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"}}_38TWEAKS = {}_38_38def 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_38inputs = {"text":""}_38api_key = "<your api key>"_38print(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:
_10curl -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:
_37import requests_37_37BASE_API_URL = "<http://localhost:3001/api/v1/process>"_37FLOW_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"}}_37TWEAKS = {}_37_37def 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_37inputs = {"text":""}_37api_key = "<your api key>"_37print(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.
