mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-24 00:03:32 +08:00
* docs: migrate code blocks from CodeSnippet to native Prism Replace the custom CodeSnippet component (@code-hike/lighter) with Docusaurus's native @theme/CodeBlock across all MDX files (current and versioned docs). Add bash to additionalLanguages and swizzle prism-include-languages.js to add custom token highlighting for shell commands and flags. Remove @code-hike/mdx dependency. * docs: improve inline code styling Darken inline code background, increase horizontal padding to 0.4em, fix vertical alignment, and remove border in light mode. * docs: address PR review — fix code slice regression and CSS/regex polish - Inline RecursiveCharacterTextSplitter inputs and methods as literal code blocks in concepts-components.mdx (current + 1.8.0 + 1.9.0), restoring the focused slices lost when migrating from CodeSnippet - Scope bash-plain Prism regex to unambiguous CLI subcommands only, removing generic bash builtins (run, add, get, set, start, stop, etc.) - Merge duplicate .theme-code-block CSS rules into a single declaration * fix(docs): prevent horizontal scroll on API docs pages The Redoc two-column layout (sidebar 300px + api-content 1300px) totals 1600px, expanding .main-wrapper beyond narrower viewports because it has overflow:visible. Clips at .main-wrapper using the html.plugin-redoc class that Docusaurus adds on API pages only. * fix(docs): API docs sidebar and layout fixes - Disable Redoc built-in search (disableSearch: true) - Pin sidebar top to navbar height (top: 60px) so it never hides behind navbar - Remove hardcoded #111 background from dark mode sidebar * fix(docs): render markdown correctly in API docs descriptions The _clean_descriptions function was converting newlines to <br> tags, mixing HTML with Markdown. CommonMark stops parsing Markdown headings (###) inside HTML blocks, causing them to appear as literal text in Redoc. Replace the <br> conversion with a simple strip() so descriptions remain pure Markdown and Redoc renders headings, lists, and code blocks correctly. * feat(docs): align API docs colors with Langflow brand - Set primaryColor to #F471B5 (Langflow pink) - Add HTTP method badge colors matching Langflow palette - Set schema.linesColor and requireLabelColor to brand pink - Set inline code color to pink, headers to #e3e3e3 - Set sidebar background to #18181b (matches frontend dark bg) - Set rightPanel background to #0d0d0f, codeBlock to #161618 - Refactor: move color config from CSS to theme.theme where safe - Remove dead search input CSS (search disabled via disableSearch:true) - Consolidate duplicate .menu-content rules * wip(docs): API docs styling — colors, components, light/dark themes * fix(docs): fix Response samples h3 title padding and refactor HTTP method button CSS * feat(docs): add sidebar dark background, active item styles, and right panel color adjustments * fix(docs): add sidebar borders and remove operation divider border * fix(docs): fix expanded response background and align dark/light theme colors * refactor(docs): standardize selectors, comments and remove duplicate rules in redocusaurus.css * refactor(docs): apply PR review — CSS custom properties, version pin, dom version comments, fix overflow * fix(docs): fix Redocly badge visibility covered by sidebar background * fix(docs): extend sidebar border-right to Redocly badge area * refactor(docs): replace hardcoded #ffffff label color with --redoc-text-label variable * fix(docs): lighten inline code background in API docs dark theme Redoc's default typography.code.backgroundColor (rgba(38, 50, 56, 0.05)) is nearly invisible over the dark background. Override it with rgba(255, 255, 255, 0.05) in dark theme only, excluding pre > code so code sample blocks stay unaffected. * feat(docs): align docs primary pink with API spec brand color Use #f471b5 (API spec primaryColor) as --ifm-color-primary in dark theme and #e44fa0 (slightly darkened for contrast on white) in light theme. Remove dark-theme pink overrides in sidebar.css (#ff6ad0 CTA and hsla(329, 55%, 68%) active TOC link) — they compensated for the old muted pink and are redundant now that the primary itself is bright. * feat(docs): lighten dark theme text colors for better readability Bump body text (#a8a8b0 -> #bcbcc4), headings (#cdcdd4 -> #dcdce2) and sidebar menu (#8a8a92 -> #9c9ca4) one step brighter. * chore(docs): add IBM Equal Access accessibility-checker setup Add accessibility-checker as devDependency with aceconfig.js (policy IBM_Accessibility, JSON reports in docs/a11y-results/, gitignored). Scan with: npx achecker <url> against a built docs site. * fix(docs): WCAG AA contrast and ARIA fixes across docs and API reference Validated with IBM Equal Access scans (light theme): home, quickstart and component pages at 0 violations; /api from 3382 down to 167 (all remaining are Redoc-internal DOM: schema table headers, svg/select labels). Docs site: - Light primary pink #d11074 — passes 4.5:1 on white and inline-code bg - Light Prism palette darkened per-token to pass 4.5:1 on #f9f9fd - TabItem swizzled to give tabpanels an accessible name (aria-label) - codeBlockA11y client module: scrollable code blocks get role=region + unique label; non-scrollable ones lose the needless tabindex API reference (Redocusaurus): - redocA11y client module: role=main on api-content, role=navigation on sidebar — fixes 1924 aria_content_in_landmark violations - HTTP method badges and response chips darkened to pass with white text - Light-theme overrides: accessible pink #cd1072 for links, required markers, constraint chips, schema tree lines; darker grays for utility buttons and type labels (incl. 0.7-opacity wrapper fix) - Sidebar active/hover items use regular text color, method badges keep their own colors; expandable property names match non-expandable ones * fix(docs): WCAG AA contrast fixes for dark theme Validated with IBM Equal Access scans in dark mode (temporary colorMode.defaultMode flip during scanning): home, quickstart and component pages at 0 violations; /api matches light at 167 remaining (all Redoc-internal DOM: table headers, svg/select labels). - Code block comments/line numbers #4a5060 -> #798197 (4.56:1 on #18181a) - Redoc dark sample tokens: boolean/null #e95c59, number #5392b8 - Status-code tabs: lift docusaurus-theme-redoc's #303846 !important selected-tab rule with a higher-specificity override - oneOf variant buttons: dark text in both themes (their white/pink backgrounds are theme-independent) - redocA11y client module: patch response chip colors (success green / error red) to dark-accessible variants when data-theme=dark — a single Redoc theme color cannot pass on both light and dark derived backgrounds, and status is only distinguishable by computed color * fix(docs): resolve remaining Redoc-internal accessibility violations Extend the redocA11y client module with semantic patches for Redoc DOM the theme cannot reach (validated: 0 IBM Equal Access violations on all scanned pages in both light and dark themes): - Decorative svg chevrons/arrows: aria-hidden=true (svg_graphics_labelled) - Content-type dropdowns: aria-label (input_label_exists) - Schema field tables (2-col name|description layout, no <th> anywhere): role=presentation — content reads in DOM order; role=rowheader on <td> is invalid ARIA inside a native table (table_headers_exists/related) - Semantic patches run on the next animation frame after DOM changes so Redoc's lazy-rendered operations are covered immediately; the heavier color patch stays debounced * ci(docs): gate docs accessibility with IBM Equal Access scans Add test-docs-accessibility job to docs_test.yml (rides the existing docs/** path filter from ci.yml): build + scan 4 representative pages (home, quickstart, component page, /api) in light theme, then flip colorMode.defaultMode to dark, rebuild and scan again. - scripts/a11y-ci.sh: serves the build and runs npx achecker per page with one retry to absorb Redoc lazy-render timing flakes; any real violation fails the job (failLevels: violation) - aceconfig.js: pin ruleArchive to 19May2026 so IBM rule updates don't break CI without a deliberate bump * ci(docs): fix Chrome sandbox launch on Ubuntu 24.04 runners Ubuntu 24.04 restricts unprivileged user namespaces via AppArmor, which prevents puppeteer's Chrome (used by the IBM checker) from starting its sandbox. Re-enable them with the documented sysctl workaround instead of weakening the browser with --no-sandbox. * fix(docs): align response status code with description text Redoc sets vertical-align: top and a smaller line-height on the status code <strong> inside response buttons, leaving "200" visually higher than "Successful Response". Align both to the shared text baseline. * refactor(docs): apply PR review feedback - redocA11y: match only real Redoc routes (/api, /api/workflow) — a bare startsWith("/api") also matched docs pages like /api-request and leaked one body MutationObserver per navigation - codeBlockA11y: also observe the hidden attribute — Docusaurus tabs toggle panels via hidden (no childList mutation), so scrollable blocks inside an initially hidden tab were never re-evaluated for tabindex - Extract Prism themes to src/prismThemes.js (docusaurus.config.js was past the 600-line red flag) - concepts-components.mdx (current + 1.9.0 + 1.8.0): comment pointing hardcoded snippets to recursive_character.py to mitigate drift Validated: clean build + IBM Equal Access scans 4/4 passing. * replace-openapi-file-with-1.10 * migrate-prism-changes-to-1.10-version * a11y-script-dont-block --------- Co-authored-by: Mendon Kissling <59585235+mendonk@users.noreply.github.com>
530 lines
23 KiB
Plaintext
530 lines
23 KiB
Plaintext
---
|
|
title: OpenAI Responses API
|
|
slug: /api-openai-responses
|
|
---
|
|
import CodeBlock from '@theme/CodeBlock';
|
|
import exampleApiOpenaiResponsesExampleRequest from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-openai-responses/example-request.sh';
|
|
import exampleApiOpenaiResponsesExampleStreamingRequest from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-openai-responses/example-streaming-request.sh';
|
|
import resultApiOpenaiResponsesResultExampleStreamingRequest from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-openai-responses/result-example-streaming-request.json';
|
|
import exampleApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-openai-responses/continue-conversations-with-response-and-session-ids.sh';
|
|
import resultApiOpenaiResponsesResultContinueConversationsWithResponseAndSessionIds from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-openai-responses/result-continue-conversations-with-response-and-session-ids.json';
|
|
import exampleApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds2 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-openai-responses/continue-conversations-with-response-and-session-ids-2.sh';
|
|
import resultApiOpenaiResponsesResultContinueConversationsWithResponseAndSessionIds2 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-openai-responses/result-continue-conversations-with-response-and-session-ids-2.json';
|
|
import exampleApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds3 from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-openai-responses/continue-conversations-with-response-and-session-ids-3.sh';
|
|
import exampleApiOpenaiResponsesRetrieveToolCallResults from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-openai-responses/retrieve-tool-call-results.sh';
|
|
import resultApiOpenaiResponsesResultRetrieveToolCallResults from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-openai-responses/result-retrieve-tool-call-results.json';
|
|
import exampleApiOpenaiResponsesPassGlobalVariablesToYourFlowsInHeaders from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-openai-responses/pass-global-variables-to-your-flows-in-headers.sh';
|
|
import exampleApiOpenaiResponsesTokenUsageTracking from '!!raw-loader!@site/docs/API-Reference/curl-examples/api-openai-responses/token-usage-tracking.sh';
|
|
import examplePythonApiOpenaiResponsesAdditionalConfigurationForOpenaiClientLibraries from '!!raw-loader!@site/docs/API-Reference/python-examples/api-openai-responses/additional-configuration-for-openai-client-libraries.py';
|
|
import exampleJavascriptApiOpenaiResponsesAdditionalConfigurationForOpenaiClientLibraries from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-openai-responses/additional-configuration-for-openai-client-libraries.ts';
|
|
import examplePythonApiOpenaiResponsesTokenUsageTracking from '!!raw-loader!@site/docs/API-Reference/python-examples/api-openai-responses/token-usage-tracking.py';
|
|
import examplePythonApiOpenaiResponsesExampleRequest from '!!raw-loader!@site/docs/API-Reference/python-examples/api-openai-responses/example-request.py';
|
|
import exampleJavascriptApiOpenaiResponsesExampleRequest from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-openai-responses/example-request.js';
|
|
import examplePythonApiOpenaiResponsesExampleStreamingRequest from '!!raw-loader!@site/docs/API-Reference/python-examples/api-openai-responses/example-streaming-request.py';
|
|
import exampleJavascriptApiOpenaiResponsesExampleStreamingRequest from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-openai-responses/example-streaming-request.js';
|
|
import examplePythonApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds from '!!raw-loader!@site/docs/API-Reference/python-examples/api-openai-responses/continue-conversations-with-response-and-session-ids.py';
|
|
import exampleJavascriptApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-openai-responses/continue-conversations-with-response-and-session-ids.js';
|
|
import examplePythonApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds2 from '!!raw-loader!@site/docs/API-Reference/python-examples/api-openai-responses/continue-conversations-with-response-and-session-ids-2.py';
|
|
import exampleJavascriptApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds2 from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-openai-responses/continue-conversations-with-response-and-session-ids-2.js';
|
|
import examplePythonApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds3 from '!!raw-loader!@site/docs/API-Reference/python-examples/api-openai-responses/continue-conversations-with-response-and-session-ids-3.py';
|
|
import exampleJavascriptApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds3 from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-openai-responses/continue-conversations-with-response-and-session-ids-3.js';
|
|
import examplePythonApiOpenaiResponsesRetrieveToolCallResults from '!!raw-loader!@site/docs/API-Reference/python-examples/api-openai-responses/retrieve-tool-call-results.py';
|
|
import exampleJavascriptApiOpenaiResponsesRetrieveToolCallResults from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-openai-responses/retrieve-tool-call-results.js';
|
|
import examplePythonApiOpenaiResponsesPassGlobalVariablesToYourFlowsInHeaders from '!!raw-loader!@site/docs/API-Reference/python-examples/api-openai-responses/pass-global-variables-to-your-flows-in-headers.py';
|
|
import exampleJavascriptApiOpenaiResponsesPassGlobalVariablesToYourFlowsInHeaders from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-openai-responses/pass-global-variables-to-your-flows-in-headers.js';
|
|
import exampleJavascriptApiOpenaiResponsesTokenUsageTracking from '!!raw-loader!@site/docs/API-Reference/javascript-examples/api-openai-responses/token-usage-tracking.js';
|
|
|
|
|
|
|
|
|
|
import Tabs from '@theme/Tabs';
|
|
import TabItem from '@theme/TabItem';
|
|
|
|
Langflow includes an endpoint that is compatible with the [OpenAI Responses API](https://platform.openai.com/docs/api-reference/responses).
|
|
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](/concepts-publish#api-access) 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](/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.
|
|
<Tabs groupId="client">
|
|
<TabItem value="Python" label="OpenAI Python Client" default>
|
|
|
|
<CodeBlock language="python">{examplePythonApiOpenaiResponsesAdditionalConfigurationForOpenaiClientLibraries}</CodeBlock>
|
|
|
|
</TabItem>
|
|
<TabItem value="JavaScript" label="OpenAI TypeScript Client">
|
|
|
|
<CodeBlock language="javascript">{exampleJavascriptApiOpenaiResponsesAdditionalConfigurationForOpenaiClientLibraries}</CodeBlock>
|
|
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
<details closed>
|
|
<summary>Response</summary>
|
|
```text
|
|
Here are the event dates for the second Wednesday of each month in 2026:
|
|
- January 14, 2026
|
|
- February 11, 2026
|
|
- March 11, 2026
|
|
- April 8, 2026
|
|
- May 13, 2026
|
|
- June 10, 2026
|
|
- July 8, 2026
|
|
- August 12, 2026
|
|
- September 9, 2026
|
|
- October 14, 2026
|
|
- November 11, 2026
|
|
- December 9, 2026
|
|
If you need these in a different format or want a downloadable calendar, let me know!
|
|
```
|
|
</details>
|
|
|
|
## Example request
|
|
|
|
<Tabs>
|
|
<TabItem value="Python" label="Python" default>
|
|
|
|
<CodeBlock language="python">{examplePythonApiOpenaiResponsesExampleRequest}</CodeBlock>
|
|
|
|
</TabItem>
|
|
<TabItem value="JavaScript" label="JavaScript">
|
|
|
|
<CodeBlock language="javascript">{exampleJavascriptApiOpenaiResponsesExampleRequest}</CodeBlock>
|
|
|
|
</TabItem>
|
|
<TabItem value="curl" label="curl">
|
|
|
|
<CodeBlock language="bash">{exampleApiOpenaiResponsesExampleRequest}</CodeBlock>
|
|
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
### Headers
|
|
|
|
| Header | Required | Description | Example |
|
|
|--------|----------|-------------|---------|
|
|
| `x-api-key` | Yes | Your Langflow API key for authentication | `"sk-..."` |
|
|
| `Content-Type` | Yes | Specifies the JSON format | `"application/json"` |
|
|
| `X-LANGFLOW-GLOBAL-VAR-*` | No | Global variables for the flow | `"X-LANGFLOW-GLOBAL-VAR-API_KEY: sk-..."` For more, see [Pass global variables to your flows in headers](#global-var). |
|
|
|
|
### Request body
|
|
|
|
| Field | Type | Required | Default | Description |
|
|
|-------|------|----------|---------|-------------|
|
|
| `model` | `string` | Yes | - | The flow ID or endpoint name to execute. |
|
|
| `input` | `string` | Yes | - | The input text to process. |
|
|
| `stream` | `boolean` | No | `false` | Whether to stream the response. |
|
|
| `background` | `boolean` | No | `false` | Whether to process in background. |
|
|
| `tools` | `list[Any]` | No | `null` | Tools are not supported yet. |
|
|
| `previous_response_id` | `string` | No | `null` | ID of previous response to continue conversation. For more, see [Continue conversations with response and session IDs](#response-id). |
|
|
| `include` | `list[string]` | No | `null` | Additional response data to include, such as `['tool_call.results']`. For more, see [Retrieve tool call results](#tool-call-results). |
|
|
|
|
## Example response
|
|
|
|
```json
|
|
{
|
|
"id": "e5e8ef8a-7efd-4090-a110-6aca082bceb7",
|
|
"object": "response",
|
|
"created_at": 1756837941,
|
|
"status": "completed",
|
|
"model": "ced2ec91-f325-4bf0-8754-f3198c2b1563",
|
|
"output": [
|
|
{
|
|
"type": "message",
|
|
"id": "msg_e5e8ef8a-7efd-4090-a110-6aca082bceb7",
|
|
"status": "completed",
|
|
"role": "assistant",
|
|
"content": [
|
|
{
|
|
"type": "output_text",
|
|
"text": "Hello! I'm here and ready to help. How can I assist you today?",
|
|
"annotations": []
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"parallel_tool_calls": true,
|
|
"previous_response_id": null,
|
|
"reasoning": {"effort": null, "summary": null},
|
|
"store": true,
|
|
"temperature": 1.0,
|
|
"text": {"format": {"type": "text"}},
|
|
"tool_choice": "auto",
|
|
"tools": [],
|
|
"top_p": 1.0,
|
|
"truncation": "disabled",
|
|
"usage": null,
|
|
"user": null,
|
|
"metadata": {}
|
|
}
|
|
```
|
|
|
|
### 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:
|
|
|
|
| Field | Type | Description |
|
|
|-------|------|-------------|
|
|
| `id` | `string` | Unique response identifier. |
|
|
| `created_at` | `int` | Unix timestamp of response creation. |
|
|
| `model` | `string` | The flow ID that was executed. |
|
|
| `output` | `list[dict]` | Array of output items (messages, tool calls, etc.). |
|
|
| `previous_response_id` | `string` | ID of previous response if continuing conversation. |
|
|
| `usage` | `dict` | Token usage statistics if the `usage` field is available. Contains `prompt_tokens`, `completion_tokens`, and `total_tokens`. |
|
|
|
|
<details>
|
|
<summary>Fields with OpenAI-compatible default values</summary>
|
|
|
|
| Field | Type | Default Value | Description |
|
|
|-------|------|---------------|-------------|
|
|
| `object` | `string` | `"response"` | Always `"response"`. |
|
|
| `status` | `string` | `"completed"` | Response status: `"completed"`, `"in_progress"`, or `"failed"`. |
|
|
| `error` | `dict` | `null` | Error details (if any). |
|
|
| `incomplete_details` | `dict` | `null` | Incomplete response details (if any). |
|
|
| `instructions` | `string` | `null` | Response instructions (if any). |
|
|
| `max_output_tokens` | `int` | `null` | Maximum output tokens (if any). |
|
|
| `parallel_tool_calls` | `boolean` | `true` | Whether parallel tool calls are enabled. |
|
|
| `reasoning` | `dict` | `{"effort": null, "summary": null}` | Reasoning information with effort and summary. |
|
|
| `store` | `boolean` | `true` | Whether response is stored. |
|
|
| `temperature` | `float` | `1.0` | Temperature setting. |
|
|
| `text` | `dict` | `{"format": {"type": "text"}}` | Text format configuration. |
|
|
| `tool_choice` | `string` | `"auto"` | Tool choice setting. |
|
|
| `tools` | `list[dict]` | `[]` | Available tools. |
|
|
| `top_p` | `float` | `1.0` | Top-p setting. |
|
|
| `truncation` | `string` | `"disabled"` | Truncation setting. |
|
|
| `usage` | `dict` | `null` | Token usage statistics. Set dynamically when available from flow components, otherwise `null`. See [Token usage tracking](#token-usage-tracking). |
|
|
| `user` | `string` | `null` | User identifier (if any). |
|
|
| `metadata` | `dict` | `{}` | Additional metadata. |
|
|
|
|
</details>
|
|
|
|
## 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.
|
|
|
|
<Tabs>
|
|
<TabItem value="Python" label="Python" default>
|
|
|
|
<CodeBlock language="python">{examplePythonApiOpenaiResponsesExampleStreamingRequest}</CodeBlock>
|
|
|
|
</TabItem>
|
|
<TabItem value="JavaScript" label="JavaScript">
|
|
|
|
<CodeBlock language="javascript">{exampleJavascriptApiOpenaiResponsesExampleStreamingRequest}</CodeBlock>
|
|
|
|
</TabItem>
|
|
<TabItem value="curl" label="curl">
|
|
|
|
<CodeBlock language="bash">{exampleApiOpenaiResponsesExampleStreamingRequest}</CodeBlock>
|
|
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
<details>
|
|
<summary>Result</summary>
|
|
|
|
<CodeBlock language="json">{resultApiOpenaiResponsesResultExampleStreamingRequest}</CodeBlock>
|
|
|
|
</details>
|
|
|
|
### Streaming response body
|
|
|
|
| Field | Type | Description |
|
|
|-------|------|-------------|
|
|
| `id` | `string` | Unique response identifier. |
|
|
| `object` | `string` | Always `"response.chunk"`. |
|
|
| `created` | `int` | Unix timestamp of chunk creation. |
|
|
| `model` | `string` | The flow ID that was executed. |
|
|
| `delta` | `dict` | The new content chunk. |
|
|
| `status` | `string` | Response status: `"completed"`, `"in_progress"`, or `"failed"` (optional). |
|
|
|
|
The stream continues until a final chunk with `"status": "completed"` indicates the response is finished.
|
|
|
|
<details>
|
|
<summary>Final completion chunk</summary>
|
|
|
|
```
|
|
{
|
|
"id": "f7fcea36-f128-41c4-9ac1-e683137375d5",
|
|
"object": "response.chunk",
|
|
"created": 1756838094,
|
|
"model": "ced2ec91-f325-4bf0-8754-f3198c2b1563",
|
|
"delta": {},
|
|
"status": "completed"
|
|
}
|
|
```
|
|
</details>
|
|
|
|
## Continue conversations with response and session IDs {#response-id}
|
|
|
|
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:
|
|
|
|
<Tabs>
|
|
<TabItem value="Python" label="Python" default>
|
|
|
|
<CodeBlock language="python">{examplePythonApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds}</CodeBlock>
|
|
|
|
</TabItem>
|
|
<TabItem value="JavaScript" label="JavaScript">
|
|
|
|
<CodeBlock language="javascript">{exampleJavascriptApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds}</CodeBlock>
|
|
|
|
</TabItem>
|
|
<TabItem value="curl" label="curl">
|
|
|
|
<CodeBlock language="bash">{exampleApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds}</CodeBlock>
|
|
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
<details>
|
|
<summary>Result</summary>
|
|
|
|
<CodeBlock language="json">{resultApiOpenaiResponsesResultContinueConversationsWithResponseAndSessionIds}</CodeBlock>
|
|
|
|
</details>
|
|
|
|
Follow-up message:
|
|
|
|
<Tabs>
|
|
<TabItem value="Python" label="Python" default>
|
|
|
|
<CodeBlock language="python">{examplePythonApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds2}</CodeBlock>
|
|
|
|
</TabItem>
|
|
<TabItem value="JavaScript" label="JavaScript">
|
|
|
|
<CodeBlock language="javascript">{exampleJavascriptApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds2}</CodeBlock>
|
|
|
|
</TabItem>
|
|
<TabItem value="curl" label="curl">
|
|
|
|
<CodeBlock language="bash">{exampleApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds2}</CodeBlock>
|
|
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
<details>
|
|
<summary>Result</summary>
|
|
|
|
<CodeBlock language="json">{resultApiOpenaiResponsesResultContinueConversationsWithResponseAndSessionIds2}</CodeBlock>
|
|
|
|
</details>
|
|
|
|
Optionally, you can use your own session ID values for the `previous_response_id`:
|
|
|
|
<Tabs>
|
|
<TabItem value="Python" label="Python" default>
|
|
|
|
<CodeBlock language="python">{examplePythonApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds3}</CodeBlock>
|
|
|
|
</TabItem>
|
|
<TabItem value="JavaScript" label="JavaScript">
|
|
|
|
<CodeBlock language="javascript">{exampleJavascriptApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds3}</CodeBlock>
|
|
|
|
</TabItem>
|
|
<TabItem value="curl" label="curl">
|
|
|
|
<CodeBlock language="bash">{exampleApiOpenaiResponsesContinueConversationsWithResponseAndSessionIds3}</CodeBlock>
|
|
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
<details>
|
|
<summary>Result</summary>
|
|
|
|
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:
|
|
|
|
```json
|
|
{
|
|
"id": "session-alice-1756839048",
|
|
"object": "response",
|
|
"created_at": 1756839048,
|
|
"status": "completed",
|
|
"model": "ced2ec91-f325-4bf0-8754-f3198c2b1563",
|
|
"output": [
|
|
{
|
|
"type": "message",
|
|
"id": "msg_session-alice-1756839048",
|
|
"status": "completed",
|
|
"role": "assistant",
|
|
"content": [
|
|
{
|
|
"type": "output_text",
|
|
"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!",
|
|
"annotations": []
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"previous_response_id": "session-alice-1756839048"
|
|
}
|
|
```
|
|
|
|
</details>
|
|
|
|
## Retrieve tool call results {#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:
|
|
|
|
```json
|
|
{
|
|
"id": "fc_1",
|
|
"type": "function_call",
|
|
"status": "completed",
|
|
"name": "evaluate_expression",
|
|
"arguments": "{\"expression\": \"15*23\"}"
|
|
},
|
|
```
|
|
|
|
To get the raw `results` of each tool execution, add `include: ["tool_call.results"]` to the request payload:
|
|
|
|
<Tabs>
|
|
<TabItem value="Python" label="Python" default>
|
|
|
|
<CodeBlock language="python">{examplePythonApiOpenaiResponsesRetrieveToolCallResults}</CodeBlock>
|
|
|
|
</TabItem>
|
|
<TabItem value="JavaScript" label="JavaScript">
|
|
|
|
<CodeBlock language="javascript">{exampleJavascriptApiOpenaiResponsesRetrieveToolCallResults}</CodeBlock>
|
|
|
|
</TabItem>
|
|
<TabItem value="curl" label="curl">
|
|
|
|
<CodeBlock language="bash">{exampleApiOpenaiResponsesRetrieveToolCallResults}</CodeBlock>
|
|
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
The response now includes the tool call's results.
|
|
For example:
|
|
|
|
```json
|
|
{
|
|
"id": "evaluate_expression_1",
|
|
"type": "tool_call",
|
|
"tool_name": "evaluate_expression",
|
|
"queries": ["15*23"],
|
|
"results": {"result": "345"}
|
|
}
|
|
```
|
|
|
|
<details>
|
|
<summary>Result</summary>
|
|
|
|
<CodeBlock language="json">{resultApiOpenaiResponsesResultRetrieveToolCallResults}</CodeBlock>
|
|
|
|
</details>
|
|
|
|
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 {#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.
|
|
|
|
<Tabs groupId="token-usage">
|
|
<TabItem value="Python" label="Python" default>
|
|
|
|
<CodeBlock language="python">{examplePythonApiOpenaiResponsesTokenUsageTracking}</CodeBlock>
|
|
|
|
</TabItem>
|
|
<TabItem value="JavaScript" label="JavaScript">
|
|
|
|
<CodeBlock language="javascript">{exampleJavascriptApiOpenaiResponsesTokenUsageTracking}</CodeBlock>
|
|
|
|
</TabItem>
|
|
<TabItem value="curl" label="curl">
|
|
|
|
<CodeBlock language="bash">{exampleApiOpenaiResponsesTokenUsageTracking}</CodeBlock>
|
|
|
|
<details>
|
|
<summary>Response with token usage</summary>
|
|
|
|
```json
|
|
{
|
|
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
|
|
"object": "response",
|
|
"created_at": 1756837941,
|
|
"status": "completed",
|
|
"model": "ced2ec91-f325-4bf0-8754-f3198c2b1563",
|
|
"output": [
|
|
{
|
|
"type": "message",
|
|
"id": "msg_a1b2c3d4-e5f6-7890-abcd-ef1234567890",
|
|
"status": "completed",
|
|
"role": "assistant",
|
|
"content": [
|
|
{
|
|
"type": "output_text",
|
|
"text": "Quantum computing is a type of computing that uses quantum mechanical phenomena...",
|
|
"annotations": []
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"usage": {
|
|
"prompt_tokens": 12,
|
|
"completion_tokens": 145,
|
|
"total_tokens": 157
|
|
},
|
|
"previous_response_id": null
|
|
}
|
|
```
|
|
|
|
</details>
|
|
|
|
</TabItem>
|
|
</Tabs>
|