> ## Documentation Index
> Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect Langflow to CometAPI

> Use this guide to connect Langflow to CometAPI by setting the base URL, API key, and model or provider options.

[Langflow](https://www.langflow.org/) is a visual framework for building agent and RAG workflows. Langflow includes a CometAPI component that calls CometAPI language models through OpenAI-compatible endpoints.

## Prerequisites

* Langflow Desktop, Langflow Cloud, or a self-hosted Langflow instance
* A CometAPI account with an active API key — [get yours in the dashboard](https://www.cometapi.com/console/token)
* A model ID from the [CometAPI Models page](/overview/models)

## Configure the integration

<Steps>
  <Step title="Add the CometAPI component">
    In the Langflow canvas, open the component menu. Search for **CometAPI**, then add the CometAPI text generation component to your flow.
  </Step>

  <Step title="Enter your CometAPI API key">
    Select the CometAPI component. In the component inspection panel, enter your CometAPI API key in the API key field.
  </Step>

  <Step title="Choose a model ID">
    Set the model ID to a value from the [CometAPI Models page](/overview/models). If the component can fetch models after you enter the API key, select the model ID from the model menu.
  </Step>

  <Step title="Connect chat input and output">
    For a minimal test flow, add **Chat Input** and **Chat Output** components. Connect **Chat Input** to the CometAPI component input, then connect the CometAPI output to **Chat Output**.
  </Step>

  <Step title="Test in Playground">
    Open Playground and send a short message. A successful chat response confirms that Langflow is calling CometAPI.
  </Step>
</Steps>

## Use CometAPI inside larger flows

Change the CometAPI component output type to **Language Model** when another Langflow component needs an LLM input. This is useful for Agent, Prompt Template, and Smart Transform flows.

For direct chat, keep the default model response output and connect it to a Chat Output component.

## Run the CometAPI flow from Python

After you test the flow in Playground, you can call the same Langflow flow from Python. The Python code calls your Langflow server. It does not send requests directly to CometAPI. Keep the CometAPI API key and model ID in the CometAPI component inside Langflow.

The REST API example sends a chat input to a flow ID or endpoint name:

```python theme={null}
import os

import requests

langflow_url = os.environ.get("LANGFLOW_URL", "http://localhost:7860")
langflow_api_key = os.environ["LANGFLOW_API_KEY"]
flow_id = os.environ["LANGFLOW_FLOW_ID"]

response = requests.post(
    f"{langflow_url}/api/v1/run/{flow_id}",
    headers={
        "x-api-key": langflow_api_key,
        "Content-Type": "application/json",
    },
    json={
        "input_value": "Hello from CometAPI",
        "input_type": "chat",
        "output_type": "chat",
    },
    timeout=60,
)
response.raise_for_status()
print(response.json())
```

For projects that use the Langflow Python SDK, install `langflow-sdk` and call the same flow through `Client.run()`:

```python theme={null}
from langflow_sdk import Client

client = Client("http://localhost:7860", api_key="<LANGFLOW_API_KEY>")
response = client.run("FLOW_ID", input_value="Hello from CometAPI")
print(response.first_text_output())
```

Replace `FLOW_ID` with the flow ID or endpoint name from Langflow. Replace `<LANGFLOW_API_KEY>` with your Langflow API key. This value is different from your CometAPI API key.

## Troubleshooting

<AccordionGroup>
  <Accordion title="The CometAPI component is missing">
    Update Langflow to a version that includes the CometAPI bundle. If your deployment hides some components, check the bundle settings or search under language model components.
  </Accordion>

  <Accordion title="The model list does not load">
    Confirm that the CometAPI API key is valid and that the account has access to the selected model. You can also enter the model ID manually.
  </Accordion>

  <Accordion title="The flow runs but returns an error">
    Check that the model ID matches CometAPI exactly and that the flow input is connected to the CometAPI component input.
  </Accordion>
</AccordionGroup>

## Related resources

* [Langflow CometAPI bundle](https://docs.langflow.org/bundles-cometapi)
* [Langflow API flow trigger](https://docs.langflow.org/concepts-publish)
* [langflow-sdk package](https://pypi.org/project/langflow-sdk/)
* [CometAPI quick start](/overview/quick-start)
* [CometAPI Models page](/overview/models)

<script type="application/ld+json">
  {`
    {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "HowTo",
        "@id": "https://apidoc.cometapi.com/integrations/langflow#howto",
        "name": "Connect Langflow to CometAPI",
        "description": "Use this guide to connect Langflow to CometAPI by setting the base URL, API key, and model or provider options.",
        "step": [
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/langflow#step-1",
            "position": 1,
            "name": "Add the CometAPI component",
            "text": "Complete the Add the CometAPI component step in the Connect Langflow to CometAPI guide."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/langflow#step-2",
            "position": 2,
            "name": "Enter your CometAPI API key",
            "text": "Complete the Enter your CometAPI API key step in the Connect Langflow to CometAPI guide."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/langflow#step-3",
            "position": 3,
            "name": "Choose a model ID",
            "text": "Complete the Choose a model ID step in the Connect Langflow to CometAPI guide."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/langflow#step-4",
            "position": 4,
            "name": "Connect chat input and output",
            "text": "Complete the Connect chat input and output step in the Connect Langflow to CometAPI guide."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/langflow#step-5",
            "position": 5,
            "name": "Test in Playground",
            "text": "Complete the Test in Playground step in the Connect Langflow to CometAPI guide."
          }
        ]
      },
      {
        "@type": "BreadcrumbList",
        "itemListElement": [
          {
            "@type": "ListItem",
            "position": 1,
            "name": "CometAPI Docs",
            "item": "https://apidoc.cometapi.com/"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "Integrations",
            "item": "https://apidoc.cometapi.com/integrations"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "Connect Langflow to CometAPI",
            "item": "https://apidoc.cometapi.com/integrations/langflow"
          }
        ]
      }
    ]
    }
    `}
</script>
