Flow trigger endpoints
Use the /run amd /webhook endpoints to run flows.
Use the /run and /webhook endpoints to run flows.
To create, read, update, and delete flows, see Flow management endpoints.
Run flow
Execute a specified flow by ID or name. -The flow is executed as a batch, but LLM responses can be streamed.
-This example runs a Basic Prompting flow with a given flow ID and passes a JSON object as the input value. -Flow IDs can be found on the Publish pane or in a flow's URL.
-The parameters are passed in the request body. In this example, the values are the default values.
-- curl
- Result
_11curl -X POST \_11 "$LANGFLOW_URL/api/v1/run/$FLOW_ID" \_11 -H "Content-Type: application/json" \_11 -d '{_11 "input_value": "Tell me about something interesting!",_11 "session_id": "chat-123",_11 "input_type": "chat",_11 "output_type": "chat",_11 "output_component": "",_11 "tweaks": null_11 }'
_29{_29 "session_id": "chat-123",_29 "outputs": [{_29 "inputs": {_29 "input_value": "Tell me about something interesting!"_29 },_29 "outputs": [{_29 "results": {_29 "message": {_29 "text": "Sure! Have you ever heard of the phenomenon known as \"bioluminescence\"? It's a fascinating natural occurrence where living organisms produce and emit light. This ability is found in various species, including certain types of jellyfish, fireflies, and deep-sea creatures like anglerfish.\n\nBioluminescence occurs through a chemical reaction in which a light-emitting molecule called luciferin reacts with oxygen, catalyzed by an enzyme called luciferase. The result is a beautiful glow that can serve various purposes, such as attracting mates, deterring predators, or luring prey.\n\nOne of the most stunning displays of bioluminescence can be seen in the ocean, where certain plankton emit light when disturbed, creating a mesmerizing blue glow in the water. This phenomenon is often referred to as \"sea sparkle\" and can be seen in coastal areas around the world.\n\nBioluminescence not only captivates our imagination but also has practical applications in science and medicine, including the development of biosensors and imaging techniques. It's a remarkable example of nature's creativity and complexity!",_29 "sender": "Machine",_29 "sender_name": "AI",_29 "session_id": "chat-123",_29 "timestamp": "2025-03-03T17:17:37+00:00",_29 "flow_id": "d2bbd92b-187e-4c84-b2d4-5df365704201",_29 "properties": {_29 "source": {_29 "id": "OpenAIModel-d1wOZ",_29 "display_name": "OpenAI",_29 "source": "gpt-4o-mini"_29 },_29 "icon": "OpenAI"_29 },_29 "component_id": "ChatOutput-ylMzN"_29 }_29 }_29 }]_29 }]_29}
The following example runs a Basic Prompting flow with flow parameters passed in the request body.
+This flow requires a chat input string (input_value), and uses default values for all other parameters.
_11curl -X POST \_11 "$LANGFLOW_SERVER_URL/api/v1/run/$FLOW_ID" \_11 -H "Content-Type: application/json" \_11 -d '{_11 "input_value": "Tell me about something interesting!",_11 "session_id": "chat-123",_11 "input_type": "chat",_11 "output_type": "chat",_11 "output_component": "",_11 "tweaks": null_11 }'
The response from /v1/run/$FLOW_ID includes metadata, inputs, and outputs for the run.
Result
The following example illustrates a response from a Basic Prompting flow:
_29{_29 "session_id": "chat-123",_29 "outputs": [{_29 "inputs": {_29 "input_value": "Tell me about something interesting!"_29 },_29 "outputs": [{_29 "results": {_29 "message": {_29 "text": "Sure! Have you ever heard of the phenomenon known as \"bioluminescence\"? It's a fascinating natural occurrence where living organisms produce and emit light. This ability is found in various species, including certain types of jellyfish, fireflies, and deep-sea creatures like anglerfish.\n\nBioluminescence occurs through a chemical reaction in which a light-emitting molecule called luciferin reacts with oxygen, catalyzed by an enzyme called luciferase. The result is a beautiful glow that can serve various purposes, such as attracting mates, deterring predators, or luring prey.\n\nOne of the most stunning displays of bioluminescence can be seen in the ocean, where certain plankton emit light when disturbed, creating a mesmerizing blue glow in the water. This phenomenon is often referred to as \"sea sparkle\" and can be seen in coastal areas around the world.\n\nBioluminescence not only captivates our imagination but also has practical applications in science and medicine, including the development of biosensors and imaging techniques. It's a remarkable example of nature's creativity and complexity!",_29 "sender": "Machine",_29 "sender_name": "AI",_29 "session_id": "chat-123",_29 "timestamp": "2025-03-03T17:17:37+00:00",_29 "flow_id": "d2bbd92b-187e-4c84-b2d4-5df365704201",_29 "properties": {_29 "source": {_29 "id": "OpenAIModel-d1wOZ",_29 "display_name": "OpenAI",_29 "source": "gpt-4o-mini"_29 },_29 "icon": "OpenAI"_29 },_29 "component_id": "ChatOutput-ylMzN"_29 }_29 }_29 }]_29 }]_29}
If you are parsing the response in an application, you most likely need to extract the relevant content from the response, rather than pass the entire response back to the user. +For an example of a script that extracts data from a Langflow API response, see the Quickstart.
Stream LLM token responses
-To stream LLM token responses, append the ?stream=true query parameter to the request. LLM chat responses are streamed back as token events until the end event closes the connection.
- curl
- Result
_10curl -X POST \_10 "$LANGFLOW_URL/api/v1/run/$FLOW_ID?stream=true" \_10 -H "accept: application/json" \_10 -H "Content-Type: application/json" \_10 -d '{_10 "message": "Tell me something interesting!",_10 "session_id": "chat-123"_10 }'
_19{"event": "add_message", "data": {"timestamp": "2025-03-03T17:20:18", "sender": "User", "sender_name": "User", "session_id": "chat-123", "text": "Tell me about something interesting!", "files": [], "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": null, "display_name": null, "source": null}, "icon": "", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": [], "id": "0103a21b-ebf7-4c02-9d72-017fb297f812", "flow_id": "d2bbd92b-187e-4c84-b2d4-5df365704201"}}_19_19{"event": "add_message", "data": {"timestamp": "2025-03-03T17:20:18", "sender": "Machine", "sender_name": "AI", "session_id": "chat-123", "text": "", "files": [], "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": "OpenAIModel-d1wOZ", "display_name": "OpenAI", "source": "gpt-4o-mini"}, "icon": "OpenAI", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": [], "id": "27b66789-e673-4c65-9e81-021752925161", "flow_id": "d2bbd92b-187e-4c84-b2d4-5df365704201"}}_19_19{"event": "token", "data": {"chunk": " Have", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}_19_19{"event": "token", "data": {"chunk": " you", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}_19_19{"event": "token", "data": {"chunk": " ever", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}_19_19{"event": "token", "data": {"chunk": " heard", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}_19_19{"event": "token", "data": {"chunk": " of", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}_19_19{"event": "token", "data": {"chunk": " the", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}_19_19{"event": "token", "data": {"chunk": " phenomenon", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}_19_19{"event": "end", "data": {"result": {"session_id": "chat-123", "message": "Sure! Have you ever heard of the phenomenon known as \"bioluminescence\"?..."}}}
This result is abbreviated, but illustrates where the end event completes the LLM's token streaming response.
With /v1/run/$FLOW_ID, the flow is executed as a batch with optional LLM token response streaming.
To stream LLM token responses, append the ?stream=true query parameter to the request:
_10curl -X POST \_10 "$LANGFLOW_SERVER_URL/api/v1/run/$FLOW_ID?stream=true" \_10 -H "accept: application/json" \_10 -H "Content-Type: application/json" \_10 -d '{_10 "message": "Tell me something interesting!",_10 "session_id": "chat-123"_10 }'
LLM chat responses are streamed back as token events, culminating in a final end event that closes the connection.
Result
The following example is truncated to illustrate a series of token events as well as the final end event that closes the LLM's token streaming response:
_19{"event": "add_message", "data": {"timestamp": "2025-03-03T17:20:18", "sender": "User", "sender_name": "User", "session_id": "chat-123", "text": "Tell me about something interesting!", "files": [], "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": null, "display_name": null, "source": null}, "icon": "", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": [], "id": "0103a21b-ebf7-4c02-9d72-017fb297f812", "flow_id": "d2bbd92b-187e-4c84-b2d4-5df365704201"}}_19_19{"event": "add_message", "data": {"timestamp": "2025-03-03T17:20:18", "sender": "Machine", "sender_name": "AI", "session_id": "chat-123", "text": "", "files": [], "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": "OpenAIModel-d1wOZ", "display_name": "OpenAI", "source": "gpt-4o-mini"}, "icon": "OpenAI", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": [], "id": "27b66789-e673-4c65-9e81-021752925161", "flow_id": "d2bbd92b-187e-4c84-b2d4-5df365704201"}}_19_19{"event": "token", "data": {"chunk": " Have", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}_19_19{"event": "token", "data": {"chunk": " you", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}_19_19{"event": "token", "data": {"chunk": " ever", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}_19_19{"event": "token", "data": {"chunk": " heard", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}_19_19{"event": "token", "data": {"chunk": " of", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}_19_19{"event": "token", "data": {"chunk": " the", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}_19_19{"event": "token", "data": {"chunk": " phenomenon", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}_19_19{"event": "end", "data": {"result": {"session_id": "chat-123", "message": "Sure! Have you ever heard of the phenomenon known as \"bioluminescence\"?..."}}}
Run endpoint headers
-| Header | Info | Example |
|---|---|---|
| Content-Type | Required. Specifies the JSON format. | "application/json" |
| accept | Required. Specifies the response format. | "application/json" |
| x-api-key | Optional. Required only if authentication is enabled. | "sk-..." |
| Header | Info | Example |
|---|---|---|
| Content-Type | Required. Specifies the JSON format. | "application/json" |
| accept | Optional. Specifies the response format. | "application/json" |
| x-api-key | Optional. Required only if authentication is enabled. | "sk-..." |
Run endpoint parameters
| Parameter | Type | Info |
|---|---|---|
| flow_id | UUID/string | Required. Part of URL: /run/$FLOW_ID |
| stream | boolean | Optional. Query parameter: /run/$FLOW_ID?stream=true |
| input_value | string | Optional. JSON body field. Main input text/prompt. Default: null |
| input_type | string | Optional. JSON body field. Input type ("chat" or "text"). Default: "chat" |
| output_type | string | Optional. JSON body field. Output type ("chat", "any", "debug"). Default: "chat" |
| output_component | string | Optional. JSON body field. Target component for output. Default: "" |
| tweaks | object | Optional. JSON body field. Component adjustments. Default: null |
| session_id | string | Optional. JSON body field. Conversation context ID. See Session ID. Default: null |
Request example with all headers and parameters
-
_17curl -X POST \_17 "http://$LANGFLOW_URL/api/v1/run/$FLOW_ID?stream=true" \_17 -H "Content-Type: application/json" \_17 -H "accept: application/json" \_17 -H "x-api-key: sk-..." \_17 -d '{_17 "input_value": "Tell me a story",_17 "input_type": "chat",_17 "output_type": "chat",_17 "output_component": "chat_output",_17 "session_id": "chat-123",_17 "tweaks": {_17 "component_id": {_17 "parameter_name": "value"_17 }_17 }_17 }'
_17curl -X POST \_17 "$LANGFLOW_SERVER_URL/api/v1/run/$FLOW_ID?stream=true" \_17 -H "Content-Type: application/json" \_17 -H "accept: application/json" \_17 -H "x-api-key: sk-..." \_17 -d '{_17 "input_value": "Tell me a story",_17 "input_type": "chat",_17 "output_type": "chat",_17 "output_component": "chat_output",_17 "session_id": "chat-123",_17 "tweaks": {_17 "component_id": {_17 "parameter_name": "value"_17 }_17 }_17 }'
Webhook run flow
Use the /webhook endpoint to start a flow by sending an HTTP POST request.
After you add a Webhook component to a flow, open the API access pane, and then click the Webhook cURL tab to get an automatically generated POST /webhook request for your flow.
_10curl -X POST \_10 "$LANGFLOW_URL/api/v1/webhook/$FLOW_ID" \_10 -H "Content-Type: application/json" \_10 -d '{"data": "example-data"}'
_10curl -X POST \_10 "$LANGFLOW_SERVER_URL/api/v1/webhook/$FLOW_ID" \_10 -H "Content-Type: application/json" \_10 -d '{"data": "example-data"}'
Result
_10{_10 "message": "Task started in the background",_10 "status": "in progress"_10}
For more information, see Webhook component and Trigger flows with webhooks.
Deprecated flow trigger endpoints
diff --git a/api-flows.html b/api-flows.html index d77bfd13ea..027d8444b1 100644 --- a/api-flows.html +++ b/api-flows.html @@ -21,7 +21,7 @@ - + diff --git a/api-logs.html b/api-logs.html index 4fe6e6f2db..ab0116188c 100644 --- a/api-logs.html +++ b/api-logs.html @@ -21,7 +21,7 @@ - + diff --git a/api-monitor.html b/api-monitor.html index aebb59af4f..a4fd2a5500 100644 --- a/api-monitor.html +++ b/api-monitor.html @@ -21,7 +21,7 @@ - + diff --git a/api-projects.html b/api-projects.html index c2322b21e8..32743c32a9 100644 --- a/api-projects.html +++ b/api-projects.html @@ -21,7 +21,7 @@ - + diff --git a/api-reference-api-examples.html b/api-reference-api-examples.html index 80865cb94b..171da2e60e 100644 --- a/api-reference-api-examples.html +++ b/api-reference-api-examples.html @@ -21,7 +21,7 @@ - + @@ -47,9 +47,11 @@To view and test all available endpoints, you can access the Langflow API's OpenAPI specification at your Langflow deployment's /docs endpoint, such as http://localhost:7860/docs.
For an example of the Langflow API in a script, see the Langflow quickstart.
The quickstart demonstrates how to get automatically generated code snippets for your flows, use a script to run a flow, and extract data from the Langfow API response.
For an example of the Langflow API in a script, see the Langflow quickstart.
The quickstart demonstrates how to get automatically generated code snippets for your flows, use a script to run a flow, and extract data from the Langfow API response.
Form Langflow API requests
-While individual parameters vary by endpoint, all Langflow API requests share some commonalities.
+While individual options vary by endpoint, all Langflow API requests share some commonalities, like a URL, method, parameters, and authentication.
+As an example of a Langflow API request, the following curl command calls the /v1/run endpoint, and it passes a runtime override (tweaks) to the flow's Chat Output component:
_14curl --request POST \_14 --url "$LANGFLOW_SERVER_URL/api/v1/run/$FLOW_ID?stream=false" \_14 --header "Content-Type: application/json" \_14 --header "x-api-key: $LANGFLOW_API_KEY" \_14 --data '{_14 "input_value": "hello world!",_14 "output_type": "chat",_14 "input_type": "chat",_14 "tweaks": {_14 "ChatOutput-6zcZt": {_14 "should_store_message": true_14 }_14 }_14}'
Base URL
Local deployments serve the Langflow API at http://localhost:LANGFLOW_PORT/api.
The default port is 7868 or 7860:
If explicit authentication is required, you must provide a valid Langflow API key in either an x-api-key header or query parameter.
For more information, see API keys.
Because authentication isn't always required, Langflow API examples in the Langflow documentation often omit authentication.
+As with any API, follow industry best practices for storing and referencing sensitive credentials. +For example, you can set environment variables for your API keys, and then reference those environment variables in your API requests.
Methods, paths, and parameters
-Langflow API requests use a variety of methods, paths, path parameters, query parameters, and body parameters. +
Langflow API requests use various methods, paths, path parameters, query parameters, and body parameters. The specific requirements and options depend on the endpoint that you want to call.
For example, to create a flow, you pass a JSON-formatted flow definition to POST /v1/flows.
Then, to run your flow, you call POST /v1/run/$FLOW_ID with optional run parameters in the request body.
Versions
+API versions
The Langflow API serves /v1 and /v2 endpoints.
Some endpoints only exist under a single version and some exist under both the /v1 and /v2 versions.
If a request fails or has an unexpected result, make sure your endpoint path has the correct version.
Set environment variables
-As a best practice with any API, store commonly used values in environment variables to facilitate reuse, simplify token rotation, and securely reference sensitive values.
-You can use any method you prefer to set environment variables, such as export, .env, zshrc, or .curlrc.
-Additionally, be sure to follow industry best practices when storing credentials and other sensitive values.
You might find it helpful to set environment variables for values like your Langflow server URL, Langflow API keys, flow IDs, and project IDs. +
You can store commonly used values in environment variables to facilitate reuse, simplify token rotation, and securely reference sensitive values.
+You can use any method you prefer to set environment variables, such as export, .env, zshrc, or .curlrc.
+Then, reference those environment variables in your API requests.
For example:
_10export LANGFLOW_URL="http://localhost:7860"_10export FLOW_ID="359cd752-07ea-46f2-9d3b-a4407ef618da"_10export PROJECT_ID="1415de42-8f01-4f36-bf34-539f23e47466"_10export API_KEY="sk-..."
-
-
- You can find flow IDs on the Publish pane, in a flow's URL, and with
GET /flows.
- - You can retrieve project IDs with
GET /projects(/api-projects#read-projects).
-
_20# Set environment variables_20export LANGFLOW_API_KEY="sk..."_20export LANGFLOW_SERVER_URL="https://localhost:7860"_20export FLOW_ID="359cd752-07ea-46f2-9d3b-a4407ef618da"_20_20# Use environment variables in API requests_20curl --request POST \_20 --url "$LANGFLOW_SERVER_URL/api/v1/run/$FLOW_ID$?stream=false" \_20 --header "Content-Type: application/json" \_20 --header "x-api-key: $LANGFLOW_API_KEY" \_20 --data '{_20 "input_value": "hello world!",_20 "output_type": "chat",_20 "input_type": "chat",_20 "tweaks": {_20 "ChatOutput-6zcZt": {_20 "should_store_message": true_20 }_20 }_20}'
Commonly used values in Langflow API requests include your Langflow server URL, Langflow API keys, flow IDs, and project IDs.
+You can retrieve flow IDs from the API access pane, in a flow's URL, and with GET /flows.
Try some Langflow API requests
Once you have your Langflow server URL, try calling these endpoints that return Langflow metadata.
If authentication is required, include an x-api-key header or query parameter with a valid Langflow API key, such as -H 'x-api-key: $API_KEY'.
Get version
Returns the current Langflow API version:
-
_10curl -X GET \_10 "$LANGFLOW_URL/api/v1/version" \_10 -H "accept: application/json"
_10curl -X GET \_10 "$LANGFLOW_SERVER_URL/api/v1/version" \_10 -H "accept: application/json"
Result
_10{_10 "version": "1.1.1",_10 "main_version": "1.1.1",_10 "package": "Langflow"_10}
Get configuration
Returns configuration details for your Langflow deployment:
-
_10curl -X GET \_10 "$LANGFLOW_URL/api/v1/config" \_10 -H "accept: application/json"
_10curl -X GET \_10 "$LANGFLOW_SERVER_URL/api/v1/config" \_10 -H "accept: application/json"
Result
_10{_10 "feature_flags": {_10 "mvp_components": false_10 },_10 "frontend_timeout": 0,_10 "auto_saving": true,_10 "auto_saving_interval": 1000,_10 "health_check_max_retries": 5,_10 "max_file_size_upload": 100_10}
Get all components
Returns a dictionary of all Langflow components:
-
_10curl -X GET \_10 "$LANGFLOW_URL/api/v1/all" \_10 -H "accept: application/json"
_10curl -X GET \_10 "$LANGFLOW_SERVER_URL/api/v1/all" \_10 -H "accept: application/json"
Next steps
- Use the Langflow API to run a flow.
- Use the Langflow API to upload files.
- Use the Langflow API to get flow logs.
- Explore all endpoints in the Langflow API specification. -