CTCaliberTek
Course: Langflow: Visual AI Builder (10 Modules) · Lesson 6 of 10Log in to track your progress and earn a certificate when you finish the course.
AI & Machine Learning

Langflow Module 6: Calling Flows from Code with the REST API

Published September 9, 2026·Updated October 29, 2026·8 min read
Like SaveLog in to like, save, and track progress.

Introduction

A flow becomes useful to other software when it is available as an API. Every Langflow flow can be run over HTTP. This module shows how to create an API key, find your flow's ID, call the run endpoint from the command line and from Python, and read the reply.

Prerequisites

  • A working flow with Chat Input and Chat Output
  • Basic familiarity with HTTP requests

Step-by-Step Guide

Step 1: Create a Langflow API key

Click your profile icon, choose Settings, then Langflow API Keys, and click Add New. Name the key and click Create API Key, then copy it immediately and store it securely. This key authenticates calls to Langflow and is separate from your model provider's key.

Step 2: Find the flow ID and a ready-made snippet

Open the flow, click Share, and choose API access. It shows ready-made snippets with your flow ID filled in. You can also give the flow a friendlier Endpoint Name there, using letters, numbers, hyphens, and underscores.

Step 3: Call the run endpoint with curl

Send a POST request to the flow's run endpoint with your key in the x-api-key header. The body carries the user's message in input_value. A session_id groups messages into one conversation.

export LANGFLOW_SERVER_URL="http://localhost:7860"
export FLOW_ID="your-flow-id"
export LANGFLOW_API_KEY="your-langflow-api-key"

curl -X POST "$LANGFLOW_SERVER_URL/api/v1/run/$FLOW_ID" \
  -H "Content-Type: application/json" \
  -H "x-api-key: $LANGFLOW_API_KEY" \
  -d '{"input_value": "Tell me about something interesting!",
       "session_id": "chat-123",
       "input_type": "chat", "output_type": "chat"}'

Step 4: Call it from Python

The same request works with the requests library. Read the keys from environment variables rather than writing them into source code. The reply text sits deep in the response structure, as shown in the Langflow quickstart.

import os
import requests

base = os.environ["LANGFLOW_SERVER_URL"]
flow_id = os.environ["FLOW_ID"]

response = requests.post(
    base + "/api/v1/run/" + flow_id,
    headers={
        "Content-Type": "application/json",
        "x-api-key": os.environ["LANGFLOW_API_KEY"],
    },
    json={
        "input_value": "Tell me about something interesting!",
        "session_id": "chat-123",
        "input_type": "chat",
        "output_type": "chat",
    },
    timeout=60,
)
response.raise_for_status()
data = response.json()
print(data["outputs"][0]["outputs"][0]["outputs"]["message"]["message"])

Step 5: Use sessions, streaming, and tweaks

Reuse the same session_id to continue a conversation. Add ?stream=true to the URL for streamed output. Tweaks override a component's parameters for a single run, using the component's ID as the key, which is useful for switching models or settings without editing the flow. Which tweaks are allowed is controlled by the LANGFLOW_TWEAKS_POLICY setting.

{
  "input_value": "Summarize this ticket",
  "tweaks": {
    "Agent-ZOknz": {"model_name": "your-model-name"}
  }
}

FAQs

Is the Playground suitable for putting a flow in my app?
No. The Playground is for testing. Call the run API from your backend and keep your API key on the server, never in browser code.
Why does the reply have such a nested structure?
A flow can have several components and outputs, so the response describes all of them. For a simple chat flow, the message text is at a predictable path, and larger flows may need you to select the right output.

Summary

Create a Langflow API key, copy the flow ID from Share, API access, and POST to the run endpoint with x-api-key and an input_value. Use session_id for conversations and tweaks for per-request changes, and keep keys on the server.

Related tutorials

Comments

Log in or create a free account to join the discussion.

  • No comments yet. Be the first to comment.