Last reviewed: 2026-09-14

Direct answer

A CometAPI Langflow integration starts with the smallest useful graph:

Chat Input -> CometAPI -> Chat Output

Add those three components to a Langflow canvas, place an active CometAPI credential in the CometAPI component’s secret field, and select a model ID offered by the component. Connect Chat Input to the CometAPI input and its default model-response output to Chat Output. Then send a short, deterministic prompt in Playground before exposing the flow to any application.

This sequence follows the public CometAPI Langflow integration guide . The important architectural boundary comes afterward: your Python application calls the Langflow server, while Langflow calls CometAPI. The CometAPI credential and model setting remain in the Langflow component. The application uses a separate Langflow credential when its deployment requires API authentication.

Once Playground succeeds, open Share, choose API access, and copy the generated Python contract for that exact flow. Use the generated server address and flow ID or endpoint name rather than reconstructing the route from memory. The CometAPI guide documents both a REST request and the langflow-sdk client for this step.

If you still need an account and project credential, Start with CometAPI , then return to Langflow and finish the three-component smoke test.

Who this is for

This tutorial is for Python developers and low-code AI builders who want to design a chat workflow visually but invoke the result from an application. It applies to Langflow Desktop, Langflow Cloud, and self-hosted deployments, although installation and API-authentication details can differ by deployment.

It is especially useful when one person owns the visual flow and another owns the calling application. That split works cleanly when the Langflow workspace retains the CometAPI credential and model configuration, while the application receives only the information required to reach the Langflow flow.

This is not a direct CometAPI HTTP-client tutorial. If your application should bypass Langflow entirely, start with the chat-completions CLI example instead. Here, Langflow is an intentional orchestration layer.

Key takeaways

  • Use Chat Input, CometAPI, and Chat Output for the first test. Add agents, prompt templates, or transforms only after that baseline works.
  • Keep the CometAPI and Langflow credentials separate. They authenticate different hops and should not be copied into prompts, logs, screenshots, or query strings.
  • Select a current model ID from the CometAPI component rather than assuming that an old example ID remains available.
  • Keep the default model-response output for direct chat. Switch to the Language Model output only when a downstream Langflow component expects an LLM.
  • Treat a Playground run and an external Python run as two distinct acceptance checks. The first verifies the flow; the second also verifies the Langflow route and application authentication.
  • Use the code generated by Share and API access as the deployed flow’s contract. It reflects the selected flow and its exposed inputs.

Build and test the flow

  1. Create a new Langflow flow and add Chat Input, CometAPI, and Chat Output.
  2. Select the CometAPI component and enter the CometAPI credential in its secret input. If you document that screen, replace the value with [REDACTED].
  3. Choose a model from the component’s model menu. If the menu does not populate, stop and resolve that problem before wiring a larger flow.
  4. Connect Chat Input to the CometAPI text input. Connect the default response output from CometAPI to Chat Output.
  5. Open Playground and send a bounded prompt such as a request for a one-sentence acknowledgement. Pass the check only when the run completes and the output is nonempty.
  6. Open Share and API access. Record the generated flow ID or endpoint name and use the generated Python example as the starting contract.

The following operator-oriented client keeps configuration outside the source file and records only sanitized run metadata:

import logging
import os
import time

from langflow_sdk import Client

logger = logging.getLogger('langflow_flow')
flow_ref = os.environ['LANGFLOW_FLOW_ID']
flow_label = os.environ.get('FLOW_LOG_LABEL', 'langflow-chat')
started = time.monotonic()
response_empty = None

try:
    client = Client(
        os.environ['LANGFLOW_URL'],
        api_key=os.environ['LANGFLOW_API_KEY'],
    )
    result = client.run(
        flow_ref,
        input_value='Reply with exactly: flow check passed',
    )
    text = result.first_text_output()
    response_empty = not bool(text and text.strip())
    if response_empty:
        raise RuntimeError('Langflow returned no text')

    logger.info(
        'langflow_run_ok',
        extra={
            'flow_label': flow_label,
            'outcome': 'success',
            'input_type': 'chat',
            'output_type': 'chat',
            'duration_ms': round((time.monotonic() - started) * 1000),
            'response_empty': response_empty,
        },
    )
    print('Langflow smoke test passed')
except Exception as exc:
    response = getattr(exc, 'response', None)
    logger.error(
        'langflow_run_failed',
        extra={
            'flow_label': flow_label,
            'outcome': 'error',
            'input_type': 'chat',
            'output_type': 'chat',
            'duration_ms': round((time.monotonic() - started) * 1000),
            'http_status': getattr(response, 'status_code', None),
            'exception_type': type(exc).__name__,
            'response_empty': response_empty,
        },
    )
    raise

For the happy path, run this against the same flow that passed Playground and require a nonempty text result. The script emits a fixed success indicator instead of printing the model response, so stdout remains suitable for a log-capturing runtime. For the error path, use a nonproduction environment and temporarily set the flow reference to a clearly nonexistent alias such as missing-flow. Confirm that the call fails, the exception remains visible to the caller, and the log contains only the event name, safe flow label, outcome, input and output types, duration, status when available, exception class, and response-empty state. Restore the valid flow reference afterward. Do not damage or print a credential merely to manufacture an authentication failure.

Sources checked

  • The CometAPI guide for connecting Langflow documents the native component, three-node chat flow, Playground check, REST shape, Python SDK call, and separation between CometAPI and Langflow credentials.
  • The Langflow CometAPI bundle reference documents the component’s inputs, model discovery, model-response and Language Model outputs, optional bundle installation, and compatible downstream components.
  • The Langflow API flow-trigger guide explains generated API snippets, v1 and v2 access choices, flow IDs, endpoint names, authentication, request tweaks, and the documented TWEAKS_REFUSED response.
  • The langflow-sdk package page is the public registry location for the Python client used by the CometAPI guide. Package versions can change, so this article does not freeze a version number.

These are the only factual sources used for this tutorial. Check the documentation for your deployed Langflow version before copying version-sensitive settings.

Contract details to verify

Component and flow contract

The current Langflow bundle page is labeled for Langflow 1.12.x and notes that the CometAPI provider can be an opt-in bundle. If the component is absent, verify the bundle configuration supported by your deployment instead of replacing it with a superficially similar generic component.

The CometAPI component accepts an input value, system message, model name, maximum-token setting, temperature, seed, extra model arguments, JSON mode, and streaming control. Most of those options are unnecessary for the first smoke test. Begin with the credential, a current model choice, and a short input. A smaller contract makes a wiring or model-selection failure easier to isolate.

For direct chat, connect the normal model response to Chat Output. The Langflow reference says the component can alternatively produce a Language Model object for components such as Agent or Smart Transform. Those outputs are not interchangeable: choose the one the next component expects.

Application contract

The CometAPI guide’s REST example posts input_value, input_type, and output_type to the Langflow run route, with both types set to chat. Its SDK example calls Client.run() with a flow ID and reads first_text_output(). The Python client therefore needs the Langflow server address, the exact flow reference, and a Langflow credential where authentication is enabled. It does not need the CometAPI credential.

Langflow’s API guide says the Share and API access pane generates Python, JavaScript, and curl snippets. It also allows an endpoint name to replace the underlying flow ID. An endpoint name may contain letters, numbers, hyphens, and underscores. A stable, descriptive endpoint name is easier to operate than copying an opaque ID between environments, but each deployment must still map that name to the intended flow.

Current Langflow documentation says most API endpoints require a Langflow API key in versions 1.5 and later. A Playground success does not prove that an external process has this second credential or the correct server address. Verify both hops separately.

Only expose component fields as runtime tweaks when callers genuinely need to change them. Langflow documents that API-exposed fields can appear in the generated tweaks object and that a disallowed tweak can return status 422 with code TWEAKS_REFUSED. Keeping the model fixed for the first application test avoids adding that extra failure surface.

Logging contract

Record safe operational facts: a non-secret flow label, outcome, duration, input and output type, HTTP status when present, exception class, and whether the response was empty. The example initializes the response-empty field as unknown, changes it to a Boolean after reading the result, and includes it in both success and failure records. Do not record either credential, request headers, full prompts, full model output, or arbitrary exception bodies by default. A fixed success indicator, status, and exception class are usually enough to identify which boundary needs inspection without copying sensitive content into centralized logs.

Failure modes

SymptomLikely boundaryWhat to check
CometAPI does not appear in the component menuLangflow installationConfirm that the deployment includes and exposes the CometAPI bundle. Update or install the appropriate bundle for that deployment before redesigning the flow.
The model menu is empty or will not loadCometAPI component configurationConfirm that the credential is active and the account can access the intended model. Never print the credential while diagnosing the menu. Enter an exact current model ID only when the component supports manual entry.
Playground returns a component errorModel selection or wiringConfirm the model ID, then verify that Chat Input reaches the CometAPI input and the normal response reaches Chat Output. Reduce the flow to the three required nodes.
Playground works but Python is rejectedLangflow API boundaryCompare the application request with the generated API-access snippet. Verify the Langflow server, flow ID or endpoint name, and the distinct Langflow credential available to the running process.
The application route is not foundFlow reference or deploymentConfirm that the ID or endpoint name belongs to the target Langflow instance. Do not assume aliases were copied between local, staging, and production environments.
A request returns 422 with TWEAKS_REFUSEDLangflow tweak policyRemove the unneeded tweak or have the deployment owner deliberately allow that field. Do not work around the policy by moving protected values into the prompt.
The request reaches a client deadlineNetwork or execution durationLog elapsed time and any available status, then distinguish connection failure from a long-running flow. A timeout alone does not identify the failing provider. Apply a bounded policy such as the one in client-side timeout handling .
The SDK returns no usable textFlow output contractRecheck Chat Output and the selected output type. Inspect the response only in a controlled development environment rather than dumping the entire payload into production logs.

A useful triage order is component availability, model selection, canvas wiring, Playground, generated route, Langflow authentication, and finally application parsing. This order follows the request from the inner flow outward and avoids changing several boundaries at once.

FAQ

Does the Python application call CometAPI directly?

No. In this design, Python calls the Langflow server. The CometAPI component inside the flow makes the model request. That is why the CometAPI credential stays in Langflow while the Python process uses a separate Langflow credential when required.

Which CometAPI output should a basic chat flow use?

Use the default model-response output and connect it to Chat Output. Use the Language Model output when another Langflow component, such as an Agent or Smart Transform, explicitly expects an LLM object.

Can I hard-code a model ID in the tutorial or client?

Keep the selected model in the Langflow component and verify its current availability before deployment. Because the component can fetch its latest available model choices after receiving a valid credential, treat that list as dynamic rather than freezing an example ID in application code. If you need a repeatable verification process, follow the model-catalog validation guide .

Should the calling application be allowed to change the model?

Not for the first integration test. Fixing the model in the flow reduces the request contract. If callers later need model choice, expose only the required field as an API tweak, constrain acceptable values, and test the deployment’s tweak policy, including the documented refusal path.

Must I use the Python SDK?

No. The CometAPI guide also shows a normal HTTP request to the Langflow run route. The SDK is convenient because it provides Client.run() and first_text_output(). Whichever client you choose, begin with the snippet generated for the actual flow and preserve its authentication and payload shape.

What should I save as smoke-test evidence?

Save the review time, deployment label, safe flow alias, selected non-secret model label, outcome, duration, response-empty flag, and HTTP status when available. Do not save credentials, headers, full user prompts, or full generated responses as routine evidence.

Reader next step

Create the three-component flow in a nonproduction Langflow workspace now. Select a currently available model, send one bounded Playground prompt, and do not proceed until the response is nonempty. Next, copy the Python snippet from Share and API access, move its configuration into environment variables, and run the same prompt through the application boundary.

Then exercise one controlled error: replace the flow reference with missing-flow, confirm the client surfaces the failure, and verify that your logs contain only sanitized fields. Restore the correct reference and run the happy path once more. That pair of checks proves more than a screenshot because it covers both the working flow and the application’s failure behavior.

Before widening access, review the model-catalog validation workflow and client timeout guidance . Keep the initial production contract narrow: one flow alias, one approved model, chat input, chat output, bounded execution, and sanitized logs.

When you are ready to configure the provider side, Start with CometAPI and complete the Playground check before connecting your Python service.