Langflow API Request in Python
This code snippet demonstrates how to make a POST request to the Langflow API using the Python requests library.
# Note: Replace <YOUR_APPLICATION_TOKEN> with your actual Application token
import requests
# The complete API endpoint URL for this flow
url = f"https://api.langflow.astra.datastax.com/lf/c7dd896f-ee9e-4616-a04f-9b55fc7251af/api/v1/run/6943989f-f50b-40d1-9db5-2abfa29b2f95"
# Request payload configuration
payload = {
"input_value": "hello world!", # The input value to be processed by the flow
"output_type": "chat", # Specifies the expected output format
"input_type": "chat" # Specifies the input format
}
# Request headers
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer <YOUR_APPLICATION_TOKEN>" # Authentication key from environment variable'}
}
try:
# Send API request
response = requests.request("POST", url, json=payload, headers=headers)
response.raise_for_status() # Raise exception for bad status codes
# Print response
print(response.text)
except requests.exceptions.RequestException as e:
print(f"Error making API request: {e}")
except ValueError as e:
print(f"Error parsing response: {e}")
import requests
# The complete API endpoint URL for this flow
url = f"https://api.langflow.astra.datastax.com/lf/c7dd896f-ee9e-4616-a04f-9b55fc7251af/api/v1/run/6943989f-f50b-40d1-9db5-2abfa29b2f95"
# Request payload configuration
payload = {
"input_value": "hello world!", # The input value to be processed by the flow
"output_type": "chat", # Specifies the expected output format
"input_type": "chat" # Specifies the input format
}
# Request headers
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer <YOUR_APPLICATION_TOKEN>" # Authentication key from environment variable'}
}
try:
# Send API request
response = requests.request("POST", url, json=payload, headers=headers)
response.raise_for_status() # Raise exception for bad status codes
# Print response
print(response.text)
except requests.exceptions.RequestException as e:
print(f"Error making API request: {e}")
except ValueError as e:
print(f"Error parsing response: {e}")
Note: This HTML code provides a formatted display of the original Python code. It does not execute the code. To run the code, you need a Python environment with the requests library installed.