-
How can I deploy my flow as an API so that I can use the chat with the flow using API endpoints? I think there's a feature like this but I couldn't see that in the documentation. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
To deploy your flow as an API and interact with it using API endpoints in Langflow, follow these steps:
Or with Python using import requests
def run_flow(inputs: dict, flow_id: str, tweaks: dict = None, apiKey: str = None) -> dict:
BASE_API_URL = "http://<your_server>/api/v1/run"
api_url = f"{BASE_API_URL}/{flow_id}"
payload = {"inputs": inputs}
headers = {"Content-Type": "application/json"}
if tweaks:
payload["tweaks"] = tweaks
if apiKey:
headers["x-api-key"] = apiKey
response = requests.post(api_url, json=payload, headers=headers)
return response.json()
inputs = {"text": "Sample input"}
api_key = "YOUR_API_KEY"
flow_id = "your_flow_id"
print(run_flow(inputs, flow_id=flow_id, apiKey=api_key)) This will execute the specified flow with your input and return the results. Ensure to replace
|
Beta Was this translation helpful? Give feedback.
To deploy your flow as an API and interact with it using API endpoints in Langflow, follow these steps:
Prepare a POST request to the
/run/{flow_id}
endpoint, replacing{flow_id}
with the ID of the flow you wish to execute.Include necessary headers in your request, such as
Content-Type: application/json
andx-api-key: YOUR_API_KEY
for authentication.Construct the request body with the input value and any tweaks. For example:
Send the request using a tool like
curl
, Postman, or a script. Here's acurl
example: