API pane
The API pane presents code templates for integrating your flow into external applications.
cURL
The cURL tab displays sample code for posting a query to your flow. Modify the input_value
to change your input message. Copy the code and run it to post a query to your flow and get the result.
Python API
The Python API tab displays code to interact with your flow using the Python HTTP requests
library.
To use the requests
library:
- Copy and paste the code into a Python script.
- Run the script and pass your message with it.
_10python3 python-api-script.py --message="tell me about something interesting"
Python code
The Python Code tab displays code to interact with your flow's .json
file using the Langflow runtime.
To use your code in a Python application using the Langflow runtime, you have to first download your flow’s JSON file.
-
In your Workspace, click Settings, and then select Export.
-
Download the flow to your local machine. Make sure the flow path in the script matches the flow’s location on your machine.
-
Copy and paste the code from the API tab into a Python script file. It will look like this:
_14from langflow.load import run_flow_from_json_14TWEAKS = {_14 "ChatInput-kKhri": {},_14 "Prompt-KDSi5": {},_14 "ChatOutput-Vr3Q7": {},_14 "OpenAIModel-4xYtx": {}_14}_14_14result = run_flow_from_json(flow="./basic-prompting-local.json",_14 input_value="tell me about something interesting",_14 fallback_to_env_vars=True, # False by default_14 tweaks=TWEAKS)_14_14print(result)
- Run the script:
_10python3 python-api-script.py
Tweaks
The Tweaks tab displays the available parameters for your flow. Modifying the parameters changes the code parameters across all windows. For example, changing the Chat Input component's input_value
will change that value across all API calls.
Send image files to your flow with the API
For information on sending files to the Langflow API, see API examples.
Chat Widget
The Chat Widget HTML tab displays code that can be inserted in the <body>
of your HTML to interact with your flow.
The Langflow Chat Widget is a powerful web component that enables communication with a Langflow project. This widget allows for a chat interface embedding, allowing the integration of Langflow into web applications effortlessly.
You can get the HTML code embedded with the chat by clicking the Code button at the Sidebar after building a flow.
Clicking the Chat Widget HTML tab, you'll get the code to be inserted. Read below to learn how to use it with HTML, React and Angular.
Embed the chat widget into HTML
To embed the chat widget into any HTML page, insert the code snippet. inside a <body>
tag.
_10<script src="https://cdn.jsdelivr.net/gh/logspace-ai/langflow-embedded-chat@v1.0.6/dist/build/static/js/bundle.min.js""></script>_10_10 <langflow-chat_10 window_title="Basic Prompting"_10 flow_id="801abb1e-19b9-4278-9632-179b6d84f126"_10 host_url="http://localhost:7860"_10_10 ></langflow-chat>
Embed the chat widget with React
To embed the Chat Widget using React, insert this <script>
tag into the React index.html file, inside the <body>
tag:
_10<script src="https://cdn.jsdelivr.net/gh/langflow-ai/langflow-embedded-chat@main/dist/build/static/js/bundle.min.js"></script>
Declare your Web Component and encapsulate it in a React component.
_20declare global {_20 namespace JSX {_20 interface IntrinsicElements {_20 "langflow-chat": any;_20 }_20 }_20}_20_20export default function ChatWidget({ className }) {_20 return (_20 <div className={className}>_20 <langflow-chat_20 chat_inputs='{"your_key":"value"}'_20 chat_input_field="your_chat_key"_20 flow_id="your_flow_id"_20 host_url="langflow_url"_20 ></langflow-chat>_20 </div>_20 );_20}
Place the component anywhere in your code to display the Chat Widget.
Embed the chat widget with Angular
To use the chat widget in Angular, first add this <script>
tag into the Angular index.html file, inside the <body>
tag.
_10<script src="https://cdn.jsdelivr.net/gh/langflow-ai/langflow-embedded-chat@main/dist/build/static/js/bundle.min.js"></script>
When you use a custom web component in an Angular template, the Angular compiler might show a warning when it doesn't recognize the custom elements by default. To suppress this warning, add CUSTOM_ELEMENTS_SCHEMA
to the module's @NgModule.schemas
.
- Open the module file (it typically ends with .module.ts) where you'd add the
langflow-chat
web component. - Import
CUSTOM_ELEMENTS_SCHEMA
at the top of the file:
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
- Add
CUSTOM_ELEMENTS_SCHEMA
to the 'schemas' array inside the '@NgModule' decorator:
_12@NgModule({_12 declarations: [_12 // ... Other components and directives ..._12 ],_12 imports: [_12 // ... Other imported modules ..._12 ],_12 schemas: [_12 CUSTOM_ELEMENTS_SCHEMA // Add the CUSTOM_ELEMENTS_SCHEMA here_12 ]_12})_12export class YourModule { }
In your Angular project, find the component belonging to the module where CUSTOM_ELEMENTS_SCHEMA
was added. Inside the template, add the langflow-chat
tag to include the Chat Widget in your component's view:
_10<langflow-chat chat_inputs='{"your_key":"value"}' chat_input_field="your_chat_key" flow_id="your_flow_id" host_url="langflow_url"></langflow-chat>
CUSTOM_ELEMENTS_SCHEMA
is a built-in schema that allows Angular to recognize custom elements. Adding CUSTOM_ELEMENTS_SCHEMA
tells Angular to allow custom elements in your templates, and it will suppress the warning related to unknown elements like langflow-chat
. Notice that you can only use the Chat Widget in components that are part of the module where you added CUSTOM_ELEMENTS_SCHEMA
.
Chat widget configuration
Use the widget API to customize your Chat Widget:
Props with the type JSON need to be passed as stringified JSONs, with the format {"key":"value"}.
Prop | Type | Required | Description |
---|---|---|---|
bot_message_style | JSON | No | Applies custom formatting to bot messages. |
chat_input_field | String | Yes | Defines the type of the input field for chat messages. |
chat_inputs | JSON | Yes | Determines the chat input elements and their respective values. |
chat_output_key | String | No | Specifies which output to display if multiple outputs are available. |
chat_position | String | No | Positions the chat window on the screen (options include: top-left, top-center, top-right, center-left, center-right, bottom-right, bottom-center, bottom-left). |
chat_trigger_style | JSON | No | Styles the chat trigger button. |
chat_window_style | JSON | No | Customizes the overall appearance of the chat window. |
error_message_style | JSON | No | Sets the format for error messages within the chat window. |
flow_id | String | Yes | Identifies the flow that the component is associated with. |
height | Number | No | Sets the height of the chat window in pixels. |
host_url | String | Yes | Specifies the URL of the host for chat component communication. |
input_container_style | JSON | No | Applies styling to the container where chat messages are entered. |
input_style | JSON | No | Sets the style for the chat input field. |
online | Boolean | No | Toggles the online status of the chat component. |
online_message | String | No | Sets a custom message to display when the chat component is online. |
placeholder | String | No | Sets the placeholder text for the chat input field. |
placeholder_sending | String | No | Sets the placeholder text to display while a message is being sent. |
send_button_style | JSON | No | Sets the style for the send button in the chat window. |
send_icon_style | JSON | No | Sets the style for the send icon in the chat window. |
tweaks | JSON | No | Applies additional custom adjustments for the associated flow. |
user_message_style | JSON | No | Determines the formatting for user messages in the chat window. |
width | Number | No | Sets the width of the chat window in pixels. |
window_title | String | No | Sets the title displayed in the chat window's header or title bar. |