Skip to main content

Get started with the Langflow API

You can use the Langflow API for programmatic interactions with Langflow, such as the following:

  • Create and edit flows, including file management for flows.
  • Develop applications that use your flows.
  • Develop custom components.
  • Build Langflow as a dependency of a larger project.
  • Contribute to the overall Langflow project.

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.

Try it

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 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:


_14
curl --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:

  • Local Langflow Desktop: http://localhost:7868/api
  • Local Langflow OSS: http://localhost:7860/api
  • Local Langflow Docker image: http://localhost:7860/api

Remotely hosted Langflow deployments are available at the domain set by the hosting service. For example:

  • https://UUID.ngrok.app/api
  • http://IP_OR_DNS/api
  • http://IP_OR_DNS:LANGFLOW_PORT/api
tip

The Langflow port number is set in the LANGFLOW_PORT environment variable.

Authentication

Your Langflow deployment's authentication settings determine whether Langflow API requests require explicit authentication with a Langflow API key.

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 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.

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

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:


_20
# Set environment variables
_20
export LANGFLOW_API_KEY="sk..."
_20
export LANGFLOW_SERVER_URL="https://localhost:7860"
_20
export FLOW_ID="359cd752-07ea-46f2-9d3b-a4407ef618da"
_20
_20
# Use environment variables in API requests
_20
curl --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:


_10
curl -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:


_10
curl -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:


_10
curl -X GET \
_10
"$LANGFLOW_SERVER_URL/api/v1/all" \
_10
-H "accept: application/json"

Next steps

Search