API Keys
Introduction
Langflow offers an API Key functionality that allows users to access their individual components and flows without going through traditional login authentication. The API Key is a user-specific token that can be included in the request's header or query parameter to authenticate API calls. The following documentation outlines how to generate, use, and manage these API Keys in Langflow.
Generating an API Key
Through 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.
Using the API Key
Using 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/process/<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))
Using the Query Parameter
Alternatively, you can 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": {}}'
Or with Python:
_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: The API key won't be retrievable again through the UI for security reasons.
- Scope: The key only allows access to the flows and components of the specific user to whom it was issued.
Revoking an API Key
To revoke an API key, simply delete it from the UI. This will immediately invalidate the key and prevent it from being used again.