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 application, codebase, or service.
- Contribute to the overall Langflow codebase.
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.
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:
- Python
- JavaScript
- curl
Base URL
By default, local deployments serve the Langflow API at http://localhost:7860/api.
Remotely hosted Langflow deployments are available at the domain set by the hosting service, such as http://IP_OR_DNS/api or http://IP_OR_DNS:LANGFLOW_PORT/api.
You can configure the Langflow port number in the LANGFLOW_PORT environment variable.
https://UUID.ngrok.app/apihttp://IP_OR_DNS/apihttp://IP_OR_DNS:LANGFLOW_PORT/api
Authentication
In Langflow versions 1.5 and later, most API endpoints require authentication with a Langflow API key in either an x-api-key header or query parameter.
For more information, see API keys and 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.