{"id":28391313,"url":"https://github.com/datastax/langflow-client-ts","last_synced_at":"2025-06-25T21:31:38.154Z","repository":{"id":274468466,"uuid":"911064589","full_name":"datastax/langflow-client-ts","owner":"datastax","description":"A TypeScript client for running flows via the Langflow API","archived":false,"fork":false,"pushed_at":"2025-06-06T06:58:45.000Z","size":442,"stargazers_count":19,"open_issues_count":2,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-06-07T08:51:39.386Z","etag":null,"topics":["genai","generative-ai","langchain","langflow"],"latest_commit_sha":null,"homepage":"https://docs.datastax.com/en/langflow/api.html","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/datastax.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-02T06:52:30.000Z","updated_at":"2025-06-01T23:51:42.000Z","dependencies_parsed_at":"2025-01-27T14:37:03.325Z","dependency_job_id":"32af9666-792a-4d77-95d9-3a4d1f184816","html_url":"https://github.com/datastax/langflow-client-ts","commit_stats":null,"previous_names":["datastax/langflow-client-ts"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/datastax/langflow-client-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datastax%2Flangflow-client-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datastax%2Flangflow-client-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datastax%2Flangflow-client-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datastax%2Flangflow-client-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/datastax","download_url":"https://codeload.github.com/datastax/langflow-client-ts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datastax%2Flangflow-client-ts/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261956040,"owners_count":23236003,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["genai","generative-ai","langchain","langflow"],"created_at":"2025-05-31T09:00:57.735Z","updated_at":"2025-06-25T21:31:38.141Z","avatar_url":"https://github.com/datastax.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JavaScript client for the Langflow API\n\n[![NPM Version](https://img.shields.io/npm/v/%40datastax%2Flangflow-client?logo=npm\u0026color=%23ea2039)](https://www.npmjs.com/@datastax/langflow-client) [![Tests](https://github.com/datastax/langflow-client-ts/actions/workflows/test.yml/badge.svg)](https://github.com/datastax/langflow-client-ts/actions/workflows/test.yml)\n\n---\n\nThis package provides an easy way to use the [Langflow API](https://docs.datastax.com/en/langflow/api.html) to run flows from within server-side JavaScript applications.\n\n- [Installation](#installation)\n  - [With npm](#with-npm)\n  - [With yarn](#with-yarn)\n  - [With pnpm](#with-pnpm)\n- [Prerequisites](#prerequisites)\n- [Configuration](#configuration)\n  - [DataStax Langflow](#datastax-langflow)\n  - [Open-source Langflow](#open-source-langflow)\n- [Usage](#usage)\n  - [Initialization](#initialization)\n  - [Running a flow](#running-a-flow)\n    - [Flow reponses](#flow-reponses)\n  - [Streaming](#streaming)\n  - [File upload](#file-upload)\n  - [Logs](#logs)\n    - [Fetching the logs](#fetching-the-logs)\n    - [Streaming the logs](#streaming-the-logs)\n  - [Aborting requests](#aborting-requests)\n- [Contributing](#contributing)\n\n## Installation\n\n### With npm\n\n```sh\nnpm install @datastax/langflow-client\n```\n\n### With yarn\n\n```sh\nyarn add @datastax/langflow-client\n```\n\n### With pnpm\n\n```sh\npnpm add @datastax/langflow-client\n```\n\n## Prerequisites\n\nTo use this Langflow client you will need a DataStax account with which you can use [DataStax Langflow](https://docs.datastax.com/en/langflow/index.html). You will need a flow before you can call its API. If you don't already have one, you can get started with the [Basic Prompting Flow](https://docs.datastax.com/en/langflow/quickstart.html).\n\nYou can also use this with an installation of [open-source Langflow](https://www.langflow.org/).\n\n## Configuration\n\n### DataStax Langflow\n\nYou will need a [Langflow API key](https://docs.datastax.com/en/langflow/concepts/settings.html#langflow-api). You provide the API key when you create a new client. You will also need your Langflow ID.\n\nYou can generate API keys and find your Langflow ID on the API modal in the Langflow flow editor.\n\n### Open-source Langflow\n\nYou will need an installation of Langflow. You may also require an [API key](https://docs.langflow.org/configuration-api-keys) if you have set up [authentication on Langflow](https://docs.langflow.org/configuration-authentication).\n\n## Usage\n\nYou can import the client like so:\n\n```js\nimport { LangflowClient } from \"@datastax/langflow-client\";\n```\n\n### Initialization\n\nYou can then create a new client object with the following options:\n\n- `baseURL`: This is set to `https://api.langflow.astra.datastax.com` by default, if you are running your own instance of Langflow you will need to provide the URL\n- `langflowId`: The ID of your organisation, which can be found in the API modal of the flow editor. This is not required for your own instance of Langflow\n- `apiKey`: A Langflow API key that can be generated within your DataStax account or in the settings of open-source Langflow\n\n```js\n// using DataStax Langflow, you do not need to provide the baseUrl\nconst dsLangflowClient = new LangflowClient({ langflowId, apiKey });\n\n// for open-source langflow, you will need to provide a baseUrl and optionally an apiKey\nconst baseUrl = \"http://localhost:7860\";\nconst apiKey = \"sk-...\";\nconst osLangflowClient = new LangflowClient({ baseUrl, apiKey });\n```\n\n### Running a flow\n\n[Langflow documentation for running a flow](https://docs.langflow.org/api/simplified-run-flow).\n\nOnce you have a client, you can create a reference to a flow using the `flowID`. This can be found in the API modal in Langflow.\n\n```js\nconst flow = client.flow(flowId);\n```\n\nYou can run a flow by calling `run` with the text input to the flow:\n\n```js\nconst response = await client.flow(flowId).run(input);\n```\n\nYou can add [tweaks](https://docs.langflow.org/concepts-api#tweaks) to a flow like so:\n\n```js\nconst response = await client\n  .flow(flowId)\n  .tweak(tweakName, tweakOptions)\n  .run(input);\n```\n\nOr you can pass all tweaks as an object:\n\n```js\nconst response = await client.flow(flowId).run(input, { tweaks });\n```\n\nYou can also pass input and output options, as well as a session ID.\n\n```js\nimport { InputTypes, OutputTypes } from \"@datastax/langflow-client/consts\";\n\nconst response = await client.flow(flowId).run(input, {\n  input_type: InputTypes.CHAT,\n  output_type: OutputTypes.CHAT,\n  session_id,\n  tweaks,\n});\n```\n\nThe available input types are \"chat\", \"text\" and \"any\". The available output types are \"chat\", \"text\", \"any\" and \"debug\". The default for both is \"chat\".\n\n#### Flow reponses\n\nLangflow is very flexible in its output. So the `FlowResponse` object gives you raw access to the `sessionId` and the `outputs`.\n\n```js\nconst response = await client.flow(flowId).run(input);\nconsole.log(response.outputs);\n```\n\nThere is one convenience function that will return you the first chat output message text. If you only have one chat output component in your flow, this is a useful shortcut to get to that response.\n\n```js\nconst response = await client.flow(flowId).run(input);\nconsole.log(response.chatOutputText());\n```\n\n### Streaming\n\nThe Langflow API supports streaming responses. Instead of calling `run` on a `Flow` object, you can call `stream` with the same arguments and the response will be a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) of objects.\n\n```js\nconst response = await client.flow(flowId).stream(input);\n\nfor await (const event of response) {\n  console.log(event);\n}\n```\n\nThere are three different events: `add_message`, `token`, and `end`. The events mean:\n\n- `add_message`: a message being added to the chat and can refer to a human input message or a response from an AI\n- `token`: a token that is emitted as part of a message being generated by the flow\n- `end`: all tokens have been returned, this message will also contain a full `FlowResponse`\n\nEvent objects have the format:\n\n```typescript\n{\n  event: \"add_message\" | \"token\" | \"end\",\n  data: object\n}\n```\n\nThe `event.data` is different per event type. The `token` event type is the simplest and looks like this:\n\n```typescript\n{\n  \"event\": \"token\",\n  \"data\": {\n    \"chunk\": \"hello \",\n    \"id\": \"6686ff20-0c95-40bb-8879-fd90ed3d634e\",\n    \"timestamp\": \"2025-02-12 22:18:04 UTC\"\n  }\n}\n```\n\nThere's more [documentation and examples of a streaming response in the Langflow docs](https://docs.langflow.org/api-reference-api-examples#run-flow).\n\n### File upload\n\n[Langflow documentation for file upload API](https://docs.langflow.org/api/upload-file-1).\n\nChat input components support files as input as well as text. You need to upload your file first, using the file upload function, then provide the file path to the flow as a tweak.\n\n```js\nconst flow = client.flow(flowId)\n\nconst file = await flow.uploadFile(pathToFile);\nconsole.log(file);\n// =\u003e { flowId: \"XXX\", filePath: \"YYY\" }\n\nconst response = await flow.tweak(\"ChatInput-abcd\": { files: file.filePath }).run(\"What can you see in this image?\");\n```\n\n\u003e [!WARNING]  \n\u003e DataStax Langflow doesn't make file upload available, you will receive a 501 Not Implemented error.\n\n### Logs\n\n[Langflow documentation for the logs API](https://docs.langflow.org/api/logs).\n\n#### Fetching the logs\n\nYou can fetch the logs for the your Langflow instance.\n\n```js\nconst logs = await client.logs.fetch();\n```\n\nWhen fetching the logs, you can pass a `timestamp` and either a number of `lines_before` or `lines_after` the timestamp. For example, the following code will get the 10 log lines that happened after 1 hour ago:\n\n```js\nconst logs = await client.logs.fetch({\n  timestamp: Date.now() - 60 * 60 * 1000,\n  lines_after: 10,\n});\n```\n\n#### Streaming the logs\n\nYou can also stream the logs by requesting the [streaming endpoint](https://docs.langflow.org/api/stream-logs).\n\n```js\nfor await (const log of await client.logs.stream()) {\n  console.log(log);\n}\n```\n\n### Aborting requests\n\nYou can use the standard [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) to cancel requests by passing a `signal` to the `run` or `uploadFile` functions. The functions will reject with a `DOMException` error with the name `AbortError` or, if you use [`AbortSignal.timeout`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static), `TimeoutError`.\n\nFor example, when running the following code, if the entire request takes longer than 500ms, then the promise will reject and the error message will be, \"The operation was aborted due to timeout\".\n\n```js\nconst signal = AbortSignal.timeout(500);\ntry {\n  const response = await client.flow(flowId).run(input, { signal });\n} catch (error) {\n  console.error(error.message);\n}\n```\n\n## Contributing\n\nTo run and contribute to this library you can clone the repository:\n\n```sh\ngit clone git@github.com:datastax/langflow-client-ts.git\ncd langflow-client-ts\n```\n\nInstall the dependencies:\n\n```sh\nnpm install\n```\n\nRun the tests:\n\n```sh\nnpm test\n```\n\nTranspile the TypeScript to JavaScript:\n\n```sh\nnpm run build\n```\n\nTranspile the TypeScript to JavaScript in watch mode:\n\n```sh\nnpm run build:watch\n```\n\nLint the code:\n\n```sh\nnpm run lint\n```\n\nFormat the code:\n\n```sh\nnpm run format\n```\n\nCheck the formatting of the code:\n\n```sh\nnpm run format:check\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatastax%2Flangflow-client-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatastax%2Flangflow-client-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatastax%2Flangflow-client-ts/lists"}