> ## 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.

# Use CrewAI with CometAPI

> Use four CrewAI LLM transport configurations with CometAPI in one sequential multi-agent Crew.

[CrewAI](https://docs.crewai.com/) is a Python framework for coordinating AI agents and tasks. This guide configures one sequential Crew to call CometAPI through four CrewAI transport configurations: OpenAI Chat Completions, OpenAI Responses, Anthropic Messages, and Gemini `generateContent`.

## Prerequisites

* Python 3.10–3.13
* [`uv`](https://docs.astral.sh/uv/getting-started/installation/)
* A CometAPI account with an active API key — [get yours in the dashboard](https://www.cometapi.com/console/token)
* Four text model IDs for the transports shown below

## Configure the integration

<Steps>
  <Step title="Create a project and install CrewAI">
    Create a new `uv` project and install CrewAI with its Anthropic and Google Gen AI extras:

    ```bash theme={null}
    uv init crewai-cometapi
    cd crewai-cometapi
    uv add 'crewai[anthropic,google-genai]'
    ```
  </Step>

  <Step title="Set your API key and model IDs">
    Set the CometAPI API key and one model ID for each transport:

    ```bash theme={null}
    read -rsp "CometAPI API key: " COMETAPI_KEY
    printf '\n'
    export COMETAPI_KEY

    export COMETAPI_CHAT_MODEL_ID=your-model-id
    export COMETAPI_RESPONSES_MODEL_ID=your-model-id
    export COMETAPI_ANTHROPIC_MODEL_ID=your-model-id
    export COMETAPI_GEMINI_MODEL_ID=your-model-id
    ```

    Replace every `your-model-id` value with a model ID from the [CometAPI Models page](/overview/models). The four values can be different. Assign each model ID to its corresponding transport.
  </Step>

  <Step title="Create the sequential Crew">
    Save the following example as `crew.py`:

    ```python theme={null}
    import os

    from crewai import Agent, Crew, LLM, Process, Task


    api_key = os.environ["COMETAPI_KEY"]

    chat_llm = LLM(
        model=os.environ["COMETAPI_CHAT_MODEL_ID"],
        custom_openai=True,
        api="completions",
        base_url="https://api.cometapi.com/v1",
        api_key=api_key,
        max_tokens=512,
        max_retries=0,
    )

    responses_llm = LLM(
        model=os.environ["COMETAPI_RESPONSES_MODEL_ID"],
        custom_openai=True,
        api="responses",
        base_url="https://api.cometapi.com/v1",
        api_key=api_key,
        max_completion_tokens=512,
        max_retries=0,
    )

    anthropic_llm = LLM(
        model=f"anthropic/{os.environ['COMETAPI_ANTHROPIC_MODEL_ID']}",
        base_url="https://api.cometapi.com",
        api_key=api_key,
        max_tokens=512,
        max_retries=0,
    )

    gemini_llm = LLM(
        model=f"gemini/{os.environ['COMETAPI_GEMINI_MODEL_ID']}",
        api_key=api_key,
        max_output_tokens=512,
        thinking_config={"thinking_budget": 0, "include_thoughts": False},
        client_params={
            "http_options": {
                "base_url": "https://api.cometapi.com",
                "api_version": "v1beta",
            }
        },
    )

    audience_agent = Agent(
        role="Audience researcher",
        goal="Define the audience for an API migration brief",
        backstory="You turn product goals into a precise audience statement.",
        llm=chat_llm,
        tools=[],
        allow_delegation=False,
        max_iter=1,
        max_retry_limit=0,
        verbose=False,
    )

    requirements_agent = Agent(
        role="Requirements planner",
        goal="Turn an audience statement into implementation requirements",
        backstory="You write concise, testable requirements for API teams.",
        llm=responses_llm,
        tools=[],
        allow_delegation=False,
        max_iter=1,
        max_retry_limit=0,
        verbose=False,
    )

    risk_agent = Agent(
        role="Risk reviewer",
        goal="Identify the most important migration risk",
        backstory="You review plans for practical delivery risks.",
        llm=anthropic_llm,
        tools=[],
        allow_delegation=False,
        max_iter=1,
        max_retry_limit=0,
        verbose=False,
    )

    editor_agent = Agent(
        role="Release brief editor",
        goal="Combine research, requirements, and risk into one brief",
        backstory="You preserve source findings while producing clear summaries.",
        llm=gemini_llm,
        tools=[],
        allow_delegation=False,
        max_iter=1,
        max_retry_limit=0,
        verbose=False,
    )

    audience_task = Task(
        description=(
            "Define one target audience for a team moving an existing OpenAI "
            "integration to a multi-provider API. Return only an Audience heading "
            "and one sentence of at most 20 words."
        ),
        expected_output="An Audience heading followed by one concise sentence.",
        agent=audience_agent,
    )

    requirements_task = Task(
        description=(
            "Using the audience statement in your context, return only a "
            "Requirements heading and exactly two numbered requirements. Keep each "
            "requirement to at most 18 words."
        ),
        expected_output="A Requirements heading followed by two numbered items.",
        agent=requirements_agent,
        context=[audience_task],
    )

    risk_task = Task(
        description=(
            "Using the audience and requirements in your context, return only a "
            "Risk heading, one risk sentence, and one mitigation sentence. Keep "
            "each sentence to at most 18 words."
        ),
        expected_output="A Risk heading with one risk and one mitigation.",
        agent=risk_agent,
        context=[audience_task, requirements_task],
    )

    brief_task = Task(
        description=(
            "Create a release brief from all prior task outputs. Return only these "
            "sections: Audience with one sentence; Requirements with two numbered "
            "items; Risk with one risk and one mitigation. Keep the exact headings "
            "Audience, Requirements, and Risk."
        ),
        expected_output=(
            "A concise release brief with Audience, Requirements, and Risk headings."
        ),
        agent=editor_agent,
        context=[audience_task, requirements_task, risk_task],
    )

    crew = Crew(
        agents=[
            audience_agent,
            requirements_agent,
            risk_agent,
            editor_agent,
        ],
        tasks=[audience_task, requirements_task, risk_task, brief_task],
        process=Process.sequential,
        verbose=False,
    )

    result = crew.kickoff()

    for index, task_output in enumerate(result.tasks_output, start=1):
        print(f"\n--- Task {index} ---\n{task_output.raw}")
    ```

    The Agents have no tools, cannot delegate, and run one at a time. Every Task after the first declares its preceding Tasks in `context`, so CrewAI includes those prior outputs in the next Task.
  </Step>

  <Step title="Run the Crew">
    Run the example in the same shell session:

    ```bash theme={null}
    uv run python crew.py
    ```

    The script prints all four Task outputs, including the final release brief.
  </Step>
</Steps>

## Route mapping

| CrewAI configuration                                    | CometAPI route                                | Base URL                      |
| ------------------------------------------------------- | --------------------------------------------- | ----------------------------- |
| `custom_openai=True`, `api="completions"`               | `POST /v1/chat/completions`                   | `https://api.cometapi.com/v1` |
| `custom_openai=True`, `api="responses"`                 | `POST /v1/responses`                          | `https://api.cometapi.com/v1` |
| `anthropic/` model prefix                               | `POST /v1/messages`                           | `https://api.cometapi.com`    |
| `gemini/` model prefix and `client_params.http_options` | `POST /v1beta/models/{model}:generateContent` | `https://api.cometapi.com`    |

The two OpenAI configurations above need the `/v1` suffix in `base_url`. The Anthropic and Gemini configurations add their own versioned route, so their base URL is the CometAPI origin without `/v1`.

## Choose model IDs

Use the [CometAPI Models page](/overview/models) to choose one text model ID for each transport. Store the model IDs in environment variables so you can change them without editing the Python file. Do not add a provider prefix to an environment variable. The example adds `anthropic/` and `gemini/` where CrewAI uses those prefixes for provider selection.

## Troubleshooting

<AccordionGroup>
  <Accordion title="Anthropic or Gemini provider imports fail">
    Run `uv add 'crewai[anthropic,google-genai]'` in the project. The base CrewAI package does not install both optional provider SDKs by default.
  </Accordion>

  <Accordion title="A Responses request returns a parameter error">
    Remove optional parameters that are not part of the selected model's interface. The example configures only the output token limit for Responses.
  </Accordion>

  <Accordion title="A request uses the wrong route">
    Compare the `LLM` configuration with the route mapping table. In particular, use `custom_openai=True` with the correct `api` value, and keep the Gemini base URL inside `client_params.http_options`.
  </Accordion>
</AccordionGroup>

## Related resources

* [CrewAI 1.15.12 LLM documentation](https://docs.crewai.com/v1.15.12/en/concepts/llms)
* [CrewAI Agents](https://docs.crewai.com/v1.15.12/en/concepts/agents)
* [CrewAI Tasks](https://docs.crewai.com/v1.15.12/en/concepts/tasks)
* [CrewAI Crews](https://docs.crewai.com/v1.15.12/en/concepts/crews)
* [CometAPI Chat Completions](/api/text/chat)
* [CometAPI Responses](/api/text/responses)
* [CometAPI Anthropic Messages](/api/text/anthropic-messages)
* [CometAPI Gemini generateContent](/api/text/gemini-generating-content)

<script type="application/ld+json">
  {`
    {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "HowTo",
        "@id": "https://apidoc.cometapi.com/integrations/crewai#howto",
        "name": "Use CrewAI with CometAPI",
        "description": "Use four CrewAI LLM transport configurations with CometAPI in one sequential multi-agent Crew.",
        "step": [
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/crewai#step-1",
            "position": 1,
            "name": "Create a project and install CrewAI",
            "text": "Create a uv project and install CrewAI with the Anthropic and Google Gen AI extras."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/crewai#step-2",
            "position": 2,
            "name": "Set your API key and model IDs",
            "text": "Set the CometAPI API key and one current model ID for each transport."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/crewai#step-3",
            "position": 3,
            "name": "Create the sequential Crew",
            "text": "Configure four LLM adapters, four Agents, and four context-linked Tasks in a sequential Crew."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/crewai#step-4",
            "position": 4,
            "name": "Run the Crew",
            "text": "Run the Crew and inspect all four Task outputs."
          }
        ]
      },
      {
        "@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": "Use CrewAI with CometAPI",
            "item": "https://apidoc.cometapi.com/integrations/crewai"
          }
        ]
      }
    ]
    }
    `}
</script>
