Skip to main content
Version: 1.10.x (Next)

OpenAI Responses API

Langflow includes an endpoint that is compatible with the OpenAI Responses API. It is available at POST /api/v1/responses.

This endpoint allows you to use existing OpenAI client libraries with minimal code changes. You only need to replace the model name, such as gpt-4, with your flow_id. You can find Flow IDs in the code snippets on the API access pane or in a flow's URL.

Prerequisites

To be compatible with Langflow's OpenAI Responses API endpoint, your flow and request must adhere to the following requirements:

  • Chat Input: Your flow must contain a Chat Input component. Flows without this component return an error when passed to this endpoint. The component types ChatInput and Chat Input are recognized as chat inputs.
  • Tools: The tools parameter isn't supported, and returns an error if provided.
  • Model Names: In your request, the model field must contain a valid flow ID or endpoint name.
  • Authentication: All requests require an API key passed in the x-api-key header. For more information, see API keys and authentication.

Additional configuration for OpenAI client libraries

This endpoint is compatible with OpenAI's API, but requires special configuration when using OpenAI client libraries. Langflow uses x-api-key headers for authentication, while OpenAI uses Authorization: Bearer headers. When sending requests to Langflow with OpenAI client libraries, you must configure custom headers and include an api_key configuration. The api_key parameter can have any value, such as "dummy-api-key" in the client examples, as the actual authentication is handled through the default_headers configuration.

In the following examples, replace the values for LANGFLOW_SERVER_URL, LANGFLOW_API_KEY, and FLOW_ID with values from your deployment.

1import os 2 3from openai import OpenAI 4 5base = (os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "")).rstrip("/") 6api_key = os.environ.get("LANGFLOW_API_KEY", "") 7flow_id = os.environ.get("FLOW_ID", "") 8 9client = OpenAI( 10 base_url=f"{base}/api/v1/", 11 default_headers={"x-api-key": api_key}, 12 api_key="dummy-api-key", # Required by OpenAI SDK but not used by Langflow 13) 14 15try: 16 response = client.responses.create( 17 model=flow_id, 18 input="There is an event that happens on the second wednesday of every month. What are the event dates in 2026?", 19 ) 20except Exception as exc: 21 # Empty bootstrap flows return an error body; use a flow with ChatInput + ChatOutput in the UI. 22 print(exc) 23else: 24 try: 25 print(response.output_text) 26 except Exception: 27 print(response) 28
Response

_14
Here are the event dates for the second Wednesday of each month in 2026:
_14
- January 14, 2026
_14
- February 11, 2026
_14
- March 11, 2026
_14
- April 8, 2026
_14
- May 13, 2026
_14
- June 10, 2026
_14
- July 8, 2026
_14
- August 12, 2026
_14
- September 9, 2026
_14
- October 14, 2026
_14
- November 11, 2026
_14
- December 9, 2026
_14
If you need these in a different format or want a downloadable calendar, let me know!

Example request

1import os 2 3import requests 4 5url = f"{os.getenv('LANGFLOW_SERVER_URL', '')}/api/v1/responses" 6 7headers = { 8 "x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}", 9 "Content-Type": "application/json", 10} 11 12payload = {"model": "$YOUR_FLOW_ID", "input": "Hello, how are you?", "stream": False} 13 14response = requests.request("POST", url, headers=headers, json=payload) 15response.raise_for_status() 16 17print(response.text) 18

Headers

HeaderRequiredDescriptionExample
x-api-keyYesYour Langflow API key for authentication"sk-..."
Content-TypeYesSpecifies the JSON format"application/json"
X-LANGFLOW-GLOBAL-VAR-*NoGlobal variables for the flow"X-LANGFLOW-GLOBAL-VAR-API_KEY: sk-..." For more, see Pass global variables to your flows in headers.

Request body

FieldTypeRequiredDefaultDescription
modelstringYes-The flow ID or endpoint name to execute.
inputstringYes-The input text to process.
streambooleanNofalseWhether to stream the response.
backgroundbooleanNofalseWhether to process in background.
toolslist[Any]NonullTools are not supported yet.
previous_response_idstringNonullID of previous response to continue conversation. For more, see Continue conversations with response and session IDs.
includelist[string]NonullAdditional response data to include, such as ['tool_call.results']. For more, see Retrieve tool call results.

Example response


_35
{
_35
"id": "e5e8ef8a-7efd-4090-a110-6aca082bceb7",
_35
"object": "response",
_35
"created_at": 1756837941,
_35
"status": "completed",
_35
"model": "ced2ec91-f325-4bf0-8754-f3198c2b1563",
_35
"output": [
_35
{
_35
"type": "message",
_35
"id": "msg_e5e8ef8a-7efd-4090-a110-6aca082bceb7",
_35
"status": "completed",
_35
"role": "assistant",
_35
"content": [
_35
{
_35
"type": "output_text",
_35
"text": "Hello! I'm here and ready to help. How can I assist you today?",
_35
"annotations": []
_35
}
_35
]
_35
}
_35
],
_35
"parallel_tool_calls": true,
_35
"previous_response_id": null,
_35
"reasoning": {"effort": null, "summary": null},
_35
"store": true,
_35
"temperature": 1.0,
_35
"text": {"format": {"type": "text"}},
_35
"tool_choice": "auto",
_35
"tools": [],
_35
"top_p": 1.0,
_35
"truncation": "disabled",
_35
"usage": null,
_35
"user": null,
_35
"metadata": {}
_35
}

Response body

The response contains fields that Langflow sets dynamically and fields that use OpenAI-compatible defaults.

The OpenAI-compatible default values shown above are currently fixed and cannot be modified via the request. They are included to maintain API compatibility and provide a consistent response format.

For your requests, you will only be setting the dynamic fields. The default values are documented here for completeness and to show the full response structure.

Fields set dynamically by Langflow:

FieldTypeDescription
idstringUnique response identifier.
created_atintUnix timestamp of response creation.
modelstringThe flow ID that was executed.
outputlist[dict]Array of output items (messages, tool calls, etc.).
previous_response_idstringID of previous response if continuing conversation.
usagedictToken usage statistics if the usage field is available. Contains prompt_tokens, completion_tokens, and total_tokens.
Fields with OpenAI-compatible default values
FieldTypeDefault ValueDescription
objectstring"response"Always "response".
statusstring"completed"Response status: "completed", "in_progress", or "failed".
errordictnullError details (if any).
incomplete_detailsdictnullIncomplete response details (if any).
instructionsstringnullResponse instructions (if any).
max_output_tokensintnullMaximum output tokens (if any).
parallel_tool_callsbooleantrueWhether parallel tool calls are enabled.
reasoningdict{"effort": null, "summary": null}Reasoning information with effort and summary.
storebooleantrueWhether response is stored.
temperaturefloat1.0Temperature setting.
textdict{"format": {"type": "text"}}Text format configuration.
tool_choicestring"auto"Tool choice setting.
toolslist[dict][]Available tools.
top_pfloat1.0Top-p setting.
truncationstring"disabled"Truncation setting.
usagedictnullToken usage statistics. Set dynamically when available from flow components, otherwise null. See Token usage tracking.
userstringnullUser identifier (if any).
metadatadict{}Additional metadata.

Example streaming request

When you set "stream": true with your request, the API returns a stream where each chunk contains a small piece of the response as it's generated. This provides a real-time experience where users can see the AI's output appear word by word, similar to ChatGPT's typing effect.

1import os 2 3import requests 4 5url = f"{os.getenv('LANGFLOW_SERVER_URL', '')}/api/v1/responses" 6 7headers = { 8 "x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}", 9 "Content-Type": "application/json", 10} 11 12payload = {"model": "$FLOW_ID", "input": "Tell me a story about a robot", "stream": True} 13 14response = requests.request("POST", url, headers=headers, json=payload) 15response.raise_for_status() 16 17print(response.text) 18
Result
1{ 2 "id": "f7fcea36-f128-41c4-9ac1-e683137375d5", 3 "object": "response.chunk", 4 "created": 1756838094, 5 "model": "ced2ec91-f325-4bf0-8754-f3198c2b1563", 6 "delta": { 7 "content": "Once" 8 }, 9 "status": null 10} 11

Streaming response body

FieldTypeDescription
idstringUnique response identifier.
objectstringAlways "response.chunk".
createdintUnix timestamp of chunk creation.
modelstringThe flow ID that was executed.
deltadictThe new content chunk.
statusstringResponse status: "completed", "in_progress", or "failed" (optional).

The stream continues until a final chunk with "status": "completed" indicates the response is finished.

Final completion chunk

_10
{
_10
"id": "f7fcea36-f128-41c4-9ac1-e683137375d5",
_10
"object": "response.chunk",
_10
"created": 1756838094,
_10
"model": "ced2ec91-f325-4bf0-8754-f3198c2b1563",
_10
"delta": {},
_10
"status": "completed"
_10
}

Continue conversations with response and session IDs

Conversation continuity allows you to maintain context across multiple API calls, enabling multi-turn conversations with your flows. This is essential for building chat applications where users can have ongoing conversations.

When you make a request, the API returns a response with an id field. You can use this id as the previous_response_id in your next request to continue the conversation from where it left off.

First Message:

1import os 2 3import requests 4 5base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "") 6flow_id = os.environ.get("FLOW_ID", "") 7api_key = os.environ.get("LANGFLOW_API_KEY", "") 8 9url = f"{base}/api/v1/responses" 10 11headers = { 12 "x-api-key": api_key, 13 "Content-Type": "application/json", 14} 15 16payload = { 17 "model": flow_id, 18 "input": "Hello, my name is Alice", 19 "stream": False, 20} 21 22response = requests.post(url, headers=headers, json=payload, timeout=120) 23response.raise_for_status() 24 25print(response.text) 26
Result
1{ 2 "id": "c45f4ac8-772b-4675-8551-c560b1afd590", 3 "object": "response", 4 "created_at": 1756839042, 5 "status": "completed", 6 "model": "ced2ec91-f325-4bf0-8754-f3198c2b1563", 7 "output": [ 8 { 9 "type": "message", 10 "id": "msg_c45f4ac8-772b-4675-8551-c560b1afd590", 11 "status": "completed", 12 "role": "assistant", 13 "content": [ 14 { 15 "type": "output_text", 16 "text": "Hello, Alice! How can I assist you today?", 17 "annotations": [] 18 } 19 ] 20 } 21 ], 22 "previous_response_id": null 23} 24

Follow-up message:

1# Continuation requests use the same endpoint; add `previous_response_id` from a prior 2# response's `id` field. The bootstrap flow is empty; use a Playground flow with ChatInput + 3# ChatOutput for a full run. Same first message as continue-conversations-with-response-and-session-ids.py. 4 5import os 6 7import requests 8 9base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "") 10flow_id = os.environ.get("FLOW_ID", "") 11api_key = os.environ.get("LANGFLOW_API_KEY", "") 12 13url = f"{base}/api/v1/responses" 14 15headers = { 16 "x-api-key": api_key, 17 "Content-Type": "application/json", 18} 19 20payload = { 21 "model": flow_id, 22 "input": "Hello, my name is Alice", 23 "stream": False, 24} 25 26response = requests.post(url, headers=headers, json=payload, timeout=120) 27response.raise_for_status() 28 29print(response.text) 30
Result
1{ 2 "id": "c45f4ac8-772b-4675-8551-c560b1afd590", 3 "object": "response", 4 "created_at": 1756839043, 5 "status": "completed", 6 "model": "ced2ec91-f325-4bf0-8754-f3198c2b1563", 7 "output": [ 8 { 9 "type": "message", 10 "id": "msg_c45f4ac8-772b-4675-8551-c560b1afd590", 11 "status": "completed", 12 "role": "assistant", 13 "content": [ 14 { 15 "type": "output_text", 16 "text": "Your name is Alice. How can I help you today?", 17 "annotations": [] 18 } 19 ] 20 } 21 ], 22 "previous_response_id": "c45f4ac8-772b-4675-8551-c560b1afd590" 23} 24

Optionally, you can use your own session ID values for the previous_response_id:

1# Same pattern as continue-conversations-with-response-and-session-ids-2.py; you can pass 2# `previous_response_id` from the prior turn (or a session id your app stores). 3 4import os 5 6import requests 7 8base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "") 9flow_id = os.environ.get("FLOW_ID", "") 10api_key = os.environ.get("LANGFLOW_API_KEY", "") 11 12url = f"{base}/api/v1/responses" 13 14headers = { 15 "x-api-key": api_key, 16 "Content-Type": "application/json", 17} 18 19payload = { 20 "model": flow_id, 21 "input": "Hello, my name is Alice", 22 "stream": False, 23} 24 25response = requests.post(url, headers=headers, json=payload, timeout=120) 26response.raise_for_status() 27 28print(response.text) 29
Result

This example uses the same flow as the other previous_response_id examples, but the LLM had not yet been introduced to Alice in the specified session:


_23
{
_23
"id": "session-alice-1756839048",
_23
"object": "response",
_23
"created_at": 1756839048,
_23
"status": "completed",
_23
"model": "ced2ec91-f325-4bf0-8754-f3198c2b1563",
_23
"output": [
_23
{
_23
"type": "message",
_23
"id": "msg_session-alice-1756839048",
_23
"status": "completed",
_23
"role": "assistant",
_23
"content": [
_23
{
_23
"type": "output_text",
_23
"text": "I don't have access to your name unless you tell me. If you'd like, you can share your name, and I'll remember it for this conversation!",
_23
"annotations": []
_23
}
_23
]
_23
}
_23
],
_23
"previous_response_id": "session-alice-1756839048"
_23
}

Retrieve tool call results

When you send a request to the /api/v1/responses endpoint to run a flow that includes tools or function calls, you can retrieve the raw tool execution details by adding "include": ["tool_call.results"] to the request payload.

Without the include parameter, tool calls return basic function call information, but not the raw tool results. For example:


_10
{
_10
"id": "fc_1",
_10
"type": "function_call",
_10
"status": "completed",
_10
"name": "evaluate_expression",
_10
"arguments": "{\"expression\": \"15*23\"}"
_10
},

To get the raw results of each tool execution, add include: ["tool_call.results"] to the request payload:

1import os 2 3import requests 4 5base = os.environ.get("LANGFLOW_URL") or os.environ.get("LANGFLOW_SERVER_URL", "") 6flow_id = os.environ.get("FLOW_ID", "") 7api_key = os.environ.get("LANGFLOW_API_KEY", "") 8 9url = f"{base}/api/v1/responses" 10 11headers = { 12 "Content-Type": "application/json", 13 "x-api-key": api_key, 14} 15 16payload = { 17 "model": flow_id, 18 "input": "Calculate 23 * 15 and show me the result", 19 "stream": False, 20 "include": ["tool_call.results"], 21} 22 23response = requests.post(url, headers=headers, json=payload, timeout=120) 24response.raise_for_status() 25 26print(response.text) 27

The response now includes the tool call's results. For example:


_10
{
_10
"id": "evaluate_expression_1",
_10
"type": "tool_call",
_10
"tool_name": "evaluate_expression",
_10
"queries": ["15*23"],
_10
"results": {"result": "345"}
_10
}

Result
1{ 2 "id": "a6e5511e-71f8-457a-88d2-7d8c6ea34e36", 3 "object": "response", 4 "created_at": 1756835379, 5 "status": "completed", 6 "error": null, 7 "incomplete_details": null, 8 "instructions": null, 9 "max_output_tokens": null, 10 "model": "ced2ec91-f325-4bf0-8754-f3198c2b1563", 11 "output": [ 12 { 13 "id": "evaluate_expression_1", 14 "queries": [ 15 "15*23" 16 ], 17 "status": "completed", 18 "tool_name": "evaluate_expression", 19 "type": "tool_call", 20 "results": { 21 "result": "345" 22 } 23 }, 24 { 25 "type": "message", 26 "id": "msg_a6e5511e-71f8-457a-88d2-7d8c6ea34e36", 27 "status": "completed", 28 "role": "assistant", 29 "content": [ 30 { 31 "type": "output_text", 32 "text": "The result of 23 * 15 is 345.", 33 "annotations": [] 34 } 35 ] 36 } 37 ], 38 "parallel_tool_calls": true, 39 "previous_response_id": null, 40 "reasoning": { 41 "effort": null, 42 "summary": null 43 }, 44 "store": true, 45 "temperature": 1.0, 46 "text": { 47 "format": { 48 "type": "text" 49 } 50 }, 51 "tool_choice": "auto", 52 "tools": [], 53 "top_p": 1.0, 54 "truncation": "disabled", 55 "usage": null, 56 "user": null, 57 "metadata": {} 58}

Variables passed with X-LANGFLOW-GLOBAL-VAR-{VARIABLE_NAME} are always available to your flow, regardless of whether they exist in the database.

If your flow components reference variables that aren't provided in headers or your Langflow database, the flow fails by default.

To avoid this, you can set the FALLBACK_TO_ENV_VARS environment variable is true, which allows the flow to use values from the .env file if they aren't otherwise specified.

In the above example, OPENAI_API_KEY will fall back to the database variable if not provided in the header. USER_ID and ENVIRONMENT will fall back to environment variables if FALLBACK_TO_ENV_VARS is enabled. Otherwise, the flow fails.

Token usage tracking

The OpenAI Responses API endpoint tracks token usage when your flow uses language model components that provide token usage information. The usage field in the response contains statistics about the number of tokens used for the request and response.

Token usage is automatically extracted from the flow execution results when the usage field is available. The usage field follows OpenAI's format with prompt_tokens, completion_tokens, and total_tokens fields. If token usage information is not available from the flow components, the usage field is null.

The usage field is always present in the response, either with token counts or as null. The conditional checks shown in the examples below are optional defensive programming to handle cases where usage might not be available.

1import os 2 3import requests 4 5url = f"{os.getenv('LANGFLOW_SERVER_URL', '')}/api/v1/responses" 6 7headers = { 8 "x-api-key": f"{os.getenv('LANGFLOW_API_KEY', '')}", 9 "Content-Type": "application/json", 10} 11 12payload = {"model": "FLOW_ID", "input": "Explain quantum computing in simple terms", "stream": False} 13 14response = requests.request("POST", url, headers=headers, json=payload) 15response.raise_for_status() 16 17print(response.text) 18
Search